private void Awake() { m_leftTarget = -m_leftBeam.transform.localPosition; m_rightTarget = -m_rightBeam.transform.localPosition; m_centralTarget = m_centralBeamTarget.transform.localPosition; m_viveWand = GetComponentInParent <ViveWand>(); }
private void OnTriggerEnter(Collider other) { ViveWand viveWand = other.GetComponent <ViveWand>(); if (viveWand) { viveWand.SetSkin(m_relatedSkin); } }
public void Grip(ViveWand wand) { transform.SetParent(wand.transform); m_rigidbody.useGravity = false; m_rigidbody.isKinematic = true; m_picked = true; }
private void Update() { int wandCount = ViveWand.wandCount; bool targeted = false; bool targetedAndActivated = false; for (int i = 0; i < wandCount; i++) { ViveWand wand = ViveWand.Wand(i); if (!wand) { continue; } if (wand.skin == ViveWand.ViveWandSkins.Beam) { continue; } if (wand.targetedGameObject == gameObject) { targeted = true; if (wand.IsInteractionPressed(XperAction.Grip) || wand.IsInteractionPressed(XperAction.Trigger)) { targetedAndActivated = true; } } } if (targeted) { if ((m_scaleFactor <= 1) || (m_scaleFactor >= m_maxScale)) { m_scaleFactorDirection = -m_scaleFactorDirection; } } else { m_scaleFactorDirection = -1; } m_scaleFactor += m_scaleFactorDirection * Time.deltaTime * m_scaleSpeed; m_scaleFactor = Mathf.Max(Mathf.Min(m_scaleFactor, m_maxScale), 1); transform.localScale = m_scaleFactor * m_baseScale; if (m_isUpperArrow) { StageManager.MoveStageUp(targetedAndActivated); } else { StageManager.MoveStageDown(targetedAndActivated); } }
protected void Update() { ViveWand previousInteractionWand = m_interactionWand; m_interactionInProgress = InteractsWithWand(out m_interactionWand, out m_interactionActionType, out m_interactionRange); if (m_interactionInProgress) { m_interactionDown = m_interactionWand.InteractionDown(m_interactionActionType); if (m_interactionDown) { m_interacting = true; } m_interactionUp = false; if (IsSimpleAction(m_interactionActionType)) { OnAction(); if (m_interactionDown) { OnActionDown(); } OnTurnAction(m_interactionWand.AngleDeltaAroundAxis(transform.forward)); } if (m_interactionWand.previouslyTouched) { OnMoveAction(m_interactionWand.touchDelta); } } else { m_interactionDown = false; if (previousInteractionWand) { m_interactionUp = previousInteractionWand.InteractionUp(m_interactionActionType); if (m_interactionUp) { m_interacting = false; OnActionUp(); } } else { m_interactionUp = false; } } m_previouslyHadFocus = m_interactionInProgress; }
private bool CheckAtRange(ViveWand wand, XperRange range) { switch (range) { case XperRange.Contact: return(wand.closestObject == gameObject); case XperRange.Ranged: return((wand.targetedGameObject == gameObject) && (wand.skin != ViveWand.ViveWandSkins.Beam)); case (XperRange.Contact | XperRange.Ranged): return(CheckAtRange(wand, XperRange.Contact) || CheckAtRange(wand, XperRange.Ranged)); } return(false); }
IEnumerator MoveAndScale() { yield return(0); ViveWand toolWand = Core.Instance.rightWand; ViveWand paletteWand = Core.Instance.leftWand; /// Scale Vars float initialScale = VoxelPainterController.Instance.World.transform.localScale.x; float initDistance = Vector3.Distance(toolWand.transform.position, paletteWand.transform.position); float currentDistance; float scaleChange = 0; //Debug.Log("Most initial scale: " + initialScale + " VoxelPainterController.Instance.World.transform.localScale: " + VoxelPainterController.Instance.World.transform.localScale); /// Pos Vars Vector3 initWorldPosition = VoxelPainterController.Instance.World.transform.position; Vector3 initCenter = (toolWand.transform.position + paletteWand.transform.position) * 0.5f; Vector3 currentCenter = initCenter; Vector3 positionDelta = Vector3.zero; while (toolWand.GetButtonPressed(Valve.VR.EVRButtonId.k_EButton_Grip) && paletteWand.GetButtonPressed(Valve.VR.EVRButtonId.k_EButton_Grip)) { /// /// Handle Scale /// currentDistance = Vector3.Distance(toolWand.transform.position, paletteWand.transform.position); //Debug.Log("Scaling. InitDist: " + initDistance + " CurrDist: " + currentDistance); currentDistance -= initDistance; scaleChange = initialScale + currentDistance * distanceScaleSensitivity; //Debug.Log("Scale change: " + scaleChange + " Init Scale: " + initialScale); VoxelPainterController.Instance.World.transform.localScale = Vector3.one * scaleChange; /// /// Handle Position /// currentCenter = (toolWand.transform.position + paletteWand.transform.position) * 0.5f; positionDelta = (currentCenter - initCenter) * 3f; VoxelPainterController.Instance.World.transform.position = initWorldPosition + positionDelta; yield return(0); } currentInputCoroutine = null; }
protected override IEnumerator Run() { while (true) { ViveWand toolWand = Core.Instance.rightWand; Vector3 logicalPosToolWand = new Vector3(0, -69696969, 0); if (toolWand) { logicalPosToolWand = VoxelPainterController.Instance.World.GetGridNodeIndex(toolWand.transform.position); } ViveWand paletteWand = Core.Instance.leftWand; Vector3 logicalPosPaletteHand = new Vector3(0, -69696969, 0); if (paletteWand) { logicalPosPaletteHand = VoxelPainterController.Instance.World.GetGridNodeIndex(paletteWand.transform.position); } // If we are currently running an input exit the loop. if (currentInputCoroutine == null) { // Grip Gestures for TRS of world: if (paletteWand.GetButtonPressed(Valve.VR.EVRButtonId.k_EButton_Grip) && toolWand.GetButtonDownThisFrame(Valve.VR.EVRButtonId.k_EButton_Grip)) { currentInputCoroutine = StartCoroutine(MoveAndScale()); } // Paint. else { if (toolWand.GetButtonPressed(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger)) { VoxelPainterController.Instance.World.SetVoxelAtIndex(logicalPosToolWand, new VoxelProxy(Color.white)); } else if (toolWand.GetButtonPressed(Valve.VR.EVRButtonId.k_EButton_Grip)) { VoxelPainterController.Instance.World.ClearVoxelAtIndex(logicalPosToolWand); } } } yield return(0); } }
private void Awake() { m_viveWand = GetComponentInParent <ViveWand>(); }
private void Awake() { m_viveWand = GetComponentInParent <ViveWand>(); m_baseRightRotation = m_rightHook.localRotation; m_baseLeftRotation = m_leftHook.localRotation; }
private bool CheckWandAction(ViveWand wand, XperAction action, XperRange range) { return(wand.IsInteractionPressed(action) && XperManager.Allows(m_itemType, action, range)); }
private bool InteractsWithWand(out ViveWand interactionWand, out XperAction mode, out XperRange range) { int wandCount = ViveWand.wandCount; XperAction activationMode = 0; XperRange activationRange = 0; ViveWand gripingWand = null; m_isAtRangeOfWand = false; List <ViveWand> wands = new List <ViveWand>(); for (int i = 0; i < wandCount; i++) { wands.Add(ViveWand.Wand(i)); } if (m_interactionWand && wands.Contains(m_interactionWand)) { if (wands[0] != m_interactionWand) { int indexOfInteractionWand = wands.IndexOf(m_interactionWand); ViveWand tmp = wands[0]; wands[0] = m_interactionWand; wands[indexOfInteractionWand] = tmp; } } foreach (ViveWand wand in wands) { if (!wand || !wand.gameObject.activeSelf) { continue; } if (!wand.upToDate) { wand.ForceUpdate(); } XperAction[] actions = Enum.GetValues(typeof(XperAction)) as XperAction[]; XperRange[] ranges = Enum.GetValues(typeof(XperRange)) as XperRange[]; foreach (XperRange tmpRange in ranges) { foreach (XperAction tmpAction in actions) { bool isAtRangeOfTestedWand = CheckAtRange(wand, tmpRange); m_isAtRangeOfWand |= isAtRangeOfTestedWand; if ((isAtRangeOfTestedWand || hasFocus) && CheckWandAction(wand, tmpAction, tmpRange)) { activationMode = tmpAction; activationRange = tmpRange; gripingWand = wand; break; } } if (gripingWand) { break; } } if (gripingWand) { break; } } range = activationRange; interactionWand = gripingWand; mode = activationMode; return(gripingWand != null); }