LagRotation.cs 915 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using UnityEngine;
  3. [AddComponentMenu("NGUI/Examples/Lag Rotation")]
  4. public class LagRotation : MonoBehaviour
  5. {
  6. public void OnRepositionEnd()
  7. {
  8. this.Interpolate(1000f);
  9. }
  10. private void Interpolate(float delta)
  11. {
  12. if (this.mTrans != null)
  13. {
  14. Transform parent = this.mTrans.parent;
  15. if (parent != null)
  16. {
  17. this.mAbsolute = Quaternion.Slerp(this.mAbsolute, parent.rotation * this.mRelative, delta * this.speed);
  18. this.mTrans.rotation = this.mAbsolute;
  19. }
  20. }
  21. }
  22. private void Start()
  23. {
  24. this.mTrans = base.transform;
  25. this.mRelative = this.mTrans.localRotation;
  26. this.mAbsolute = this.mTrans.rotation;
  27. }
  28. private void Update()
  29. {
  30. this.Interpolate((!this.ignoreTimeScale) ? Time.deltaTime : RealTime.deltaTime);
  31. }
  32. public float speed = 10f;
  33. public bool ignoreTimeScale;
  34. private Transform mTrans;
  35. private Quaternion mRelative;
  36. private Quaternion mAbsolute;
  37. }