CustomPartsWindow.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  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. if (Product.isPublic)
  266. {
  267. foreach (TBodySkin tbodySkin in this.maid.body0.goSlot.GetListParents())
  268. {
  269. if (tbodySkin.m_ParentMPN == menu.m_mpn)
  270. {
  271. tbodySkin.Update();
  272. }
  273. }
  274. attachPointListFromMPN = this.maid.body0.GetAttachPointListFromMPN(menu.m_mpn);
  275. this.selectCustomParts = new CustomParts[attachPointListFromMPN.Count];
  276. }
  277. this.selectCustomParts = new CustomParts[attachPointListFromMPN.Count];
  278. }
  279. for (int i = 0; i < attachPointListFromMPN.Count; i++)
  280. {
  281. CustomParts customParts = new CustomParts(this.maid, attachPointListFromMPN[i].Key, attachPointListFromMPN[i].Value);
  282. customParts.indirectObject = GameObject.Find(menu.m_nMenuFileRID.ToString() + "_" + i.ToString());
  283. if (customParts.indirectObject == null)
  284. {
  285. customParts.indirectObject = new GameObject();
  286. customParts.indirectObject.name = menu.m_nMenuFileRID.ToString();
  287. }
  288. if (this.isBackupDatas != null && this.isBackupDatas.Length == attachPointListFromMPN.Count && this.isBackupDatas[i])
  289. {
  290. customParts.enabled = true;
  291. customParts.LoadBackup();
  292. }
  293. Vector3 position;
  294. Quaternion rotation;
  295. Vector3 localScale;
  296. customParts.GetTransformData(out position, out rotation, out localScale, true);
  297. customParts.indirectObject.transform.position = position;
  298. customParts.indirectObject.transform.rotation = rotation;
  299. customParts.indirectObject.transform.localScale = localScale;
  300. customParts.menuItem = menu;
  301. customParts.tranformAxis = PhotoWindowManager.CreateWorldTransformAxis(customParts.indirectObject, false, true);
  302. customParts.tranformAxis.Visible = false;
  303. customParts.tranformAxis.ScaleMinMax = new Vector2(this.scaleSlider.MinNum, this.scaleSlider.MaxNum);
  304. customParts.gizmoRender = PhotoWindowManager.CreateWorldTransformRotate(customParts.indirectObject, false);
  305. customParts.gizmoRender.offsetScale = 0.4f;
  306. customParts.gizmoRender.Visible = false;
  307. this.checkBoxCustomEnabled.check = customParts.enabled;
  308. this.selectCustomParts[i] = customParts;
  309. }
  310. this.isBackupDatas = null;
  311. }
  312. public void OnSelectIndexButton()
  313. {
  314. if (!UIWFSelectButton.current.isSelected)
  315. {
  316. return;
  317. }
  318. this.selectCustomPartsIndex = 0;
  319. UILabel componentInChildren = UIWFSelectButton.current.transform.parent.GetComponentInChildren<UILabel>(true);
  320. if (componentInChildren == null)
  321. {
  322. this.selectCustomPartsIndex = 0;
  323. }
  324. else
  325. {
  326. this.selectCustomPartsIndex = int.Parse(componentInChildren.text) - 1;
  327. }
  328. this.UpdateUI();
  329. }
  330. public void OnSelectVisibleButton()
  331. {
  332. this.UpdateUI();
  333. }
  334. public void onChangeScaleSlider(float value)
  335. {
  336. if (!this.editMode || this.selectCustomParts == null || this.selectCustomParts.Length == 0)
  337. {
  338. return;
  339. }
  340. CustomParts customParts = this.selectCustomParts[this.selectCustomPartsIndex];
  341. customParts.indirectObject.transform.localScale = new Vector3(value, value, value);
  342. }
  343. protected void OnClickOpenSubWindow(WFCheckBox checkBox)
  344. {
  345. if (GameMain.Instance.CharacterMgr.IsBusy() || this.selectCustomParts == null || this.selectCustomParts.Length <= 0)
  346. {
  347. this.editMode = false;
  348. return;
  349. }
  350. this.editMode = checkBox.check;
  351. this.partsIndexTabPanel.Select(this.partsIndexTabPanel.button_list[this.selectCustomPartsIndex]);
  352. for (int i = 0; i < this.partsIndexTabPanel.transform.childCount; i++)
  353. {
  354. this.partsIndexTabPanel.transform.GetChild(i).gameObject.SetActive(i < this.selectCustomParts.Length);
  355. }
  356. this.OnClickCustomEnabled(this.checkBoxCustomEnabled);
  357. }
  358. protected void OnClickCustomEnabled(WFCheckBox checkBox)
  359. {
  360. if (!this.editMode)
  361. {
  362. return;
  363. }
  364. CustomParts customParts = this.selectCustomParts[this.selectCustomPartsIndex];
  365. customParts.enabled = checkBox.check;
  366. this.UpdateUI();
  367. }
  368. public bool playMaidAnimation
  369. {
  370. get
  371. {
  372. return !(this.animation == null) && !this.maid.GetLockHeadAndEye();
  373. }
  374. set
  375. {
  376. if (this.playMaidAnimation == value || this.animation == null)
  377. {
  378. return;
  379. }
  380. AnimationState animationState = this.animation[this.maid.body0.LastAnimeFN.ToLower()];
  381. if (animationState == null)
  382. {
  383. Debug.LogError(this.maid.body0.LastAnimeFN.ToLower() + "のAnimationStateが見つかりませんでした");
  384. return;
  385. }
  386. animationState.enabled = value;
  387. this.maid.LockHeadAndEye(!value);
  388. if (GameMain.Instance.VRMode)
  389. {
  390. if (GameMain.Instance.OvrMgr.ovr_obj.left_controller != null && GameMain.Instance.OvrMgr.ovr_obj.left_controller.grip_collider != null)
  391. {
  392. GameMain.Instance.OvrMgr.ovr_obj.left_controller.grip_collider.ResetGrip();
  393. }
  394. if (GameMain.Instance.OvrMgr.ovr_obj.right_controller != null && GameMain.Instance.OvrMgr.ovr_obj.right_controller.grip_collider != null)
  395. {
  396. GameMain.Instance.OvrMgr.ovr_obj.right_controller.grip_collider.ResetGrip();
  397. }
  398. MaidColliderCollect component = this.maid.GetComponent<MaidColliderCollect>();
  399. if (component != null)
  400. {
  401. List<CapsuleCollider> list = new List<CapsuleCollider>();
  402. if (this.maid.body0.IsCrcBody)
  403. {
  404. list = component.GetCollider(MaidColliderCollect.ColliderType.Crc);
  405. }
  406. else
  407. {
  408. list = component.GetCollider(MaidColliderCollect.ColliderType.Grab);
  409. }
  410. foreach (CapsuleCollider capsuleCollider in list)
  411. {
  412. capsuleCollider.gameObject.SetActive(value);
  413. }
  414. }
  415. }
  416. }
  417. }
  418. public override bool visible
  419. {
  420. get
  421. {
  422. return base.visible;
  423. }
  424. set
  425. {
  426. base.visible = value;
  427. this.subWindowVisibleCheckBox.check = value;
  428. this.OnClickOpenSubWindow(this.subWindowVisibleCheckBox);
  429. }
  430. }
  431. public bool editMode
  432. {
  433. get
  434. {
  435. return this.subWindowVisibleCheckBox.check;
  436. }
  437. set
  438. {
  439. if (this.selectCustomParts == null)
  440. {
  441. value = false;
  442. }
  443. this.subWindowVisibleCheckBox.check = value;
  444. this.playMaidAnimation = !value;
  445. if (this.selectCustomParts != null && this.selectCustomParts.Length != 0)
  446. {
  447. this.UpdateUI();
  448. }
  449. }
  450. }
  451. [SerializeField]
  452. private WFCheckBox subWindowVisibleCheckBox;
  453. [SerializeField]
  454. private WFCheckBox checkBoxCustomEnabled;
  455. [SerializeField]
  456. private GameObject editToolObject;
  457. [SerializeField]
  458. private UIWFTabPanel partsIndexTabPanel;
  459. [SerializeField]
  460. private UIWFTabPanel visibleTabPanel;
  461. [SerializeField]
  462. private UIWFTabButton axisVisibleButton;
  463. [SerializeField]
  464. private UIWFTabButton rotateVisibleButton;
  465. [SerializeField]
  466. private PhotoSliderAndInput scaleSlider;
  467. [SerializeField]
  468. private string[] customEnabledMpnNames;
  469. private Maid maid;
  470. private Animation animation;
  471. private SceneEdit.SMenuItem reseaveLoadMenuItem;
  472. private bool[] isBackupDatas;
  473. private CustomParts[] selectCustomParts;
  474. private int selectCustomPartsIndex;
  475. private HashSet<MPN> enabledMpns;
  476. }
  477. }