CustomPartsWindow.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace SceneEditWindow
  5. {
  6. [AddComponentMenu("SceneEditWindow/CustomPartsWindow")]
  7. public class CustomPartsWindow : BasePhotoWindow
  8. {
  9. public override string windowName
  10. {
  11. get
  12. {
  13. return "CustomPartsWindow";
  14. }
  15. }
  16. public override void Start()
  17. {
  18. base.Start();
  19. this.subWindowVisibleCheckBox.check = false;
  20. this.subWindowVisibleCheckBox.onClick.Add(new Action<WFCheckBox>(this.OnClickOpenSubWindow));
  21. this.checkBoxCustomEnabled.onClick.Add(new Action<WFCheckBox>(this.OnClickCustomEnabled));
  22. this.subWindowVisibleCheckBox.visible = false;
  23. this.enabledMpns = new HashSet<MPN>();
  24. foreach (string value in this.customEnabledMpnNames)
  25. {
  26. MPN item = MPN.null_mpn;
  27. try
  28. {
  29. item = (MPN)Enum.Parse(typeof(MPN), value);
  30. }
  31. catch (Exception e)
  32. {
  33. NDebug.AssertParseError("MPN", e);
  34. }
  35. this.enabledMpns.Add(item);
  36. }
  37. this.partsIndexTabPanel.UpdateChildren();
  38. foreach (UIWFTabButton uiwftabButton in this.partsIndexTabPanel.button_list)
  39. {
  40. EventDelegate.Add(uiwftabButton.onSelect, new EventDelegate.Callback(this.OnSelectIndexButton));
  41. }
  42. this.visibleTabPanel.UpdateChildren();
  43. foreach (UIWFTabButton uiwftabButton2 in this.visibleTabPanel.button_list)
  44. {
  45. EventDelegate.Add(uiwftabButton2.onSelect, new EventDelegate.Callback(this.OnSelectVisibleButton));
  46. }
  47. this.visibleTabPanel.Select(this.visibleTabPanel.button_list[0]);
  48. this.scaleSlider.onChangeValue.Clear();
  49. this.scaleSlider.onChangeValue.Add(new Action<float>(this.onChangeScaleSlider));
  50. this.UpdateChildren();
  51. }
  52. public void Initizalize(Maid maid)
  53. {
  54. if (maid == null || maid.body0 == null || maid.body0.m_Bones == null)
  55. {
  56. NDebug.Assert("メイドのボディ読み込みが終了していないのにInitizalizeが呼ばれています", false);
  57. return;
  58. }
  59. this.subWindowVisibleCheckBox.check = false;
  60. this.maid = maid;
  61. this.animation = maid.body0.m_Bones.GetComponent<Animation>();
  62. this.visible = false;
  63. }
  64. private void OnDestroy()
  65. {
  66. GameObject worldTransformAxisParent = PhotoWindowManager.GetWorldTransformAxisParent();
  67. if (worldTransformAxisParent != null)
  68. {
  69. UnityEngine.Object.DestroyImmediate(worldTransformAxisParent);
  70. }
  71. }
  72. public void DestroySelectCustomParts()
  73. {
  74. if (this.selectCustomParts == null)
  75. {
  76. return;
  77. }
  78. foreach (CustomParts customParts in this.selectCustomParts)
  79. {
  80. customParts.Destroy();
  81. }
  82. this.selectCustomParts = null;
  83. }
  84. public bool SetItem(SceneEdit.SMenuItem menuItem)
  85. {
  86. this.reseaveLoadMenuItem = null;
  87. if (menuItem == null || menuItem.m_boDelOnly || !this.enabledMpns.Contains(menuItem.m_mpn))
  88. {
  89. return false;
  90. }
  91. this.reseaveLoadMenuItem = menuItem;
  92. return true;
  93. }
  94. public void ResetPoint(MPN mpn)
  95. {
  96. List<KeyValuePair<TBody.SlotID, string>> attachPointListFromMPN = this.maid.body0.GetAttachPointListFromMPN(mpn);
  97. for (int i = 0; i < attachPointListFromMPN.Count; i++)
  98. {
  99. CustomParts customParts = new CustomParts(this.maid, attachPointListFromMPN[i].Key, attachPointListFromMPN[i].Value);
  100. customParts.enabled = false;
  101. }
  102. }
  103. public void ResetAllPoint()
  104. {
  105. foreach (MPN mpn in this.enabledMpns)
  106. {
  107. this.ResetPoint(mpn);
  108. }
  109. }
  110. public new void Update()
  111. {
  112. if (this.reseaveLoadMenuItem != null && !GameMain.Instance.CharacterMgr.IsBusy())
  113. {
  114. this.CreateItemData(this.reseaveLoadMenuItem);
  115. this.reseaveLoadMenuItem = null;
  116. }
  117. if (this.selectCustomParts == null || this.selectCustomParts.Length == 0 || !this.editMode)
  118. {
  119. return;
  120. }
  121. foreach (CustomParts customParts in this.selectCustomParts)
  122. {
  123. if (customParts.enabled)
  124. {
  125. Transform transform = customParts.indirectObject.transform;
  126. customParts.SetTransformData(transform, true);
  127. }
  128. }
  129. }
  130. public void UpdateUI()
  131. {
  132. if (this.selectCustomParts != null)
  133. {
  134. foreach (CustomParts customParts in this.selectCustomParts)
  135. {
  136. customParts.tranformAxis.Visible = false;
  137. customParts.gizmoRender.Visible = false;
  138. }
  139. }
  140. if (!this.editMode)
  141. {
  142. return;
  143. }
  144. CustomParts customParts2 = this.selectCustomParts[this.selectCustomPartsIndex];
  145. this.checkBoxCustomEnabled.check = customParts2.enabled;
  146. Vector3 position;
  147. Quaternion rotation;
  148. Vector3 localScale;
  149. customParts2.GetTransformData(out position, out rotation, out localScale, true);
  150. customParts2.indirectObject.transform.position = position;
  151. customParts2.indirectObject.transform.rotation = rotation;
  152. customParts2.indirectObject.transform.localScale = localScale;
  153. customParts2.tranformAxis.Visible = (customParts2.enabled && this.axisVisibleButton.isSelected);
  154. customParts2.gizmoRender.Visible = (customParts2.enabled && this.rotateVisibleButton.isSelected);
  155. this.scaleSlider.value = customParts2.scale.x;
  156. this.editToolObject.SetActive(customParts2.enabled);
  157. }
  158. public void ViewMode(bool enabled)
  159. {
  160. if (this.selectCustomParts == null || this.selectCustomParts.Length == 0 || !this.editMode)
  161. {
  162. return;
  163. }
  164. if (this.selectCustomParts != null)
  165. {
  166. foreach (CustomParts customParts in this.selectCustomParts)
  167. {
  168. customParts.tranformAxis.Visible = false;
  169. customParts.gizmoRender.Visible = false;
  170. }
  171. }
  172. if (enabled)
  173. {
  174. return;
  175. }
  176. this.UpdateUI();
  177. }
  178. public void OnExecItemPrev(SceneEdit.SMenuItem menuItem)
  179. {
  180. this.isBackupDatas = null;
  181. if (this.reseaveLoadMenuItem != null && !GameMain.Instance.CharacterMgr.IsBusy())
  182. {
  183. this.CreateItemData(this.reseaveLoadMenuItem);
  184. this.reseaveLoadMenuItem = null;
  185. }
  186. this.DestroySelectCustomParts();
  187. if (menuItem.m_mpn == MPN.hairf || menuItem.m_mpn == MPN.hairt)
  188. {
  189. MPN f_mpn = (menuItem.m_mpn != MPN.hairf) ? MPN.acckamisub : MPN.acckami;
  190. List<KeyValuePair<TBody.SlotID, string>> attachPointListFromMPN = this.maid.body0.GetAttachPointListFromMPN(f_mpn);
  191. for (int i = 0; i < attachPointListFromMPN.Count; i++)
  192. {
  193. new BaseCustomParts(this.maid, attachPointListFromMPN[i].Key, attachPointListFromMPN[i].Value)
  194. {
  195. enabled = false
  196. }.Reset();
  197. }
  198. this.visible = false;
  199. }
  200. else if (this.enabledMpns.Contains(menuItem.m_mpn))
  201. {
  202. MaidProp prop = this.maid.GetProp(menuItem.m_mpn);
  203. int nFileNameRID = prop.nFileNameRID;
  204. bool flag = menuItem.m_nMenuFileRID == nFileNameRID;
  205. if (menuItem.m_nMenuFileRID != nFileNameRID && !menuItem.m_boDelOnly)
  206. {
  207. List<SceneEdit.SMenuItem> list = null;
  208. if (menuItem.m_bGroupLeader)
  209. {
  210. list = menuItem.m_listMember;
  211. }
  212. else if (menuItem.m_leaderMenu != null)
  213. {
  214. list = menuItem.m_leaderMenu.m_listMember;
  215. }
  216. if (list != null)
  217. {
  218. foreach (SceneEdit.SMenuItem smenuItem in list)
  219. {
  220. if (smenuItem.m_nMenuFileRID == nFileNameRID)
  221. {
  222. flag = true;
  223. break;
  224. }
  225. }
  226. }
  227. }
  228. List<CustomParts> list2 = new List<CustomParts>();
  229. List<KeyValuePair<TBody.SlotID, string>> attachPointListFromMPN2 = this.maid.body0.GetAttachPointListFromMPN(menuItem.m_mpn);
  230. for (int j = 0; j < attachPointListFromMPN2.Count; j++)
  231. {
  232. list2.Add(new CustomParts(this.maid, attachPointListFromMPN2[j].Key, attachPointListFromMPN2[j].Value));
  233. }
  234. if (flag)
  235. {
  236. this.isBackupDatas = new bool[list2.Count];
  237. for (int k = 0; k < list2.Count; k++)
  238. {
  239. CustomParts customParts = list2[k];
  240. this.isBackupDatas[k] = customParts.enabled;
  241. if (customParts.enabled)
  242. {
  243. customParts.SaveBackup();
  244. }
  245. }
  246. }
  247. foreach (CustomParts customParts2 in list2)
  248. {
  249. customParts2.Reset();
  250. customParts2.enabled = false;
  251. }
  252. }
  253. else
  254. {
  255. this.visible = false;
  256. }
  257. }
  258. public void CreateItemData(SceneEdit.SMenuItem menu)
  259. {
  260. this.DestroySelectCustomParts();
  261. this.selectCustomPartsIndex = 0;
  262. List<KeyValuePair<TBody.SlotID, string>> attachPointListFromMPN = this.maid.body0.GetAttachPointListFromMPN(menu.m_mpn);
  263. if (attachPointListFromMPN.Count != 0)
  264. {
  265. this.selectCustomParts = new CustomParts[attachPointListFromMPN.Count];
  266. }
  267. for (int i = 0; i < attachPointListFromMPN.Count; i++)
  268. {
  269. CustomParts customParts = new CustomParts(this.maid, attachPointListFromMPN[i].Key, attachPointListFromMPN[i].Value);
  270. customParts.indirectObject = GameObject.Find(menu.m_nMenuFileRID.ToString() + "_" + i.ToString());
  271. if (customParts.indirectObject == null)
  272. {
  273. customParts.indirectObject = new GameObject();
  274. customParts.indirectObject.name = menu.m_nMenuFileRID.ToString();
  275. }
  276. if (this.isBackupDatas != null && this.isBackupDatas.Length == attachPointListFromMPN.Count && this.isBackupDatas[i])
  277. {
  278. customParts.enabled = true;
  279. customParts.LoadBackup();
  280. }
  281. Vector3 position;
  282. Quaternion rotation;
  283. Vector3 localScale;
  284. customParts.GetTransformData(out position, out rotation, out localScale, true);
  285. customParts.indirectObject.transform.position = position;
  286. customParts.indirectObject.transform.rotation = rotation;
  287. customParts.indirectObject.transform.localScale = localScale;
  288. customParts.menuItem = menu;
  289. customParts.tranformAxis = PhotoWindowManager.CreateWorldTransformAxis(customParts.indirectObject, false, true);
  290. customParts.tranformAxis.Visible = false;
  291. customParts.tranformAxis.ScaleMinMax = new Vector2(this.scaleSlider.MinNum, this.scaleSlider.MaxNum);
  292. customParts.gizmoRender = PhotoWindowManager.CreateWorldTransformRotate(customParts.indirectObject, false);
  293. customParts.gizmoRender.offsetScale = 0.4f;
  294. customParts.gizmoRender.Visible = false;
  295. this.checkBoxCustomEnabled.check = customParts.enabled;
  296. this.selectCustomParts[i] = customParts;
  297. }
  298. this.isBackupDatas = null;
  299. }
  300. public void OnSelectIndexButton()
  301. {
  302. if (!UIWFSelectButton.current.isSelected)
  303. {
  304. return;
  305. }
  306. this.selectCustomPartsIndex = 0;
  307. UILabel componentInChildren = UIWFSelectButton.current.transform.parent.GetComponentInChildren<UILabel>(true);
  308. if (componentInChildren == null)
  309. {
  310. this.selectCustomPartsIndex = 0;
  311. }
  312. else
  313. {
  314. this.selectCustomPartsIndex = int.Parse(componentInChildren.text) - 1;
  315. }
  316. this.UpdateUI();
  317. }
  318. public void OnSelectVisibleButton()
  319. {
  320. this.UpdateUI();
  321. }
  322. public void onChangeScaleSlider(float value)
  323. {
  324. if (!this.editMode || this.selectCustomParts == null || this.selectCustomParts.Length == 0)
  325. {
  326. return;
  327. }
  328. CustomParts customParts = this.selectCustomParts[this.selectCustomPartsIndex];
  329. customParts.indirectObject.transform.localScale = new Vector3(value, value, value);
  330. }
  331. protected void OnClickOpenSubWindow(WFCheckBox checkBox)
  332. {
  333. if (GameMain.Instance.CharacterMgr.IsBusy() || this.selectCustomParts == null || this.selectCustomParts.Length <= 0)
  334. {
  335. this.editMode = false;
  336. return;
  337. }
  338. this.editMode = checkBox.check;
  339. this.partsIndexTabPanel.Select(this.partsIndexTabPanel.button_list[this.selectCustomPartsIndex]);
  340. for (int i = 0; i < this.partsIndexTabPanel.transform.childCount; i++)
  341. {
  342. this.partsIndexTabPanel.transform.GetChild(i).gameObject.SetActive(i < this.selectCustomParts.Length);
  343. }
  344. this.OnClickCustomEnabled(this.checkBoxCustomEnabled);
  345. }
  346. protected void OnClickCustomEnabled(WFCheckBox checkBox)
  347. {
  348. if (!this.editMode)
  349. {
  350. return;
  351. }
  352. CustomParts customParts = this.selectCustomParts[this.selectCustomPartsIndex];
  353. customParts.enabled = checkBox.check;
  354. this.UpdateUI();
  355. }
  356. public bool playMaidAnimation
  357. {
  358. get
  359. {
  360. return !(this.animation == null) && !this.maid.GetLockHeadAndEye();
  361. }
  362. set
  363. {
  364. if (this.playMaidAnimation == value || this.animation == null)
  365. {
  366. return;
  367. }
  368. AnimationState animationState = this.animation[this.maid.body0.LastAnimeFN.ToLower()];
  369. if (animationState == null)
  370. {
  371. Debug.LogError(this.maid.body0.LastAnimeFN.ToLower() + "のAnimationStateが見つかりませんでした");
  372. return;
  373. }
  374. animationState.enabled = value;
  375. this.maid.LockHeadAndEye(!value);
  376. if (GameMain.Instance.VRMode)
  377. {
  378. if (GameMain.Instance.OvrMgr.ovr_obj.left_controller != null && GameMain.Instance.OvrMgr.ovr_obj.left_controller.grip_collider != null)
  379. {
  380. GameMain.Instance.OvrMgr.ovr_obj.left_controller.grip_collider.ResetGrip();
  381. }
  382. if (GameMain.Instance.OvrMgr.ovr_obj.right_controller != null && GameMain.Instance.OvrMgr.ovr_obj.right_controller.grip_collider != null)
  383. {
  384. GameMain.Instance.OvrMgr.ovr_obj.right_controller.grip_collider.ResetGrip();
  385. }
  386. MaidColliderCollect component = this.maid.GetComponent<MaidColliderCollect>();
  387. List<CapsuleCollider> collider = component.GetCollider(MaidColliderCollect.ColliderType.Grab);
  388. foreach (CapsuleCollider capsuleCollider in collider)
  389. {
  390. capsuleCollider.gameObject.SetActive(value);
  391. }
  392. }
  393. }
  394. }
  395. public override bool visible
  396. {
  397. get
  398. {
  399. return base.visible;
  400. }
  401. set
  402. {
  403. base.visible = value;
  404. this.subWindowVisibleCheckBox.check = value;
  405. this.OnClickOpenSubWindow(this.subWindowVisibleCheckBox);
  406. }
  407. }
  408. public bool editMode
  409. {
  410. get
  411. {
  412. return this.subWindowVisibleCheckBox.check;
  413. }
  414. set
  415. {
  416. if (this.selectCustomParts == null)
  417. {
  418. value = false;
  419. }
  420. this.subWindowVisibleCheckBox.check = value;
  421. this.playMaidAnimation = !value;
  422. if (this.selectCustomParts != null && this.selectCustomParts.Length != 0)
  423. {
  424. this.UpdateUI();
  425. }
  426. }
  427. }
  428. [SerializeField]
  429. private WFCheckBox subWindowVisibleCheckBox;
  430. [SerializeField]
  431. private WFCheckBox checkBoxCustomEnabled;
  432. [SerializeField]
  433. private GameObject editToolObject;
  434. [SerializeField]
  435. private UIWFTabPanel partsIndexTabPanel;
  436. [SerializeField]
  437. private UIWFTabPanel visibleTabPanel;
  438. [SerializeField]
  439. private UIWFTabButton axisVisibleButton;
  440. [SerializeField]
  441. private UIWFTabButton rotateVisibleButton;
  442. [SerializeField]
  443. private PhotoSliderAndInput scaleSlider;
  444. [SerializeField]
  445. private string[] customEnabledMpnNames;
  446. private Maid maid;
  447. private Animation animation;
  448. private SceneEdit.SMenuItem reseaveLoadMenuItem;
  449. private bool[] isBackupDatas;
  450. private CustomParts[] selectCustomParts;
  451. private int selectCustomPartsIndex;
  452. private HashSet<MPN> enabledMpns;
  453. }
  454. }