GravityControlWindow.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using wf;
  5. public class GravityControlWindow : BaseMaidPhotoWindow
  6. {
  7. public override void Awake()
  8. {
  9. base.Awake();
  10. this.selectGravityData = null;
  11. this.editSubWindow = this.subWindows[0];
  12. this.noCharaActive = base.GetComponentInChildren<PhotoNoCharaActive>();
  13. foreach (GravityControlWindow.GravityData gravityData in this.gravityDatas)
  14. {
  15. NDebug.Assert(!string.IsNullOrEmpty(gravityData.categoryName), "GravityControlWindow 初期化エラーcategoryNameが不正です");
  16. NDebug.Assert(0 < gravityData.slotIds.Length, "GravityControlWindow 初期化エラーslotIdsが不正です");
  17. EventDelegate.Add(gravityData.button.onClick, delegate()
  18. {
  19. for (int j = 0; j < this.gravityDatas.Length; j++)
  20. {
  21. if (this.gravityDatas[j].button == UIButton.current)
  22. {
  23. if (this.gravityDatas[j] == this.selectGravityData)
  24. {
  25. this.CloseEditSubWindow();
  26. }
  27. else
  28. {
  29. this.OnSelectCategoryButton(this.gravityDatas[j]);
  30. }
  31. break;
  32. }
  33. }
  34. });
  35. }
  36. this.checkBoxEnabledGravityControl.onClick.Add(delegate(WFCheckBox check_box)
  37. {
  38. if (base.mgr.select_maid == null || base.mgr.select_maid.boMAN || this.selectGravityData == null)
  39. {
  40. return;
  41. }
  42. GravityTransformControl gravityTransformControl = this.GetGravityTransformControl(base.mgr.select_maid, this.selectGravityData.categoryName);
  43. if (gravityTransformControl == null)
  44. {
  45. return;
  46. }
  47. gravityTransformControl.isEnabled = check_box.check;
  48. });
  49. this.UpdateChildren();
  50. }
  51. public override void Start()
  52. {
  53. base.Start();
  54. this.noCharaActive.ChangeMode(true, true);
  55. this.editSubWindow.SetButtonEnabled(BasePhotoSubWindow.BtnType.End, true, false);
  56. this.editSubWindow.GetButtonOnClickEventList(BasePhotoSubWindow.BtnType.End).Add(new Action(this.CloseEditSubWindow));
  57. this.editSubWindow.visible = false;
  58. }
  59. public override void OnMaidAddEvent(Maid maid, bool is_deserialize_load)
  60. {
  61. if (maid == null || maid.boMAN)
  62. {
  63. return;
  64. }
  65. Dictionary<string, GravityTransformControl> dictionary = new Dictionary<string, GravityTransformControl>();
  66. foreach (GravityControlWindow.GravityData gravityData in this.gravityDatas)
  67. {
  68. string text = "GravityDatas_" + maid.status.guid + "_" + gravityData.categoryName;
  69. Transform bone = maid.body0.GetBone("Bip01");
  70. Transform transform = bone.Find(text);
  71. if (transform == null)
  72. {
  73. GameObject gameObject = new GameObject();
  74. gameObject.name = text;
  75. gameObject.transform.SetParent(bone, false);
  76. gameObject.transform.SetParent(maid.transform, true);
  77. gameObject.transform.localScale = Vector3.one;
  78. gameObject.transform.rotation = Quaternion.identity;
  79. GameObject gameObject2 = new GameObject();
  80. gameObject2.transform.SetParent(gameObject.transform, false);
  81. gameObject2.name = text;
  82. transform = gameObject2.transform;
  83. }
  84. else
  85. {
  86. transform = transform.transform.GetChild(0);
  87. }
  88. GravityTransformControl gravityTransformControl = transform.gameObject.AddComponent<GravityTransformControl>();
  89. gravityTransformControl.transTargetObject = new PhotoTransTargetObject(transform.gameObject, text, PhotoTransTargetObject.Type.Prefab, Vector2.one);
  90. gravityTransformControl.SetTargetSlods(gravityData.slotIds);
  91. gravityTransformControl.forceRate = gravityData.forceRate;
  92. dictionary.Add(gravityData.categoryName, gravityTransformControl);
  93. Dictionary<string, string> maidStoreData = base.GetMaidStoreData(maid);
  94. string categoryName = gravityData.categoryName;
  95. if (gravityTransformControl.isValid)
  96. {
  97. if (maidStoreData.ContainsKey(categoryName))
  98. {
  99. gravityTransformControl.isEnabled = bool.Parse(maidStoreData[categoryName]);
  100. gravityTransformControl.transform.localPosition = Parse.Vector3(maidStoreData[categoryName + "pos"]);
  101. }
  102. }
  103. else if (maidStoreData != null && maidStoreData.ContainsKey(categoryName))
  104. {
  105. maidStoreData.Remove(categoryName);
  106. maidStoreData.Remove(categoryName + "pos");
  107. }
  108. }
  109. this.activeMaidControllerList.Add(maid.status.guid, dictionary);
  110. this.noCharaActive.ChangeMode(false, true);
  111. }
  112. public override void OnMaidRemoveEvent(Maid maid)
  113. {
  114. if (maid == null || maid.boMAN)
  115. {
  116. return;
  117. }
  118. foreach (GravityControlWindow.GravityData gravityData in this.gravityDatas)
  119. {
  120. GravityTransformControl gravityTransformControl = this.GetGravityTransformControl(maid, gravityData.categoryName);
  121. GameObject gameObject = gravityTransformControl.transform.parent.gameObject;
  122. if (gravityTransformControl.transTargetObject != null)
  123. {
  124. gravityTransformControl.transTargetObject.Delete();
  125. }
  126. UnityEngine.Object.DestroyImmediate(gameObject);
  127. }
  128. if (this.activeMaidControllerList.ContainsKey(maid.status.guid))
  129. {
  130. this.activeMaidControllerList.Remove(maid.status.guid);
  131. }
  132. if (this.activeMaidControllerList.Count <= 0)
  133. {
  134. this.noCharaActive.ChangeMode(true, true);
  135. }
  136. }
  137. public override void OnMaidChangeEvent(Maid maid)
  138. {
  139. base.OnMaidChangeEvent(maid);
  140. foreach (GravityControlWindow.GravityData gravityData in this.gravityDatas)
  141. {
  142. GravityTransformControl gravityTransformControl = (!(maid == null) && !maid.boMAN) ? this.GetGravityTransformControl(maid, gravityData.categoryName) : null;
  143. bool flag = !(gravityTransformControl == null) && gravityTransformControl.isValid;
  144. if (!flag)
  145. {
  146. gravityData.button.SetSelect(false);
  147. }
  148. gravityData.button.isEnabled = flag;
  149. }
  150. if (this.selectGravityData != null)
  151. {
  152. this.OnSelectCategoryButton(this.selectGravityData);
  153. }
  154. }
  155. public void OnChangeMekure()
  156. {
  157. if (base.mgr.select_maid == null || base.mgr.select_maid.boMAN)
  158. {
  159. return;
  160. }
  161. foreach (GravityControlWindow.GravityData gravityData in this.gravityDatas)
  162. {
  163. GravityTransformControl gravityTransformControl = this.GetGravityTransformControl(base.mgr.select_maid, gravityData.categoryName);
  164. if (!(gravityTransformControl == null))
  165. {
  166. gravityTransformControl.OnChangeMekure();
  167. }
  168. }
  169. }
  170. public override void OnSerializeEvent()
  171. {
  172. List<string> maidStoreGuidList = base.mgr.GetMaidStoreGuidList();
  173. foreach (string text in maidStoreGuidList)
  174. {
  175. Dictionary<string, string> maidStoreData = base.GetMaidStoreData(text);
  176. if (maidStoreData != null)
  177. {
  178. foreach (GravityControlWindow.GravityData gravityData in this.gravityDatas)
  179. {
  180. string categoryName = gravityData.categoryName;
  181. GravityTransformControl gravityTransformControl = this.GetGravityTransformControl(text, gravityData.categoryName);
  182. if (!(gravityTransformControl == null))
  183. {
  184. if (gravityTransformControl.isValid)
  185. {
  186. maidStoreData[categoryName] = gravityTransformControl.isEnabled.ToString();
  187. maidStoreData[categoryName + "pos"] = gravityTransformControl.transform.localPosition.ToString("G9");
  188. }
  189. else
  190. {
  191. maidStoreData[categoryName] = false.ToString();
  192. maidStoreData[categoryName + "pos"] = Vector3.zero.ToString("G9");
  193. }
  194. }
  195. }
  196. }
  197. }
  198. }
  199. public override void OnDeserializeEvent()
  200. {
  201. }
  202. private void OnSelectCategoryButton(GravityControlWindow.GravityData selectedData)
  203. {
  204. this.CloseEditSubWindow();
  205. if (base.mgr.select_maid == null || base.mgr.select_maid.boMAN || selectedData == null || !selectedData.button.isEnabled)
  206. {
  207. return;
  208. }
  209. GravityTransformControl gravityTransformControl = this.GetGravityTransformControl(base.mgr.select_maid, selectedData.categoryName);
  210. if (gravityTransformControl == null)
  211. {
  212. return;
  213. }
  214. this.transInput.SetTarget(gravityTransformControl.transform, Vector3.zero);
  215. this.checkBoxEnabledGravityControl.check = gravityTransformControl.isEnabled;
  216. gravityTransformControl.visibleTransTargetObject = true;
  217. this.editSubWindow.visible = true;
  218. selectedData.isSelectedButton = true;
  219. this.selectGravityData = selectedData;
  220. }
  221. private void CloseEditSubWindow()
  222. {
  223. if (this.selectGravityData != null)
  224. {
  225. this.selectGravityData.isSelectedButton = false;
  226. this.selectGravityData.button.SetSelect(false);
  227. this.editSubWindow.visible = false;
  228. }
  229. foreach (KeyValuePair<string, Dictionary<string, GravityTransformControl>> keyValuePair in this.activeMaidControllerList)
  230. {
  231. foreach (KeyValuePair<string, GravityTransformControl> keyValuePair2 in keyValuePair.Value)
  232. {
  233. keyValuePair2.Value.visibleTransTargetObject = false;
  234. }
  235. }
  236. this.selectGravityData = null;
  237. }
  238. private GravityTransformControl GetGravityTransformControl(Maid maid, string gravityCategoryName)
  239. {
  240. if (maid == null)
  241. {
  242. return null;
  243. }
  244. return this.GetGravityTransformControl(maid.status.guid, gravityCategoryName);
  245. }
  246. private GravityTransformControl GetGravityTransformControl(string maidGuid, string gravityCategoryName)
  247. {
  248. GravityTransformControl result = null;
  249. if (this.activeMaidControllerList.ContainsKey(maidGuid))
  250. {
  251. result = ((!this.activeMaidControllerList[maidGuid].ContainsKey(gravityCategoryName)) ? null : this.activeMaidControllerList[maidGuid][gravityCategoryName]);
  252. }
  253. return result;
  254. }
  255. [SerializeField]
  256. private GravityControlWindow.GravityData[] gravityDatas;
  257. [SerializeField]
  258. private WFCheckBox checkBoxEnabledGravityControl;
  259. [SerializeField]
  260. private PhotTransInput transInput;
  261. private GravityControlWindow.GravityData selectGravityData;
  262. private BasePhotoSubWindow editSubWindow;
  263. private PhotoNoCharaActive noCharaActive;
  264. private Dictionary<string, Dictionary<string, GravityTransformControl>> activeMaidControllerList = new Dictionary<string, Dictionary<string, GravityTransformControl>>();
  265. [Serializable]
  266. private class GravityData
  267. {
  268. public TBody.SlotID[] slotIds
  269. {
  270. get
  271. {
  272. if (this.slotIds_ == null && this.slotIdNames != null)
  273. {
  274. this.slotIds_ = new TBody.SlotID[this.slotIdNames.Length];
  275. for (int i = 0; i < this.slotIdNames.Length; i++)
  276. {
  277. this.slotIds_[i] = (TBody.SlotID)Enum.Parse(typeof(TBody.SlotID), this.slotIdNames[i]);
  278. }
  279. }
  280. return this.slotIds_;
  281. }
  282. }
  283. public bool isSelectedButton
  284. {
  285. get
  286. {
  287. return this.button.isSelected;
  288. }
  289. set
  290. {
  291. if (value)
  292. {
  293. BoxCollider component = this.button.GetComponent<BoxCollider>();
  294. Vector3 size = component.size;
  295. this.button.SetSelect(true);
  296. component.size = size;
  297. }
  298. else
  299. {
  300. this.button.SetSelect(false);
  301. }
  302. }
  303. }
  304. [SerializeField]
  305. public string categoryName;
  306. [SerializeField]
  307. public float forceRate;
  308. [SerializeField]
  309. public UIWFTabButton button;
  310. [SerializeField]
  311. private string[] slotIdNames;
  312. private TBody.SlotID[] slotIds_;
  313. }
  314. }