WindowPartsTransform.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class WindowPartsTransform : MonoBehaviour
  5. {
  6. public virtual void Awake()
  7. {
  8. this.visible_setting_btn_dic_ = new Dictionary<string, UIWFTabButton>();
  9. if (this.VisibleSettingTab != null)
  10. {
  11. this.VisibleSettingTab.UpdateChildren();
  12. if (this.PosInput != null)
  13. {
  14. this.visible_setting_btn_dic_.Add("move", UTY.GetChildObject(this.VisibleSettingTab.gameObject, "MoveBtn/Btn", false).GetComponent<UIWFTabButton>());
  15. EventDelegate.Add(this.visible_setting_btn_dic_["move"].onClick, delegate()
  16. {
  17. this.axis_visible_type_ = WindowPartsTransform.AxisVisibleType.Position;
  18. this.OnChangeAxisVisibleType();
  19. });
  20. }
  21. else
  22. {
  23. UTY.GetChildObject(this.VisibleSettingTab.gameObject, "MoveBtn/Btn", false).SetActive(false);
  24. }
  25. if (this.RotateInput != null)
  26. {
  27. this.visible_setting_btn_dic_.Add("rotate", UTY.GetChildObject(this.VisibleSettingTab.gameObject, "RotateBtn/Btn", false).GetComponent<UIWFTabButton>());
  28. EventDelegate.Add(this.visible_setting_btn_dic_["rotate"].onClick, delegate()
  29. {
  30. this.axis_visible_type_ = WindowPartsTransform.AxisVisibleType.Rotate;
  31. this.OnChangeAxisVisibleType();
  32. });
  33. }
  34. else
  35. {
  36. UTY.GetChildObject(this.VisibleSettingTab.gameObject, "RotateBtn/Btn", false).SetActive(false);
  37. }
  38. if (this.PosInput != null || this.RotateInput != null)
  39. {
  40. this.visible_setting_btn_dic_.Add("unvisible", UTY.GetChildObject(this.VisibleSettingTab.gameObject, "UnVisibleBtn/Btn", false).GetComponent<UIWFTabButton>());
  41. EventDelegate.Add(this.visible_setting_btn_dic_["unvisible"].onClick, delegate()
  42. {
  43. this.axis_visible_type_ = WindowPartsTransform.AxisVisibleType.UnVisible;
  44. this.OnChangeAxisVisibleType();
  45. });
  46. }
  47. else
  48. {
  49. UTY.GetChildObject(this.VisibleSettingTab.gameObject, "UnVisibleBtn/Btn", false).SetActive(false);
  50. }
  51. if (this.visible_setting_btn_dic_.Count == 0)
  52. {
  53. this.VisibleSettingTab.gameObject.SetActive(false);
  54. }
  55. else
  56. {
  57. this.VisibleSettingTab.GetComponentInChildren<UIGrid>().Reposition();
  58. }
  59. }
  60. if (this.PosInput != null)
  61. {
  62. this.axis_visible_type = WindowPartsTransform.AxisVisibleType.Position;
  63. }
  64. else
  65. {
  66. this.axis_visible_type = WindowPartsTransform.AxisVisibleType.UnVisible;
  67. }
  68. }
  69. public virtual void Start()
  70. {
  71. }
  72. public virtual void SetObject(GameObject target_object)
  73. {
  74. this.target_object_ = target_object;
  75. Transform target_trans = null;
  76. if (this.target_object_ != null)
  77. {
  78. target_trans = this.target_object_.transform;
  79. }
  80. if (this.PosInput != null)
  81. {
  82. this.PosInput.SetTarget(target_trans, Vector3.zero);
  83. }
  84. if (this.RotateInput != null)
  85. {
  86. this.RotateInput.SetTarget(target_trans, Vector3.zero);
  87. }
  88. if (this.ScaleInput != null)
  89. {
  90. this.ScaleInput.SetTarget(target_trans, new Vector3(this.ScaleInput.SliderMin, this.ScaleInput.SliderMin, this.ScaleInput.SliderMin));
  91. }
  92. }
  93. public virtual void SetObject(GameObject target_object, Vector3 init_pos, Vector3 init_rotate, Vector3 init_scale)
  94. {
  95. this.target_object_ = target_object;
  96. Transform target_trans = null;
  97. if (this.target_object_ != null)
  98. {
  99. target_trans = this.target_object_.transform;
  100. }
  101. if (this.PosInput != null)
  102. {
  103. this.PosInput.SetTarget(target_trans, init_pos);
  104. }
  105. if (this.RotateInput != null)
  106. {
  107. this.RotateInput.SetTarget(target_trans, init_rotate);
  108. }
  109. if (this.ScaleInput != null)
  110. {
  111. this.ScaleInput.SetTarget(target_trans, init_scale);
  112. }
  113. }
  114. public void NextAxis()
  115. {
  116. if (this.axis_visible_type == WindowPartsTransform.AxisVisibleType.Position)
  117. {
  118. this.axis_visible_type = WindowPartsTransform.AxisVisibleType.Rotate;
  119. }
  120. else if (this.axis_visible_type == WindowPartsTransform.AxisVisibleType.Rotate)
  121. {
  122. this.axis_visible_type = WindowPartsTransform.AxisVisibleType.UnVisible;
  123. }
  124. else if (this.axis_visible_type == WindowPartsTransform.AxisVisibleType.UnVisible)
  125. {
  126. this.axis_visible_type = WindowPartsTransform.AxisVisibleType.Position;
  127. }
  128. this.OnChangeAxisVisibleType();
  129. }
  130. public void SetEnabledAxisButton(bool pos, bool rotate)
  131. {
  132. if (this.PosInput != null)
  133. {
  134. this.visible_setting_btn_dic_["move"].isEnabled = pos;
  135. }
  136. if (this.RotateInput != null)
  137. {
  138. this.visible_setting_btn_dic_["rotate"].isEnabled = rotate;
  139. }
  140. }
  141. public WindowPartsTransform.AxisVisibleType axis_visible_type
  142. {
  143. get
  144. {
  145. return this.axis_visible_type_;
  146. }
  147. set
  148. {
  149. if (this.visible_setting_btn_dic_.Count == 0)
  150. {
  151. this.axis_visible_type_ = WindowPartsTransform.AxisVisibleType.UnVisible;
  152. return;
  153. }
  154. this.axis_visible_type_ = value;
  155. if (value == WindowPartsTransform.AxisVisibleType.Position)
  156. {
  157. if (this.visible_setting_btn_dic_.ContainsKey("move"))
  158. {
  159. this.VisibleSettingTab.Select(this.visible_setting_btn_dic_["move"]);
  160. }
  161. else
  162. {
  163. this.VisibleSettingTab.Select(this.visible_setting_btn_dic_["unvisible"]);
  164. }
  165. }
  166. else if (value == WindowPartsTransform.AxisVisibleType.Rotate)
  167. {
  168. if (this.visible_setting_btn_dic_.ContainsKey("rotate"))
  169. {
  170. this.VisibleSettingTab.Select(this.visible_setting_btn_dic_["rotate"]);
  171. }
  172. else
  173. {
  174. this.VisibleSettingTab.Select(this.visible_setting_btn_dic_["unvisible"]);
  175. }
  176. }
  177. else
  178. {
  179. this.VisibleSettingTab.Select(this.visible_setting_btn_dic_["unvisible"]);
  180. }
  181. }
  182. }
  183. protected virtual void OnChangeAxisVisibleType()
  184. {
  185. if (this.onChangeAxisVisibleType == null)
  186. {
  187. return;
  188. }
  189. for (int i = 0; i < this.onChangeAxisVisibleType.Count; i++)
  190. {
  191. this.onChangeAxisVisibleType[i]();
  192. }
  193. }
  194. public PhotTransInput PosInput;
  195. public PhotTransInput RotateInput;
  196. public PhotTransInput ScaleInput;
  197. public UIWFTabPanel VisibleSettingTab;
  198. public List<Action> onChangeAxisVisibleType = new List<Action>();
  199. private WindowPartsTransform.AxisVisibleType axis_visible_type_;
  200. private GameObject target_object_;
  201. private Dictionary<string, UIWFTabButton> visible_setting_btn_dic_;
  202. public enum AxisVisibleType
  203. {
  204. Position,
  205. Rotate,
  206. UnVisible
  207. }
  208. }