GizmoRenderTarget.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 quaternion = base.transform.rotation;
  53. base.OnRenderObject();
  54. if (this.target_trans != null && quaternion != base.transform.rotation)
  55. {
  56. if (this.rotate_limit_ != null)
  57. {
  58. bool flag;
  59. quaternion = this.rotate_limit_.GetLimitedLocalRotation(this.target_trans.localRotation, out flag);
  60. if (flag)
  61. {
  62. this.target_trans.localRotation = quaternion;
  63. base.transform.rotation = this.target_trans.rotation;
  64. }
  65. else
  66. {
  67. this.target_trans.rotation = base.transform.rotation;
  68. }
  69. }
  70. else
  71. {
  72. this.target_trans.rotation = base.transform.rotation;
  73. }
  74. }
  75. }
  76. public Transform target_trans;
  77. public IKManager ik_mgr;
  78. private Transform backup_trans_;
  79. private RotationLimit rotate_limit_;
  80. }