GravityTransformControl.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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) || (this.dynamicYureBones != null && this.dynamicYureBones.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. this.dynamicYureBones.Clear();
  67. foreach (TBody.SlotID i2 in slotIds)
  68. {
  69. if (this.maidBody.goSlot[(int)i2] != null && !(this.maidBody.goSlot[(int)i2].obj == null))
  70. {
  71. DynamicSkirtBone component = this.maidBody.goSlot[(int)i2].obj.GetComponent<DynamicSkirtBone>();
  72. if (component != null)
  73. {
  74. this.dynamickirtBones.Add(new KeyValuePair<DynamicSkirtBone, Vector3>(component, component.m_vGravity));
  75. }
  76. DynamicBone component2 = this.maidBody.goSlot[(int)i2].obj.GetComponent<DynamicBone>();
  77. if (component2 != null)
  78. {
  79. this.dynamicBones.Add(new KeyValuePair<DynamicBone, Vector3>(component2, component2.m_Force));
  80. }
  81. DynamicYureBone component3 = this.maidBody.goSlot[(int)i2].obj.GetComponent<DynamicYureBone>();
  82. if (component3 != null)
  83. {
  84. this.dynamicYureBones.Add(new KeyValuePair<DynamicYureBone, Vector3>(component3, component3.status.force));
  85. }
  86. }
  87. }
  88. }
  89. public bool OnChangeMekure()
  90. {
  91. bool flag = false;
  92. foreach (KeyValuePair<DynamicSkirtBone, Vector3> keyValuePair in this.dynamickirtBones)
  93. {
  94. if (keyValuePair.Key == null)
  95. {
  96. flag = true;
  97. break;
  98. }
  99. }
  100. if (!flag)
  101. {
  102. foreach (KeyValuePair<DynamicBone, Vector3> keyValuePair2 in this.dynamicBones)
  103. {
  104. if (keyValuePair2.Key == null)
  105. {
  106. flag = true;
  107. break;
  108. }
  109. }
  110. }
  111. if (flag)
  112. {
  113. this.SetTargetSlods(this.targetSloatIds);
  114. }
  115. return true;
  116. }
  117. public void Update()
  118. {
  119. Vector3 b = Vector3.zero;
  120. Vector3 vector = base.transform.localPosition;
  121. 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));
  122. base.transform.localPosition = vector;
  123. if (!this.isEnabled)
  124. {
  125. vector = Vector3.zero;
  126. }
  127. if (!wf.Math.Approximately(vector, Vector3.zero))
  128. {
  129. b = vector * this.forceRate;
  130. }
  131. foreach (KeyValuePair<DynamicSkirtBone, Vector3> keyValuePair in this.dynamickirtBones)
  132. {
  133. DynamicSkirtBone key = keyValuePair.Key;
  134. Vector3 vector2 = keyValuePair.Value + b;
  135. if (!wf.Math.Approximately(key.m_vGravity, vector2))
  136. {
  137. key.m_vGravity = vector2;
  138. key.UpdateParameters();
  139. }
  140. }
  141. foreach (KeyValuePair<DynamicBone, Vector3> keyValuePair2 in this.dynamicBones)
  142. {
  143. DynamicBone key2 = keyValuePair2.Key;
  144. Vector3 vector3 = keyValuePair2.Value + b;
  145. if (!wf.Math.Approximately(key2.m_Force, vector3))
  146. {
  147. key2.m_Force = vector3;
  148. key2.UpdateParameters();
  149. }
  150. }
  151. foreach (KeyValuePair<DynamicYureBone, Vector3> keyValuePair3 in this.dynamicYureBones)
  152. {
  153. DynamicYureBone key3 = keyValuePair3.Key;
  154. Vector3 vector4 = keyValuePair3.Value + b;
  155. if (!wf.Math.Approximately(key3.status.force, vector4))
  156. {
  157. key3.status.force = vector4;
  158. key3.UpdateParameters();
  159. }
  160. }
  161. }
  162. public float forceRate = 1f;
  163. public PhotoTransTargetObject transTargetObject;
  164. private TBody maidBody;
  165. private TBody.SlotID[] targetSloatIds;
  166. private List<KeyValuePair<DynamicSkirtBone, Vector3>> dynamickirtBones = new List<KeyValuePair<DynamicSkirtBone, Vector3>>();
  167. private List<KeyValuePair<DynamicBone, Vector3>> dynamicBones = new List<KeyValuePair<DynamicBone, Vector3>>();
  168. private List<KeyValuePair<DynamicYureBone, Vector3>> dynamicYureBones = new List<KeyValuePair<DynamicYureBone, Vector3>>();
  169. private bool isEnabled_;
  170. }