public void Awake() { InteractiveRigidbody irb = GetComponent <InteractiveRigidbody>(); irb.OnHoverStart.AddListener(OnHoverStart); irb.OnHoverEnd.AddListener(OnHoverEnd); irb.OnGrabStart.AddListener(OnGrabStart); irb.OnGrabEnd.AddListener(OnGrabEnd); m_hover = m_grab = false; UpdateMaterials(); }
/// <summary> /// Update mesh polling center position to camera. /// </summary> void FixedUpdate() { if (m_handlerActive != null) { if (m_handlerActive.IsActivated()) { m_rotation = 0; m_lastRotation = transform.rotation.eulerAngles; } else if (m_handlerActive.IsActive()) { Vector3 newRot = transform.rotation.eulerAngles; // find delta rotation float deltaRot = newRot.z - m_lastRotation.z; // account for 360 degree jump while (deltaRot < -180) { deltaRot += 360; } while (deltaRot > +180) { deltaRot -= 360; } // This should only work when controller points horizontally // > diminish when |Y| component of forwards vector increases float changeFactor = 1 - Mathf.Abs(transform.forward.y); deltaRot *= changeFactor; // accumulate change (minus: clockwise = positive number) m_rotation += -deltaRot; // constrain to control curve limits m_rotation = Mathf.Clamp(m_rotation, Curve.keys[0].time, Curve.keys[Curve.length - 1].time); // actually change parameter InteractiveRigidbody irb = m_physicsGrabScript.GetActiveBody(); if ((Mathf.Abs(m_rotation) > 1) && (irb != null) && irb.CanScale) { float relScaleFactor = 1.0f + Curve.Evaluate(m_rotation) * Time.fixedDeltaTime; Vector3 oldScale = irb.Rigidbody.transform.localScale; Vector3 newScale = oldScale * relScaleFactor; Vector3 pivot = m_physicsGrabScript.GetGrabPoint(); Vector3 posDiff = irb.Rigidbody.transform.position - pivot; irb.Rigidbody.MovePosition(pivot + posDiff * relScaleFactor); irb.Rigidbody.transform.localScale = newScale; } m_lastRotation = newRot; } } }
private void OnGrabEnd(InteractiveRigidbody _rb, GameObject _other) { m_grab = false; UpdateMaterials(); }
private void OnGrabStart(InteractiveRigidbody _rb, GameObject _other) { m_grab = true; UpdateMaterials(); }
private void OnHoverEnd(InteractiveRigidbody _rb, GameObject _other) { m_hover = false; UpdateMaterials(); }
private void OnHoverStart(InteractiveRigidbody _rb, GameObject _other) { m_hover = true; UpdateMaterials(); }