/// <summary> /// Create all necessary resources. /// </summary> private void SetupManipulation() { TakeDownManipulation(); if (userOriented) { boundingBox = owner.gameObject.AddComponent <BoundingBox>(); boundingBox.HideElementsInInspector = false; boundingBox.BoundingBoxActivation = BoundingBox.BoundingBoxActivationType.ActivateByProximityAndPointer; boundingBox.RotateStarted.AddListener(BeginManipulation); boundingBox.RotateStopped.AddListener(FinishManipulation); boundingBox.ScaleStarted.AddListener(BeginManipulation); boundingBox.ScaleStopped.AddListener(FinishManipulation); float maxScaleFactor = 8.0f; float minScaleFactor = 0.2f; MinMaxScaleConstraint scaleHandler = owner.GetComponent <MinMaxScaleConstraint>(); if (scaleHandler == null) { scaleHandler = owner.gameObject.AddComponent <MinMaxScaleConstraint>(); } scaleHandler.RelativeToInitialState = true; scaleHandler.ScaleMaximum = maxScaleFactor; scaleHandler.ScaleMinimum = minScaleFactor; } manipulationHandler = owner.gameObject.AddComponent <ManipulationHandler>(); manipulationHandler.OneHandRotationModeFar = ManipulationHandler.RotateInOneHandType.MaintainOriginalRotation; manipulationHandler.OneHandRotationModeNear = ManipulationHandler.RotateInOneHandType.MaintainOriginalRotation; manipulationHandler.ConstraintOnRotation = Toolkit.Utilities.RotationConstraintType.None; manipulationHandler.OnManipulationStarted.AddListener(BeginManipulation); manipulationHandler.OnManipulationEnded.AddListener(FinishManipulation); nearGrabbable = owner.gameObject.AddComponent <NearInteractionGrabbable>(); }
/// <summary> /// 初期化処理を実施します /// </summary> private void OnEnable() { if (isInitialized) { return; } isInitialized = true; manipulationHandler = GetComponent <ManipulationHandler>(); interactionGrabbable = GetComponent <NearInteractionGrabbable>(); handInteractionHint = GetComponentInChildren <HandInteractionHint>(); arrowAnimate = GetComponentInChildren <ArrowAnimate>(); toolTip = GetComponentInChildren <ToolTip>(); systemKeyboardInputHelper = GetComponentInChildren <SystemKeyboardInputHelper>(); pos1 = handInteractionHint.transform.GetChild(1).transform.position; pos2 = handInteractionHint.transform.GetChild(2).transform.position; }
/// <summary> /// Create all necessary resources. /// </summary> private void SetupManipulation() { TakeDownManipulation(); if (userOriented) { boundingBox = owner.gameObject.AddComponent <BoundingBox>(); boundingBox.HideElementsInInspector = false; boundingBox.BoundingBoxActivation = BoundingBox.BoundingBoxActivationType.ActivateByProximityAndPointer; boundingBox.RotateStarted.AddListener(BeginManipulation); boundingBox.RotateStopped.AddListener(FinishManipulation); boundingBox.ScaleStarted.AddListener(BeginManipulation); boundingBox.ScaleStopped.AddListener(FinishManipulation); float maxScaleFactor = 8.0f; float minScaleFactor = 0.2f; MinMaxScaleConstraint scaleHandler = owner.GetComponent <MinMaxScaleConstraint>(); if (scaleHandler == null) { scaleHandler = owner.gameObject.AddComponent <MinMaxScaleConstraint>(); } scaleHandler.RelativeToInitialState = true; scaleHandler.ScaleMaximum = maxScaleFactor; scaleHandler.ScaleMinimum = minScaleFactor; } manipulationHandler = owner.gameObject.AddComponent <ObjectManipulator>(); var rotationAxisConstraint = owner.gameObject.AddComponent <RotationAxisConstraint>(); rotationAxisConstraint.HandType = Toolkit.Utilities.ManipulationHandFlags.OneHanded | Toolkit.Utilities.ManipulationHandFlags.TwoHanded; rotationAxisConstraint.ProximityType = Toolkit.Utilities.ManipulationProximityFlags.Near | Toolkit.Utilities.ManipulationProximityFlags.Far; rotationAxisConstraint.ConstraintOnRotation = 0; var fixedRotationToWorldConstraint = owner.gameObject.AddComponent <FixedRotationToWorldConstraint>(); fixedRotationToWorldConstraint.HandType = Toolkit.Utilities.ManipulationHandFlags.OneHanded; fixedRotationToWorldConstraint.ProximityType = Toolkit.Utilities.ManipulationProximityFlags.Near | Toolkit.Utilities.ManipulationProximityFlags.Far; manipulationHandler.OnManipulationStarted.AddListener(BeginManipulation); manipulationHandler.OnManipulationEnded.AddListener(FinishManipulation); nearGrabbable = owner.gameObject.AddComponent <NearInteractionGrabbable>(); }
public void Update() { TetherVisualsEnabled = false; if (_nearPointer != null && _nearPointer.IsFocusLocked && _nearPointer.IsTargetPositionLockedOnFocusLock && _nearPointer.Result != null) { NearInteractionGrabbable grabbedObject = GetGrabbedObject(); if (grabbedObject != null && grabbedObject.ShowTetherWhenManipulating) { Vector3 graspPosition; _nearPointer.TryGetNearGraspPoint(out graspPosition); tetherLine.FirstPoint = graspPosition; Vector3 endPoint = pointer.Result.Details.Object.transform.TransformPoint(pointer.Result.Details.PointLocalSpace); tetherLine.LastPoint = endPoint; TetherVisualsEnabled = Vector3.Distance(tetherLine.FirstPoint, tetherLine.LastPoint) > minTetherLength; tetherLine.enabled = TetherVisualsEnabled; tetherEndPoint.gameObject.SetActive(TetherVisualsEnabled); tetherEndPoint.position = endPoint; } } visualsRoot.gameObject.SetActive(TetherVisualsEnabled); }
public bool TryUpdateQueryBufferForLayerMask(LayerMask layerMask, Vector3 pointerPosition, QueryTriggerInteraction triggerInteraction) { grabbable = null; numColliders = UnityEngine.Physics.OverlapSphereNonAlloc( pointerPosition, queryRadius, queryBuffer, layerMask, triggerInteraction); if (numColliders == queryBuffer.Length) { Debug.LogFormat(LogType.Warning, LogOption.NoStacktrace, null, $"Maximum number of {numColliders} colliders found in SpherePointer overlap query. Consider increasing the query buffer size in the pointer profile."); } for (int i = 0; i < numColliders; i++) { if (grabbable = queryBuffer[i].GetComponent <NearInteractionGrabbable>()) { return(true); } } return(false); }
/// <summary> /// Clean up all resources. /// </summary> private void TakeDownManipulation() { boundingBox = null; manipulationHandler = null; nearGrabbable = null; }