PhotTransInput.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. public class PhotTransInput : MonoBehaviour
  6. {
  7. public void Awake()
  8. {
  9. if (this.Type == PhotTransInput.BehaviorType.Scale)
  10. {
  11. NDebug.Assert(this.SliderXYZ != null);
  12. }
  13. if (this.InputXYZ != null)
  14. {
  15. EventDelegate.Add(this.InputXYZ.onChange, new EventDelegate.Callback(this.OnTextChange));
  16. EventDelegate.Add(this.SliderXYZ.onChange, new EventDelegate.Callback(this.OnSliderChange));
  17. }
  18. else
  19. {
  20. EventDelegate.Add(this.InputX.onChange, new EventDelegate.Callback(this.OnTextChange));
  21. EventDelegate.Add(this.InputY.onChange, new EventDelegate.Callback(this.OnTextChange));
  22. EventDelegate.Add(this.InputZ.onChange, new EventDelegate.Callback(this.OnTextChange));
  23. }
  24. this.btn_list_.Clear();
  25. this.btn_list_.Add(UTY.GetChildObject(base.gameObject, "Btns/ResetBtn", false).GetComponent<UIButton>());
  26. EventDelegate.Add(this.btn_list_[this.btn_list_.Count - 1].onClick, new EventDelegate.Callback(this.OnReset));
  27. EventDelegate eventDelegate = new EventDelegate(this, "OnMouseHoverIn");
  28. eventDelegate.parameters[0].value = "リセット";
  29. this.btn_list_[this.btn_list_.Count - 1].gameObject.GetComponent<UIEventTrigger>().onHoverOver.Add(eventDelegate);
  30. this.btn_list_.Add(UTY.GetChildObject(base.gameObject, "Btns/CopyBtn", false).GetComponent<UIButton>());
  31. EventDelegate.Add(this.btn_list_[this.btn_list_.Count - 1].onClick, new EventDelegate.Callback(this.OnCopy));
  32. eventDelegate = new EventDelegate(this, "OnMouseHoverIn");
  33. eventDelegate.parameters[0].value = "コピー";
  34. this.btn_list_[this.btn_list_.Count - 1].gameObject.GetComponent<UIEventTrigger>().onHoverOver.Add(eventDelegate);
  35. this.btn_list_.Add(UTY.GetChildObject(base.gameObject, "Btns/PasteBtn", false).GetComponent<UIButton>());
  36. EventDelegate.Add(this.btn_list_[this.btn_list_.Count - 1].onClick, new EventDelegate.Callback(this.OnPaste));
  37. eventDelegate = new EventDelegate(this, "OnMouseHoverIn");
  38. eventDelegate.parameters[0].value = "ペースト";
  39. this.btn_list_[this.btn_list_.Count - 1].gameObject.GetComponent<UIEventTrigger>().onHoverOver.Add(eventDelegate);
  40. for (int i = 0; i < this.btn_list_.Count; i++)
  41. {
  42. EventDelegate.Add(this.btn_list_[i].gameObject.GetComponent<UIEventTrigger>().onHoverOut, new EventDelegate.Callback(this.OnMouseHoverOut));
  43. EventDelegate.Add(this.btn_list_[i].gameObject.GetComponent<UIEventTrigger>().onRelease, new EventDelegate.Callback(this.OnMouseHoverOut));
  44. }
  45. this.SetTarget(null, Vector3.zero);
  46. }
  47. public void SetTarget(Transform target_trans, Vector3 init_vector)
  48. {
  49. this.SetInitVector(init_vector);
  50. this.target_trans_ = target_trans;
  51. if (this.target_trans_ != null)
  52. {
  53. for (int i = 0; i < this.btn_list_.Count; i++)
  54. {
  55. this.btn_list_[i].isEnabled = true;
  56. }
  57. if (this.InputX != null)
  58. {
  59. this.InputX.enabled = true;
  60. }
  61. if (this.InputY != null)
  62. {
  63. this.InputY.enabled = true;
  64. }
  65. if (this.InputZ != null)
  66. {
  67. this.InputZ.enabled = true;
  68. }
  69. if (this.InputXYZ != null)
  70. {
  71. this.InputXYZ.enabled = true;
  72. }
  73. if (this.SliderXYZ != null)
  74. {
  75. this.SliderXYZ.enabled = true;
  76. this.SliderXYZ.thumb.GetComponent<UIButton>().isEnabled = true;
  77. this.SliderXYZ.GetComponent<BoxCollider>().enabled = true;
  78. }
  79. this.UpdateInputValue();
  80. }
  81. else
  82. {
  83. for (int j = 0; j < this.btn_list_.Count; j++)
  84. {
  85. this.btn_list_[j].isEnabled = false;
  86. }
  87. if (this.InputX != null)
  88. {
  89. this.InputX.enabled = false;
  90. }
  91. if (this.InputY != null)
  92. {
  93. this.InputY.enabled = false;
  94. }
  95. if (this.InputZ != null)
  96. {
  97. this.InputZ.enabled = false;
  98. }
  99. if (this.InputXYZ != null)
  100. {
  101. this.InputXYZ.enabled = false;
  102. }
  103. if (this.SliderXYZ != null)
  104. {
  105. this.SliderXYZ.enabled = true;
  106. this.SliderXYZ.thumb.GetComponent<UIButton>().isEnabled = false;
  107. this.SliderXYZ.GetComponent<BoxCollider>().enabled = false;
  108. }
  109. this.bacup_pos_ = Vector3.zero;
  110. if (this.InputXYZ != null)
  111. {
  112. this.InputXYZ.value = string.Empty;
  113. }
  114. else
  115. {
  116. UIInput inputX = this.InputX;
  117. string text = string.Empty;
  118. this.InputZ.value = text;
  119. text = text;
  120. this.InputY.value = text;
  121. inputX.value = text;
  122. }
  123. if (this.SliderXYZ != null)
  124. {
  125. this.SliderXYZ.value = 0f;
  126. }
  127. }
  128. }
  129. public void SetInitVector(Vector3 init_vector)
  130. {
  131. this.init_vector_ = init_vector;
  132. }
  133. private void OnTextChange()
  134. {
  135. if (this.target_trans_ == null || this.fix_update_)
  136. {
  137. return;
  138. }
  139. float num = 0f;
  140. try
  141. {
  142. num = float.Parse(UIInput.current.value);
  143. }
  144. catch
  145. {
  146. return;
  147. }
  148. Vector3 num_vec = this.num_vec;
  149. if (this.InputX == UIInput.current)
  150. {
  151. num_vec.x = num;
  152. }
  153. else if (this.InputY == UIInput.current)
  154. {
  155. num_vec.y = num;
  156. }
  157. else if (this.InputZ == UIInput.current)
  158. {
  159. num_vec.z = num;
  160. }
  161. else if (this.InputXYZ == UIInput.current)
  162. {
  163. if (num < this.SliderMin)
  164. {
  165. num = this.SliderMin;
  166. }
  167. else if (this.SliderMax < num)
  168. {
  169. num = this.SliderMax;
  170. }
  171. this.SliderXYZ.value = (num - this.SliderMin) / (this.SliderMax - this.SliderMin);
  172. num = this.SliderMin + (this.SliderMax - this.SliderMin) * this.SliderXYZ.value;
  173. return;
  174. }
  175. this.num_vec = num_vec;
  176. this.bacup_pos_ = this.num_vec;
  177. }
  178. private void OnSliderChange()
  179. {
  180. if (this.target_trans_ == null || this.fix_update_)
  181. {
  182. return;
  183. }
  184. float z = 1f;
  185. try
  186. {
  187. z = this.SliderMin + (this.SliderMax - this.SliderMin) * this.SliderXYZ.value;
  188. }
  189. catch
  190. {
  191. return;
  192. }
  193. Vector3 num_vec = this.num_vec;
  194. num_vec.x = (num_vec.y = (num_vec.z = z));
  195. this.fix_update_ = true;
  196. this.InputXYZ.value = z.ToString("G9");
  197. this.fix_update_ = false;
  198. this.num_vec = num_vec;
  199. this.bacup_pos_ = this.num_vec;
  200. }
  201. public void LateUpdate()
  202. {
  203. if (this.target_trans_ == null)
  204. {
  205. return;
  206. }
  207. Vector3 num_vec = this.num_vec;
  208. if (this.bacup_pos_ != num_vec)
  209. {
  210. this.UpdateInputValue();
  211. }
  212. }
  213. public void UpdateInputValue()
  214. {
  215. Vector3 num_vec = this.num_vec;
  216. this.fix_update_ = true;
  217. if (this.InputXYZ != null)
  218. {
  219. this.InputXYZ.value = num_vec.x.ToString("G9");
  220. }
  221. else
  222. {
  223. this.InputX.value = num_vec.x.ToString("G9");
  224. this.InputY.value = num_vec.y.ToString("G9");
  225. this.InputZ.value = num_vec.z.ToString("G9");
  226. }
  227. if (this.SliderXYZ != null)
  228. {
  229. this.SliderXYZ.value = (num_vec.x - this.SliderMin) / (this.SliderMax - this.SliderMin);
  230. }
  231. this.fix_update_ = false;
  232. this.bacup_pos_ = num_vec;
  233. }
  234. public void OnReset()
  235. {
  236. if (this.target_trans_ == null)
  237. {
  238. return;
  239. }
  240. this.num_vec = this.init_vector_;
  241. this.UpdateInputValue();
  242. }
  243. public void OnCopy()
  244. {
  245. if (this.target_trans_ == null)
  246. {
  247. return;
  248. }
  249. this.UpdateInputValue();
  250. Vector3 num_vec = this.num_vec;
  251. StringWriter stringWriter = new StringWriter();
  252. stringWriter.WriteLine(num_vec.x);
  253. stringWriter.WriteLine(num_vec.y);
  254. stringWriter.WriteLine(num_vec.z);
  255. BasePhotoWindowManager.SetCopyData(this.copy_data_title, stringWriter.ToString());
  256. }
  257. public void OnPaste()
  258. {
  259. if (this.target_trans_ == null)
  260. {
  261. return;
  262. }
  263. string copyData = BasePhotoWindowManager.GetCopyData(this.copy_data_title);
  264. if (string.IsNullOrEmpty(copyData))
  265. {
  266. return;
  267. }
  268. StringReader stringReader = new StringReader(copyData);
  269. try
  270. {
  271. this.num_vec = new Vector3
  272. {
  273. x = float.Parse(stringReader.ReadLine()),
  274. y = float.Parse(stringReader.ReadLine()),
  275. z = float.Parse(stringReader.ReadLine())
  276. };
  277. }
  278. catch
  279. {
  280. return;
  281. }
  282. this.UpdateInputValue();
  283. }
  284. public void OnMouseHoverIn(string text)
  285. {
  286. MouseExposition @object = MouseExposition.GetObject();
  287. @object.text = text;
  288. }
  289. public void OnMouseHoverOut()
  290. {
  291. MouseExposition @object = MouseExposition.GetObject();
  292. @object.text = string.Empty;
  293. }
  294. public Vector3 num_vec
  295. {
  296. get
  297. {
  298. Vector3 result;
  299. if (this.Type == PhotTransInput.BehaviorType.Pos)
  300. {
  301. result = this.target_trans_.localPosition;
  302. }
  303. else if (this.Type == PhotTransInput.BehaviorType.Rotate)
  304. {
  305. result = this.target_trans_.localRotation.eulerAngles;
  306. }
  307. else
  308. {
  309. result = this.target_trans_.localScale;
  310. }
  311. return result;
  312. }
  313. set
  314. {
  315. if (this.Type == PhotTransInput.BehaviorType.Pos)
  316. {
  317. this.target_trans_.localPosition = value;
  318. }
  319. else if (this.Type == PhotTransInput.BehaviorType.Rotate)
  320. {
  321. this.target_trans_.rotation = Quaternion.Euler(value);
  322. }
  323. else
  324. {
  325. this.target_trans_.localScale = value;
  326. }
  327. }
  328. }
  329. private string copy_data_title
  330. {
  331. get
  332. {
  333. return "PhotTransInput_" + this.Type.ToString();
  334. }
  335. }
  336. public PhotTransInput.BehaviorType Type;
  337. public UIInput InputX;
  338. public UIInput InputY;
  339. public UIInput InputZ;
  340. public UIInput InputXYZ;
  341. public UISlider SliderXYZ;
  342. public float SliderMin;
  343. public float SliderMax;
  344. private List<UIButton> btn_list_ = new List<UIButton>();
  345. private Transform target_trans_;
  346. private Vector3 bacup_pos_ = Vector3.zero;
  347. private bool fix_update_;
  348. private Vector3 init_vector_ = Vector3.zero;
  349. public enum BehaviorType
  350. {
  351. Pos,
  352. Rotate,
  353. Scale
  354. }
  355. }