Last active
October 27, 2020 21:26
-
-
Save techanon/b139858b725e8177cc37d918f0cfa533 to your computer and use it in GitHub Desktop.
Sample concept of using OnPickup inplace of Interact in order to detect the used hand.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UdonSharp; | |
using UnityEngine; | |
using VRC.SDKBase; | |
using VRC.Udon; | |
[RequireComponent(typeof(VRC_Pickup))] | |
public class PickupAsInteract : UdonSharpBehaviour | |
{ | |
[Tooltip("Receives events: OnInteractLeft, OnInteractRight")] | |
public UdonBehaviour eventTarget; | |
private VRC_Pickup pickup; | |
private Vector3 pos; | |
private Quaternion rot; | |
void Start() { | |
pickup = (VRC_Pickup)gameObject.GetComponent(typeof(VRC_Pickup)); | |
// cache original transform data | |
pos = transform.position; | |
rot = transform.rotation; | |
} | |
void OnPickup() { | |
// get the hand state, false = right hand | |
bool leftHand = pickup.currentHand == VRC_Pickup.PickupHand.Left; | |
// force drop the target | |
pickup.Drop(); | |
// may not be needed, but I like the guarentee of enforcing the original transform after bring dropped | |
transform.SetPositionAndRotation(pos, rot); | |
// trigger event | |
eventTarget.SendCustomEvent(leftHand ? "OnInteractLeft" : "OnInteractRight"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.data_start | |
.export eventTarget | |
instance_0: %UnityEngineGameObject, this | |
type_0: %SystemType, null | |
Type_0: %SystemType, null | |
instance_1: %UnityEngineTransform, this | |
instance_3: %UnityEngineTransform, this | |
instance_2: %UnityEngineGameObject, this | |
GameObject_0: %UnityEngineGameObject, this | |
objA_0: %SystemObject, null | |
objB_0: %SystemObject, null | |
instance_4: %SystemObject, null | |
instance_5: %VRCSDK3ComponentsVRCPickup, null | |
Int32_0: %SystemInt32, null | |
instance_6: %VRCSDK3ComponentsVRCPickup, null | |
instance_7: %UnityEngineTransform, this | |
position_0: %UnityEngineVector3, null | |
rotation_0: %UnityEngineQuaternion, null | |
instance_8: %UnityEngineGameObject, this | |
GameObject_1: %UnityEngineGameObject, this | |
Boolean_0: %SystemBoolean, null | |
instance_9: %VRCUdonUdonBehaviour, this | |
eventName_0: %SystemString, null | |
instance_A: %VRCUdonUdonBehaviour, this | |
eventName_1: %SystemString, null | |
pickup: %VRCSDK3ComponentsVRCPickup, null | |
pos: %UnityEngineVector3, null | |
rot: %UnityEngineQuaternion, null | |
eventTarget: %VRCUdonUdonBehaviour, this | |
leftHand: %SystemBoolean, null | |
.data_end | |
.code_start | |
.export _start | |
_start: | |
PUSH, GameObject_0 | |
PUSH, instance_0 | |
COPY | |
PUSH, Type_0 | |
PUSH, type_0 | |
COPY | |
PUSH, instance_0 | |
PUSH, type_0 | |
PUSH, pickup | |
EXTERN, "UnityEngineGameObject.__GetComponent__SystemType__UnityEngineComponent" | |
PUSH, GameObject_0 | |
PUSH, instance_2 | |
COPY | |
PUSH, instance_2 | |
PUSH, instance_1 | |
EXTERN, "UnityEngineGameObject.__get_transform__UnityEngineTransform" | |
PUSH, instance_1 | |
PUSH, pos | |
EXTERN, "UnityEngineTransform.__get_position__UnityEngineVector3" | |
PUSH, pos | |
PUSH, pos | |
COPY | |
PUSH, GameObject_0 | |
PUSH, instance_2 | |
COPY | |
PUSH, instance_1 | |
PUSH, instance_3 | |
COPY | |
PUSH, instance_1 | |
PUSH, rot | |
EXTERN, "UnityEngineTransform.__get_rotation__UnityEngineQuaternion" | |
PUSH, rot | |
PUSH, rot | |
COPY | |
JUMP, 0xFFFFFFFC | |
.export _onPickup | |
_onPickup: | |
PUSH, pickup | |
PUSH, instance_5 | |
COPY | |
PUSH, instance_5 | |
PUSH, instance_4 | |
EXTERN, "VRCSDK3ComponentsVRCPickup.__get_currentHand__VRCSDKBaseVRC_PickupPickupHand" | |
PUSH, instance_4 | |
PUSH, objA_0 | |
EXTERN, "SystemObject.__GetHashCode__SystemInt32" | |
PUSH, Int32_0 | |
PUSH, objB_0 | |
COPY | |
PUSH, objA_0 | |
PUSH, objB_0 | |
PUSH, leftHand | |
EXTERN, "SystemObject.__Equals__SystemObject_SystemObject__SystemBoolean" | |
PUSH, leftHand | |
PUSH, leftHand | |
COPY | |
PUSH, pickup | |
PUSH, instance_6 | |
COPY | |
PUSH, instance_6 | |
EXTERN, "VRCSDK3ComponentsVRCPickup.__Drop__SystemVoid" | |
PUSH, GameObject_1 | |
PUSH, instance_8 | |
COPY | |
PUSH, instance_8 | |
PUSH, instance_7 | |
EXTERN, "UnityEngineGameObject.__get_transform__UnityEngineTransform" | |
PUSH, instance_7 | |
PUSH, pos | |
PUSH, rot | |
EXTERN, "UnityEngineTransform.__SetPositionAndRotation__UnityEngineVector3_UnityEngineQuaternion__SystemVoid" | |
PUSH, leftHand | |
JUMP_IF_FALSE, 0x0000023C | |
PUSH, eventTarget | |
PUSH, instance_9 | |
COPY | |
PUSH, instance_9 | |
PUSH, eventName_0 | |
EXTERN, "VRCUdonCommonInterfacesIUdonEventReceiver.__SendCustomEvent__SystemString__SystemVoid" | |
JUMP, 0x00000268 | |
PUSH, eventTarget | |
PUSH, instance_A | |
COPY | |
PUSH, instance_A | |
PUSH, eventName_1 | |
EXTERN, "VRCUdonCommonInterfacesIUdonEventReceiver.__SendCustomEvent__SystemString__SystemVoid" | |
JUMP, 0xFFFFFFFC | |
.code_end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment