1using System.Collections;
2using System.Collections.Generic;
7using Valve.VR.InteractionSystem;
10using static Valve.VR.InteractionSystem.Hand;
16 private bool isGripping =
false;
17 private bool isGameObject =
false;
24 GameObject SelectedGameObject;
25 GameObject ConnectedAction;
26 GameObject touchedObject;
29 public SteamVR_Action_Boolean
grabGripAction = SteamVR_Input.GetAction<SteamVR_Action_Boolean>(
"GrabGrip");
37 bool isGrabbedRight =
false;
38 bool isGrabbedLeft =
false;
39 GameObject attachedGameObject;
40 bool isSelected =
false;
41 Vector3 initialHandPosition1;
42 Vector3 initialHandPosition2;
43 Quaternion initialObjectRotation;
44 Vector3 initialObjectScale;
45 Vector3 initialObjectDirection;
47 AttachmentFlags initialAttachmentFlags;
50 private object objectToAttach;
66 if (collision.gameObject)
68 touchedObject = collision.gameObject;
77 if (
Player.GetComponent<
Player>().hands[0].currentAttachedObject)
79 attachedGameObject =
Player.GetComponent<
Player>().hands[0].currentAttachedObject;
81 if (
Player.GetComponent<
Player>().hands[1].currentAttachedObject)
83 attachedGameObject =
Player.GetComponent<
Player>().hands[1].currentAttachedObject;
96 if (SteamVR_Actions._default.Teleport.GetStateUp(SteamVR_Input_Sources.Any))
98 if (attachedGameObject)
103 Debug.Log(a.selectedHash);
104 if (attachedGameObject.gameObject == a.GetGameObject() && !isSelected)
107 if (a.GetOutputAction())
109 ConnectedAction = a.GetOutputAction();
115 if (!attachedGameObject)
119 if (SteamVR_Actions._default.Teleport.GetStateUp(SteamVR_Input_Sources.Any) && ConnectedAction)
121 ConnectedAction.GetComponent<
PositionAction>().FillCurrentTransform();
125 if (SteamVR_Actions._default.GrabPinch.GetStateDown(SteamVR_Input_Sources.Any) &&
LineLeft.activeInHierarchy || SteamVR_Actions._default.GrabPinch.GetStateDown(SteamVR_Input_Sources.Any) &&
LineRight.activeInHierarchy)
127 if (SteamVR_Actions._default.GrabPinch.GetStateDown(SteamVR_Input_Sources.LeftHand))
131 if (SteamVR_Actions._default.GrabPinch.GetStateDown(SteamVR_Input_Sources.RightHand))
136 if (chosedController.hitVC.collider.gameObject.GetComponent<
ScreneCapture>())
142 Vector2 touch = SteamVR_Actions._default.Touch.GetAxis(SteamVR_Input_Sources.Any);
143 float scroll = touch.y;
144 if (SteamVR_Actions._default.Scroll.GetChanged(SteamVR_Input_Sources.Any))
146 if (SteamVR_Actions._default.Scroll.GetChanged(SteamVR_Input_Sources.LeftHand))
150 if (SteamVR_Actions._default.Scroll.GetChanged(SteamVR_Input_Sources.RightHand))
154 if (chosedController.hitVC.collider.gameObject.GetComponent<
ScreneCapture>())
160 if (SteamVR_Actions._default.GrabPinch.GetStateUp(SteamVR_Input_Sources.Any) &&
LineLeft.activeInHierarchy || SteamVR_Actions._default.GrabPinch.GetStateUp(SteamVR_Input_Sources.Any) &&
LineRight.activeInHierarchy)
162 if (chosedController.hitVC.collider.gameObject.GetComponent<
ScreneCapture>())
168 if (chosedController.hitVC.collider.gameObject.GetComponent<
VivePointerTarget>())
170 chosedController.hitVC.collider.gameObject.GetComponent<
VivePointerTarget>().OnPointerClick();
174 chosedController.hitVC.collider.gameObject.GetComponent<
VivePointerTarget>().OnPointerClick();
179 if (SteamVR_Actions._default.SnapTurnDown.GetStateDown(SteamVR_Input_Sources.Any))
181 if (SteamVR_Actions._default.SnapTurnDown.GetStateDown(SteamVR_Input_Sources.LeftHand))
185 if (SteamVR_Actions._default.SnapTurnDown.GetStateDown(SteamVR_Input_Sources.RightHand))
189 if (chosedController.GetComponentInChildren<ScrollRect>())
191 chosedController.GetComponentInChildren<ScrollRect>().horizontalScrollbar.value += 0.05f;
194 if (SteamVR_Actions._default.SnapTurnUp.GetStateDown(SteamVR_Input_Sources.Any))
196 if (SteamVR_Actions._default.SnapTurnUp.GetStateDown(SteamVR_Input_Sources.LeftHand))
200 if (SteamVR_Actions._default.SnapTurnUp.GetStateDown(SteamVR_Input_Sources.RightHand))
204 if (chosedController.GetComponentInChildren<ScrollRect>())
206 chosedController.GetComponentInChildren<ScrollRect>().horizontalScrollbar.value -= 0.05f;
209 if (SteamVR_Actions._default.Menu.GetStateUp(SteamVR_Input_Sources.RightHand))
222 if (SteamVR_Actions._default.Menu.GetStateUp(SteamVR_Input_Sources.LeftHand))
236 if (
Player.GetComponent<
Player>().hands[1].currentAttachedObject && !isGrabbedRight)
238 initialHandPosition1 =
Player.GetComponent<
Player>().hands[1].transform.position;
239 initialObjectScale = attachedGameObject.transform.localScale;
240 isGrabbedRight =
true;
244 if (
Player.GetComponent<
Player>().hands[0].currentAttachedObject && !isGrabbedLeft)
246 initialHandPosition2 =
Player.GetComponent<
Player>().hands[0].transform.position;
247 isGrabbedLeft =
true;
249 if (!
Player.GetComponent<
Player>().hands[1].currentAttachedObject)
251 isGrabbedRight =
false;
254 if (!
Player.GetComponent<
Player>().hands[0].currentAttachedObject)
256 isGrabbedLeft =
false;
258 if (
CanvasSelector.transform.GetChild(0).GetComponent<
Button>() && SteamVR_Actions._default.GrabGrip.GetStateDown(SteamVR_Input_Sources.Any))
264 if (
Player.GetComponent<
Player>().hands[1].currentAttachedObject &&
Player.GetComponent<
Player>().hands[0].currentAttachedObject)
266 int xDistance = (int)
Player.GetComponent<
Player>().hands[1].transform.localPosition.x - (int)
Player.GetComponent<
Player>().hands[0].transform.localPosition.x;
268 float initialGrabDistance =
Vector3.Distance(initialHandPosition1, initialHandPosition2);
269 Vector3 rightHandPosition =
Player.GetComponent<
Player>().hands[1].transform.localPosition;
270 Vector3 leftHandPosition =
Player.GetComponent<
Player>().hands[0].transform.localPosition;
271 float currentGrabDistance =
Vector3.Distance(rightHandPosition, leftHandPosition);
272 float p = (currentGrabDistance / initialGrabDistance);
273 Vector3 newScale =
new Vector3(p * initialObjectScale.x, p * initialObjectScale.y, p * initialObjectScale.z);
274 attachedGameObject.transform.localScale = newScale;
277 catch (System.Exception)
UnityEngine.UI.Button Button
static void SetSelection(IEnumerable< GameObject > selection)
GameObject GetGameObject()
static void Scroll(uint value)
GameObject LeftHandModelMask
GameObject CanvasSelector
void OnCollisionEnter(Collision collision)
GameObject StageManagerWindow
SteamVR_Action_Boolean grabGripAction
SteamVR_Action_Boolean gripButton
GameObject LeftController
VivePointer vivePointerLeft
pb_StageManagerButton StgBtn
GameObject RightHandModelMask
GameObject RightController
GameObject StageManagerCanvas