CreativeRoomUIPlacementMaid.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Specialized;
  4. using UnityEngine;
  5. using UnityEngine.EventSystems;
  6. using UnityEngine.UI;
  7. public class CreativeRoomUIPlacementMaid : MonoBehaviour
  8. {
  9. private Maid targetMaid
  10. {
  11. get
  12. {
  13. if (this.m_TargetMaid == null)
  14. {
  15. this.m_TargetMaid = this.GetMaid(true);
  16. if (this.m_TargetMaid == null)
  17. {
  18. this.m_TargetMaid = this.GetMaid(false);
  19. }
  20. if (this.m_TargetMaid)
  21. {
  22. this.m_TargetMaid.body0.SetBoneHitHeightY(-1000f);
  23. }
  24. }
  25. return this.m_TargetMaid;
  26. }
  27. }
  28. private Maid GetMaid(bool searchLeader = true)
  29. {
  30. if (this.m_CharaMgr == null)
  31. {
  32. return null;
  33. }
  34. Maid maid = null;
  35. foreach (Maid maid2 in this.m_CharaMgr.GetStockMaidList())
  36. {
  37. if (maid2 != null)
  38. {
  39. if (!searchLeader || maid2.status.leader)
  40. {
  41. maid = maid2;
  42. break;
  43. }
  44. }
  45. }
  46. if (maid == null)
  47. {
  48. int maidCount = this.m_CharaMgr.GetMaidCount();
  49. for (int i = 0; i < maidCount; i++)
  50. {
  51. Maid maid3 = this.m_CharaMgr.GetMaid(i);
  52. if (maid3 != null)
  53. {
  54. if (!searchLeader || maid3.status.leader)
  55. {
  56. maid = maid3;
  57. break;
  58. }
  59. }
  60. }
  61. }
  62. return maid;
  63. }
  64. public float snapValuePosition
  65. {
  66. set
  67. {
  68. if (this.m_GizmoObject == null)
  69. {
  70. return;
  71. }
  72. this.m_GizmoObject.snapValuePosition = value;
  73. }
  74. }
  75. private void Awake()
  76. {
  77. this.m_CharaMgr = GameMain.Instance.CharacterMgr;
  78. GameObject gameObject;
  79. if (!(gameObject = GameObject.Find("[CreativeRoomUI Placement Maid] GizmoControlObject")))
  80. {
  81. gameObject = new GameObject("[CreativeRoomUI Placement Maid] GizmoControlObject");
  82. GizmoObject gizmoObject = gameObject.AddComponent<GizmoObject>();
  83. gizmoObject.activeAxis = true;
  84. gizmoObject.activeRot = false;
  85. gizmoObject.snapValuePosition = 0.5f;
  86. gizmoObject.snapValueAngles = 15f;
  87. gizmoObject.snapValueScale = 0.1f;
  88. gameObject.SetActive(false);
  89. }
  90. this.m_GizmoObject = gameObject.GetComponent<GizmoObject>();
  91. GizmoObject gizmoObject2 = this.m_GizmoObject;
  92. gizmoObject2.onChangePosition = (Action<Vector3>)Delegate.Combine(gizmoObject2.onChangePosition, new Action<Vector3>(this.OnUpdateGizmoPosition));
  93. GizmoObject gizmoObject3 = this.m_GizmoObject;
  94. gizmoObject3.onChangeRotation = (Action<Quaternion>)Delegate.Combine(gizmoObject3.onChangeRotation, new Action<Quaternion>(this.OnUpdateGizmoRotation));
  95. GizmoObject gizmoObject4 = this.m_GizmoObject;
  96. gizmoObject4.onChangeScale = (Action<Vector3>)Delegate.Combine(gizmoObject4.onChangeScale, new Action<Vector3>(this.OnUpdateGizmoScale));
  97. this.SetUpUI();
  98. }
  99. private void SetUpUI()
  100. {
  101. this.m_CachedTransformDataDic = new StringDictionary();
  102. this.m_InputFieldPosX.contentType = InputField.ContentType.DecimalNumber;
  103. this.m_InputFieldPosY.contentType = InputField.ContentType.DecimalNumber;
  104. this.m_InputFieldPosZ.contentType = InputField.ContentType.DecimalNumber;
  105. this.m_InputFieldRotX.contentType = InputField.ContentType.DecimalNumber;
  106. this.m_InputFieldRotY.contentType = InputField.ContentType.DecimalNumber;
  107. this.m_InputFieldRotZ.contentType = InputField.ContentType.DecimalNumber;
  108. this.m_InputFieldScale.contentType = InputField.ContentType.DecimalNumber;
  109. this.m_InputFieldPosX.text = this.m_GizmoObject.position.x.ToString("f3");
  110. this.m_InputFieldPosY.text = this.m_GizmoObject.position.y.ToString("f3");
  111. this.m_InputFieldPosZ.text = this.m_GizmoObject.position.z.ToString("f3");
  112. this.m_InputFieldRotX.text = this.m_GizmoObject.eulerAngles.x.ToString("f3");
  113. this.m_InputFieldRotY.text = this.m_GizmoObject.eulerAngles.y.ToString("f3");
  114. this.m_InputFieldRotZ.text = this.m_GizmoObject.eulerAngles.z.ToString("f3");
  115. this.m_InputFieldScale.text = this.m_GizmoObject.scale.x.ToString("f3");
  116. this.m_SliderScale.value = this.m_GizmoObject.scale.x;
  117. Action<InputField, Action<float>, Action> action = delegate(InputField input, Action<float> act_change, Action act_end)
  118. {
  119. input.onValueChanged.AddListener(delegate(string str)
  120. {
  121. float obj;
  122. if (float.TryParse(str, out obj))
  123. {
  124. act_change(obj);
  125. }
  126. });
  127. input.onEndEdit.AddListener(delegate(string str)
  128. {
  129. act_end();
  130. });
  131. };
  132. action(this.m_InputFieldPosX, delegate(float value)
  133. {
  134. Vector3 position = this.m_GizmoObject.position;
  135. position.x = value;
  136. this.m_GizmoObject.position = position;
  137. }, delegate
  138. {
  139. this.m_InputFieldPosX.text = this.m_GizmoObject.position.x.ToString("f3");
  140. });
  141. action(this.m_InputFieldPosY, delegate(float value)
  142. {
  143. Vector3 position = this.m_GizmoObject.position;
  144. position.y = value;
  145. this.m_GizmoObject.position = position;
  146. }, delegate
  147. {
  148. this.m_InputFieldPosY.text = this.m_GizmoObject.position.y.ToString("f3");
  149. });
  150. action(this.m_InputFieldPosZ, delegate(float value)
  151. {
  152. Vector3 position = this.m_GizmoObject.position;
  153. position.z = value;
  154. this.m_GizmoObject.position = position;
  155. }, delegate
  156. {
  157. this.m_InputFieldPosZ.text = this.m_GizmoObject.position.z.ToString("f3");
  158. });
  159. action(this.m_InputFieldRotX, delegate(float value)
  160. {
  161. Vector3 eulerAngles = this.m_GizmoObject.eulerAngles;
  162. eulerAngles.x = value;
  163. this.m_GizmoObject.eulerAngles = eulerAngles;
  164. }, delegate
  165. {
  166. this.m_InputFieldRotX.text = this.m_GizmoObject.eulerAngles.x.ToString("f3");
  167. });
  168. action(this.m_InputFieldRotY, delegate(float value)
  169. {
  170. Vector3 eulerAngles = this.m_GizmoObject.eulerAngles;
  171. eulerAngles.y = value;
  172. this.m_GizmoObject.eulerAngles = eulerAngles;
  173. }, delegate
  174. {
  175. this.m_InputFieldRotY.text = this.m_GizmoObject.eulerAngles.y.ToString("f3");
  176. });
  177. action(this.m_InputFieldRotZ, delegate(float value)
  178. {
  179. Vector3 eulerAngles = this.m_GizmoObject.eulerAngles;
  180. eulerAngles.z = value;
  181. this.m_GizmoObject.eulerAngles = eulerAngles;
  182. }, delegate
  183. {
  184. this.m_InputFieldRotZ.text = this.m_GizmoObject.eulerAngles.z.ToString("f3");
  185. });
  186. action(this.m_InputFieldScale, delegate(float value)
  187. {
  188. Vector3 scale = this.m_GizmoObject.scale;
  189. value = Mathf.Clamp(value, this.m_SliderScale.minValue, this.m_SliderScale.maxValue);
  190. if (Mathf.Approximately(scale.x, value))
  191. {
  192. return;
  193. }
  194. scale.x = (scale.y = (scale.z = value));
  195. this.m_GizmoObject.scale = scale;
  196. this.m_SliderScale.value = value;
  197. }, delegate
  198. {
  199. this.m_InputFieldScale.text = this.m_GizmoObject.scale.x.ToString("f3");
  200. });
  201. this.m_SliderScale.onValueChanged.AddListener(delegate(float value)
  202. {
  203. if (Mathf.Approximately(this.m_GizmoObject.cachedSnapScale.x, value))
  204. {
  205. return;
  206. }
  207. this.m_GizmoObject.nonCallbackScale = Vector3.one * value;
  208. float x = this.m_GizmoObject.cachedSnapScale.x;
  209. this.m_SliderScale.value = x;
  210. if (!this.m_InputFieldScale.isFocused)
  211. {
  212. this.m_InputFieldScale.text = x.ToString("f3");
  213. }
  214. });
  215. }
  216. private void Update()
  217. {
  218. if (this.targetMaid == null || !this.targetMaid.Visible)
  219. {
  220. this.m_GizmoObject.gameObject.SetActive(false);
  221. return;
  222. }
  223. if (EventSystem.current != null)
  224. {
  225. if (NInput.GetMouseButtonDown(0))
  226. {
  227. GameObject currentSelectedGameObject = EventSystem.current.currentSelectedGameObject;
  228. if (EventSystem.current.IsPointerOverGameObject() && currentSelectedGameObject && currentSelectedGameObject.GetComponent<RectTransform>())
  229. {
  230. this.m_GizmoObject.gameObject.SetActive(false);
  231. }
  232. }
  233. else if (NInput.GetMouseButtonUp(0))
  234. {
  235. this.m_GizmoObject.gameObject.SetActive(true);
  236. }
  237. }
  238. }
  239. private void OnUpdateGizmoPosition(Vector3 position)
  240. {
  241. if (this.targetMaid != null)
  242. {
  243. this.targetMaid.transform.position = position;
  244. if (!this.m_InputFieldPosX.isFocused)
  245. {
  246. this.m_InputFieldPosX.text = position.x.ToString("f3");
  247. }
  248. if (!this.m_InputFieldPosY.isFocused)
  249. {
  250. this.m_InputFieldPosY.text = position.y.ToString("f3");
  251. }
  252. if (!this.m_InputFieldPosZ.isFocused)
  253. {
  254. this.m_InputFieldPosZ.text = position.z.ToString("f3");
  255. }
  256. }
  257. }
  258. private void OnUpdateGizmoRotation(Quaternion rotation)
  259. {
  260. if (this.targetMaid != null)
  261. {
  262. this.targetMaid.transform.rotation = rotation;
  263. Vector3 eulerAngles = rotation.eulerAngles;
  264. if (!this.m_InputFieldRotX.isFocused)
  265. {
  266. this.m_InputFieldRotX.text = eulerAngles.x.ToString("f3");
  267. }
  268. if (!this.m_InputFieldRotY.isFocused)
  269. {
  270. this.m_InputFieldRotY.text = eulerAngles.y.ToString("f3");
  271. }
  272. if (!this.m_InputFieldRotZ.isFocused)
  273. {
  274. this.m_InputFieldRotZ.text = eulerAngles.z.ToString("f3");
  275. }
  276. }
  277. }
  278. private void OnUpdateGizmoScale(Vector3 scale)
  279. {
  280. if (this.targetMaid != null)
  281. {
  282. this.targetMaid.transform.localScale = scale;
  283. if (!this.m_InputFieldScale.isFocused)
  284. {
  285. this.m_InputFieldScale.text = scale.x.ToString("f3");
  286. }
  287. this.m_SliderScale.value = scale.x;
  288. }
  289. }
  290. public void ButtonEvent_GizmoEnableMove()
  291. {
  292. GizmoObject gizmoObject = this.m_GizmoObject;
  293. gizmoObject.activeAxis = true;
  294. gizmoObject.activeRot = false;
  295. }
  296. public void ButtonEvent_GizmoEnableRot()
  297. {
  298. GizmoObject gizmoObject = this.m_GizmoObject;
  299. gizmoObject.activeAxis = false;
  300. gizmoObject.activeRot = true;
  301. }
  302. public void ButtonEvent_GizmoDisable()
  303. {
  304. GizmoObject gizmoObject = this.m_GizmoObject;
  305. gizmoObject.activeAxis = false;
  306. gizmoObject.activeRot = false;
  307. }
  308. public void ButtonEvent_CopyPosition()
  309. {
  310. Vector3 position = this.m_GizmoObject.position;
  311. string text = string.Format("{0},{1},{2}", position.x, position.y, position.z);
  312. this.m_CachedTransformDataDic["position"] = text.ToString();
  313. }
  314. public void ButtonEvent_PastePosition()
  315. {
  316. string text = this.m_CachedTransformDataDic["position"];
  317. if (string.IsNullOrEmpty(text))
  318. {
  319. Debug.Log("座標データはまだない");
  320. return;
  321. }
  322. string[] array = text.Split(new char[]
  323. {
  324. ','
  325. });
  326. if (array.Length != 3)
  327. {
  328. Debug.LogError("position の文字数が" + array.Length + "でした");
  329. return;
  330. }
  331. this.m_GizmoObject.position = new Vector3(float.Parse(array[0]), float.Parse(array[1]), float.Parse(array[2]));
  332. }
  333. public void ButtonEvent_ResetPosition()
  334. {
  335. this.m_GizmoObject.position = Vector3.zero;
  336. }
  337. public void ButtonEvent_CopyRotation()
  338. {
  339. Quaternion rotation = this.m_GizmoObject.rotation;
  340. string text = string.Format("{0},{1},{2},{3}", new object[]
  341. {
  342. rotation.x,
  343. rotation.y,
  344. rotation.z,
  345. rotation.w
  346. });
  347. this.m_CachedTransformDataDic["rotation"] = text.ToString();
  348. }
  349. public void ButtonEvent_PasteRotation()
  350. {
  351. string text = this.m_CachedTransformDataDic["rotation"];
  352. if (string.IsNullOrEmpty(text))
  353. {
  354. Debug.Log("回転データはまだない");
  355. return;
  356. }
  357. string[] array = text.Split(new char[]
  358. {
  359. ','
  360. });
  361. if (array.Length != 4)
  362. {
  363. Debug.LogError("rotation の文字数が" + array.Length + "でした");
  364. return;
  365. }
  366. this.m_GizmoObject.rotation = new Quaternion(float.Parse(array[0]), float.Parse(array[1]), float.Parse(array[2]), float.Parse(array[3]));
  367. }
  368. public void ButtonEvent_ResetRotation()
  369. {
  370. this.m_GizmoObject.rotation = Quaternion.identity;
  371. }
  372. public void ButtonEvent_CopyScale()
  373. {
  374. Vector3 scale = this.m_GizmoObject.scale;
  375. string text = string.Format("{0},{1},{2}", scale.x, scale.y, scale.z);
  376. this.m_CachedTransformDataDic["scale"] = text.ToString();
  377. }
  378. public void ButtonEvent_PasteScale()
  379. {
  380. string text = this.m_CachedTransformDataDic["scale"];
  381. if (string.IsNullOrEmpty(text))
  382. {
  383. Debug.Log("スケールデータはまだない");
  384. return;
  385. }
  386. string[] array = text.Split(new char[]
  387. {
  388. ','
  389. });
  390. if (array.Length != 3)
  391. {
  392. Debug.LogError("scale の文字数が" + array.Length + "でした");
  393. return;
  394. }
  395. this.m_GizmoObject.scale = new Vector3(float.Parse(array[0]), float.Parse(array[1]), float.Parse(array[2]));
  396. }
  397. public void ButtonEvent_ResetScale()
  398. {
  399. this.m_GizmoObject.scale = Vector3.one;
  400. }
  401. public void ButtonEvent_CameraFocus()
  402. {
  403. Maid targetMaid = this.targetMaid;
  404. if (!targetMaid)
  405. {
  406. return;
  407. }
  408. if (!targetMaid.Visible)
  409. {
  410. return;
  411. }
  412. Transform bone = targetMaid.body0.GetBone("Bip01 Head");
  413. WfCameraMoveSupport wfCameraMoveSupport = base.GetComponent<WfCameraMoveSupport>();
  414. if (wfCameraMoveSupport == null)
  415. {
  416. wfCameraMoveSupport = base.gameObject.AddComponent<WfCameraMoveSupport>();
  417. }
  418. Vector3 position = bone.position;
  419. float distance = Mathf.Sqrt(5f) * 2f;
  420. Vector2 aroundAngle = new Vector2(-135f, 45f);
  421. wfCameraMoveSupport.StartCameraPosition(position, distance, aroundAngle);
  422. }
  423. public void ButtonEvent_VisibleMaid(bool isVisible)
  424. {
  425. if (this.m_CharaMgr.IsBusy())
  426. {
  427. return;
  428. }
  429. if (this.targetMaid == null)
  430. {
  431. return;
  432. }
  433. if (this.targetMaid.ActiveSlotNo == -1)
  434. {
  435. this.m_CharaMgr.SetActiveMaid(this.targetMaid, 0);
  436. this.targetMaid.AllProcPropSeqStart();
  437. }
  438. this.targetMaid.Visible = isVisible;
  439. if (isVisible && this.targetMaid.IsBusy)
  440. {
  441. uGUIUtility.SetActiveEventSystem(false);
  442. GameMain.Instance.MainCamera.FadeOut(0f, false, null, true, default(Color));
  443. base.StartCoroutine(this.CorMaidLoad(this.targetMaid, new Action(this.OnMaidLoadEnd)));
  444. }
  445. }
  446. public void ButtonEvent_ToggleSnap(bool isEnable)
  447. {
  448. if (this.m_GizmoObject)
  449. {
  450. if (isEnable)
  451. {
  452. this.m_GizmoObject.controlType = GizmoObject.ControlType.Snap;
  453. }
  454. else
  455. {
  456. this.m_GizmoObject.controlType = GizmoObject.ControlType.Default;
  457. }
  458. }
  459. }
  460. private IEnumerator CorMaidLoad(Maid targetMaid, Action actLoadEnd)
  461. {
  462. targetMaid.Visible = true;
  463. while (targetMaid.IsBusy)
  464. {
  465. yield return null;
  466. }
  467. actLoadEnd();
  468. yield break;
  469. }
  470. private void OnMaidLoadEnd()
  471. {
  472. GameMain.Instance.MainCamera.FadeIn(0.3f, false, null, true, true, default(Color));
  473. this.targetMaid.CrossFade("maid_stand01.anm", false, true, false, 0.5f, 1f);
  474. this.targetMaid.FaceAnime("通常", 0f, 0);
  475. this.targetMaid.EyeToCamera(Maid.EyeMoveType.目と顔を向ける, 0f);
  476. uGUIUtility.SetActiveEventSystem(true);
  477. }
  478. private void OnDisable()
  479. {
  480. if (this.m_GizmoObject)
  481. {
  482. this.m_GizmoObject.gameObject.SetActive(false);
  483. }
  484. }
  485. private void OnEnable()
  486. {
  487. if (this.m_GizmoObject && this.targetMaid != null && this.targetMaid.Visible)
  488. {
  489. this.m_GizmoObject.gameObject.SetActive(true);
  490. }
  491. }
  492. private void OnDestroy()
  493. {
  494. if (this.m_GizmoObject)
  495. {
  496. UnityEngine.Object.Destroy(this.m_GizmoObject);
  497. }
  498. if (this.targetMaid)
  499. {
  500. this.targetMaid.transform.position = Vector3.zero;
  501. this.targetMaid.transform.rotation = Quaternion.identity;
  502. this.targetMaid.transform.localScale = Vector3.one;
  503. this.targetMaid.ResetAll();
  504. this.targetMaid.Visible = false;
  505. }
  506. }
  507. [Header("座標入力欄")]
  508. [SerializeField]
  509. private InputField m_InputFieldPosX;
  510. [SerializeField]
  511. private InputField m_InputFieldPosY;
  512. [SerializeField]
  513. private InputField m_InputFieldPosZ;
  514. [Header("回転入力欄")]
  515. [SerializeField]
  516. private InputField m_InputFieldRotX;
  517. [SerializeField]
  518. private InputField m_InputFieldRotY;
  519. [SerializeField]
  520. private InputField m_InputFieldRotZ;
  521. [Header("スケール入力欄")]
  522. [SerializeField]
  523. private InputField m_InputFieldScale;
  524. [SerializeField]
  525. private Slider m_SliderScale;
  526. private CharacterMgr m_CharaMgr;
  527. private GizmoObject m_GizmoObject;
  528. private Maid m_TargetMaid;
  529. private StringDictionary m_CachedTransformDataDic;
  530. }