GravityTransformControl.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using wf;
  5. public class GravityTransformControl : MonoBehaviour
  6. {
  7. public bool isEnabled
  8. {
  9. get
  10. {
  11. return this.isEnabled_;
  12. }
  13. set
  14. {
  15. this.isEnabled_ = false;
  16. if (value && this.isValid)
  17. {
  18. this.isEnabled_ = true;
  19. }
  20. }
  21. }
  22. public bool isValid
  23. {
  24. get
  25. {
  26. return (this.dynamickirtBones != null && this.dynamickirtBones.Count != 0) || (this.dynamicBones != null && this.dynamicBones.Count != 0);
  27. }
  28. }
  29. public bool visibleTransTargetObject
  30. {
  31. get
  32. {
  33. return this.transTargetObject != null && this.transTargetObject.axis_obj.Visible;
  34. }
  35. set
  36. {
  37. if (this.transTargetObject != null)
  38. {
  39. this.transTargetObject.axis_obj.Visible = value;
  40. }
  41. }
  42. }
  43. private void Awake()
  44. {
  45. if (this.maidBody != null)
  46. {
  47. return;
  48. }
  49. Transform parent = base.transform.parent;
  50. while (parent != null)
  51. {
  52. this.maidBody = parent.GetComponent<TBody>();
  53. if (this.maidBody != null)
  54. {
  55. break;
  56. }
  57. parent = parent.parent;
  58. }
  59. }
  60. public void SetTargetSlods(TBody.SlotID[] slotIds)
  61. {
  62. this.Awake();
  63. this.targetSloatIds = slotIds;
  64. this.dynamickirtBones.Clear();
  65. this.dynamicBones.Clear();
  66. foreach (TBody.SlotID index in slotIds)
  67. {
  68. if (this.maidBody.goSlot[(int)index] != null && !(this.maidBody.goSlot[(int)index].obj == null))
  69. {
  70. DynamicSkirtBone component = this.maidBody.goSlot[(int)index].obj.GetComponent<DynamicSkirtBone>();
  71. if (component != null)
  72. {
  73. this.dynamickirtBones.Add(new KeyValuePair<DynamicSkirtBone, Vector3>(component, component.m_vGravity));
  74. }
  75. DynamicBone component2 = this.maidBody.goSlot[(int)index].obj.GetComponent<DynamicBone>();
  76. if (component2 != null)
  77. {
  78. this.dynamicBones.Add(new KeyValuePair<DynamicBone, Vector3>(component2, component2.m_Force));
  79. }
  80. }
  81. }
  82. }
  83. public bool OnChangeMekure()
  84. {
  85. bool flag = false;
  86. foreach (KeyValuePair<DynamicSkirtBone, Vector3> keyValuePair in this.dynamickirtBones)
  87. {
  88. if (keyValuePair.Key == null)
  89. {
  90. flag = true;
  91. break;
  92. }
  93. }
  94. if (!flag)
  95. {
  96. foreach (KeyValuePair<DynamicBone, Vector3> keyValuePair2 in this.dynamicBones)
  97. {
  98. if (keyValuePair2.Key == null)
  99. {
  100. flag = true;
  101. break;
  102. }
  103. }
  104. }
  105. if (flag)
  106. {
  107. this.SetTargetSlods(this.targetSloatIds);
  108. }
  109. return true;
  110. }
  111. public void Update()
  112. {
  113. Vector3 b = Vector3.zero;
  114. Vector3 vector = base.transform.localPosition;
  115. vector = new Vector3(Mathf.Max(Mathf.Min(1f, vector.x), -1f), Mathf.Max(Mathf.Min(1f, vector.y), -1f), Mathf.Max(Mathf.Min(1f, vector.z), -1f));
  116. base.transform.localPosition = vector;
  117. if (!this.isEnabled)
  118. {
  119. vector = Vector3.zero;
  120. }
  121. if (!wf.Math.Approximately(vector, Vector3.zero))
  122. {
  123. b = vector * this.forceRate;
  124. }
  125. foreach (KeyValuePair<DynamicSkirtBone, Vector3> keyValuePair in this.dynamickirtBones)
  126. {
  127. DynamicSkirtBone key = keyValuePair.Key;
  128. Vector3 vector2 = keyValuePair.Value + b;
  129. if (!wf.Math.Approximately(key.m_vGravity, vector2))
  130. {
  131. key.m_vGravity = vector2;
  132. key.UpdateParameters();
  133. }
  134. }
  135. foreach (KeyValuePair<DynamicBone, Vector3> keyValuePair2 in this.dynamicBones)
  136. {
  137. DynamicBone key2 = keyValuePair2.Key;
  138. Vector3 vector3 = keyValuePair2.Value + b;
  139. if (!wf.Math.Approximately(key2.m_Force, vector3))
  140. {
  141. key2.m_Force = vector3;
  142. key2.UpdateParameters();
  143. }
  144. }
  145. }
  146. public float forceRate = 1f;
  147. public PhotoTransTargetObject transTargetObject;
  148. private TBody maidBody;
  149. private TBody.SlotID[] targetSloatIds;
  150. private List<KeyValuePair<DynamicSkirtBone, Vector3>> dynamickirtBones = new List<KeyValuePair<DynamicSkirtBone, Vector3>>();
  151. private List<KeyValuePair<DynamicBone, Vector3>> dynamicBones = new List<KeyValuePair<DynamicBone, Vector3>>();
  152. private bool isEnabled_;
  153. }