GizmoRenderTarget.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using RootMotion.FinalIK;
  3. using UnityEngine;
  4. public class GizmoRenderTarget : GizmoRender
  5. {
  6. public void OnEnable()
  7. {
  8. if (this.backup_trans_ == null)
  9. {
  10. return;
  11. }
  12. this.rotate_limit_ = null;
  13. if (this.target_trans != null)
  14. {
  15. this.rotate_limit_ = this.GetLimitComponet();
  16. }
  17. }
  18. private RotationLimit GetLimitComponet()
  19. {
  20. if (this.target_trans == null)
  21. {
  22. return null;
  23. }
  24. return this.target_trans.gameObject.GetComponent<RotationLimit>();
  25. }
  26. public new void Update()
  27. {
  28. if (this.backup_trans_ != this.target_trans)
  29. {
  30. this.backup_trans_ = this.target_trans;
  31. this.rotate_limit_ = null;
  32. if (this.target_trans != null)
  33. {
  34. this.rotate_limit_ = this.GetLimitComponet();
  35. }
  36. }
  37. if (this.target_trans != null)
  38. {
  39. base.transform.position = this.target_trans.position;
  40. base.transform.rotation = this.target_trans.rotation;
  41. }
  42. }
  43. public override void OnDragEnd()
  44. {
  45. if (this.ik_mgr != null)
  46. {
  47. this.ik_mgr.HistoryPush();
  48. }
  49. }
  50. public override void OnRenderObject()
  51. {
  52. Quaternion rotation = base.transform.rotation;
  53. base.OnRenderObject();
  54. if (this.target_trans != null && rotation != base.transform.rotation)
  55. {
  56. this.target_trans.rotation = base.transform.rotation;
  57. if (this.rotate_limit_ != null)
  58. {
  59. this.rotate_limit_.Apply();
  60. }
  61. }
  62. }
  63. public Transform target_trans;
  64. public IKManager ik_mgr;
  65. private Transform backup_trans_;
  66. private RotationLimit rotate_limit_;
  67. }