CreativeRoomUIPlacementMaid.cs 15 KB

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