protected void OnSelect() { dragRaycaster = interactiveItem.SelectingRaycaster; if (dragRaycaster) { flexLaserVisual = dragRaycaster.gameObject.GetComponentInChildren <FlexLaserVisual>(true); } if (flexLaserVisual) { flexLaserVisual.SelectedObject = transform; } originPos = transform.position; originRot = transform.rotation; originScale = transform.localScale; if (rigidbodyCmp == null) { InitRigidbody(); } initialControllerOrientation = ControlTransform.rotation; // Store inverse initial controller quaternion, for performance. inverseControllerOrientation = Quaternion.Inverse(initialControllerOrientation); // Perform the transformation relative to control. Vector3 vectorToObject = transform.position - ControlPosition; float d = vectorToObject.magnitude; controlTransformPosition = transform.position; objectStartRotation = transform.rotation; verifyRotation = Quaternion.identity; // If the distance vector cannot be normalized, use the look vector. if (d > NORMALIZATION_EPSILON) { normalizedForward = vectorToObject / d; } else { d = 0; normalizedForward = ControlForward; } // Reset distance interpolation values to current values. targetControlZDistance = controlZDistance = d; // Reset orientation interpolation values to 0. targetOrientationDelta = orientationDelta = Quaternion.identity; // Get the up vector for the object. Vector3 objectUp = transform.TransformDirection(Vector3.up); // Get the dot product of the object up vector and the world up vector. float dotUp = Vector3.Dot(objectUp, Vector3.up); // Mark whether the object is upside down or rightside up. objectInverted = dotUp < 0; lastStateChangeFrame = Time.frameCount; }
protected void OnDeselect() { if (flexLaserVisual) { flexLaserVisual.SelectedObject = null; } flexLaserVisual = null; ResetRigidbody(); lastStateChangeFrame = Time.frameCount; }