PhotoFaceDataShortcutSetter.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Kasizuki;
  5. using UnityEngine;
  6. public class PhotoFaceDataShortcutSetter : MonoBehaviour
  7. {
  8. public float fadeSpeed
  9. {
  10. get
  11. {
  12. return this.m_FadeSpeed;
  13. }
  14. set
  15. {
  16. this.m_FadeSpeed = Mathf.Clamp(value, 0.001f, 1f);
  17. }
  18. }
  19. private PhotoFaceDataShortcut targetControllerRight { get; set; }
  20. private PhotoFaceDataShortcut targetControllerLeft { get; set; }
  21. private PhotoFaceDataShortcut.ItemData nowSelectItem
  22. {
  23. get
  24. {
  25. return this.m_NowSelectItem;
  26. }
  27. set
  28. {
  29. this.m_NowSelectItem = value;
  30. }
  31. }
  32. public void Init(PhotoFaceDataShortcut rightHandUI, PhotoFaceDataShortcut LeftHandUI)
  33. {
  34. this.m_FadeWindowShortcutButtonsRight = this.m_ButtonListShortcutRight.GetComponent<NGUIWindow>();
  35. this.m_FadeWindowShortcutButtonsLeft = this.m_ButtonListShortcutLeft.GetComponent<NGUIWindow>();
  36. this.m_FadeWindowFaceDataList = this.m_WindowListFaceData.GetComponent<NGUIWindow>();
  37. this.targetControllerRight = rightHandUI;
  38. this.targetControllerLeft = LeftHandUI;
  39. PhotoFaceData.Create();
  40. List<PhotoFaceData> data2 = PhotoFaceData.data;
  41. ListViewerWindow windowListFaceData = this.m_WindowListFaceData;
  42. windowListFaceData.Show<PhotoFaceData, UIWFTabButton>(data2, delegate(int index, PhotoFaceData data, UIWFTabButton item)
  43. {
  44. UILabel componentInChildren = item.GetComponentInChildren<UILabel>();
  45. componentInChildren.text = data.name;
  46. EventDelegate.Add(item.onClick, delegate
  47. {
  48. this.OnClickData(data);
  49. });
  50. });
  51. UIWFTabPanel component = windowListFaceData.viewer.parentItemArea.GetComponent<UIWFTabPanel>();
  52. if (component)
  53. {
  54. component.UpdateChildren();
  55. }
  56. this.m_ButtonListShortcutRight.Show<Transform>(this.targetControllerRight.itemDataList.Count, delegate(int index, Transform trans)
  57. {
  58. PhotoFaceDataShortcut.ItemData data = this.targetControllerRight.itemDataList[index];
  59. UILabel componentInChildren = trans.GetComponentInChildren<UILabel>();
  60. UIButton componentInChildren2 = trans.GetComponentInChildren<UIButton>();
  61. componentInChildren.text = data.GetDataName();
  62. EventDelegate.Add(componentInChildren2.onClick, delegate
  63. {
  64. this.OnClickShortcutButton(data);
  65. });
  66. PhotoFaceDataShortcutSetter.ItemData itemData = trans.gameObject.AddComponent<PhotoFaceDataShortcutSetter.ItemData>();
  67. itemData.label = componentInChildren;
  68. this.m_ItemPairDic.Add(data, itemData);
  69. });
  70. this.m_ButtonListShortcutLeft.Show<Transform>(this.targetControllerLeft.itemDataList.Count, delegate(int index, Transform trans)
  71. {
  72. PhotoFaceDataShortcut.ItemData data = this.targetControllerLeft.itemDataList[index];
  73. UILabel componentInChildren = trans.GetComponentInChildren<UILabel>();
  74. UIButton componentInChildren2 = trans.GetComponentInChildren<UIButton>();
  75. componentInChildren.text = data.GetDataName();
  76. EventDelegate.Add(componentInChildren2.onClick, delegate
  77. {
  78. this.OnClickShortcutButton(data);
  79. });
  80. PhotoFaceDataShortcutSetter.ItemData itemData = trans.gameObject.AddComponent<PhotoFaceDataShortcutSetter.ItemData>();
  81. itemData.label = componentInChildren;
  82. this.m_ItemPairDic.Add(data, itemData);
  83. });
  84. Transform transform = this.m_ParentAddFaceOptions.transform.Find("Buttons");
  85. for (int i = 0; i < transform.childCount; i++)
  86. {
  87. WFCheckBox component2 = transform.GetChild(i).GetComponent<WFCheckBox>();
  88. component2.check = false;
  89. component2.enabled = true;
  90. this.m_AddFaceOptionDic.Add(component2.GetComponentInChildren<UILabel>().text, component2);
  91. component2.onClick.Add(new Action<WFCheckBox>(this.OnClickCheckBoxAddOption));
  92. }
  93. EventDelegate.Add(this.m_ButtonFaceListOK.onClick, new EventDelegate.Callback(this.OnClickFaceListOK));
  94. NGUIWindow fadeWindowFaceDataList = this.m_FadeWindowFaceDataList;
  95. fadeWindowFaceDataList.OnOpen = (Action)Delegate.Combine(fadeWindowFaceDataList.OnOpen, new Action(delegate
  96. {
  97. this.m_WindowListFaceData.Reposition();
  98. }));
  99. }
  100. private void OnClickData(PhotoFaceData data)
  101. {
  102. TMorph.AddBlendType blendType = this.ConvertBlendType();
  103. this.ApplyItemData(this.nowSelectItem, data, blendType);
  104. PhotoFaceDataShortcutSetter.ItemData itemData;
  105. if (this.m_ItemPairDic != null && this.m_ItemPairDic.TryGetValue(this.nowSelectItem, out itemData))
  106. {
  107. itemData.label.text = this.nowSelectItem.GetDataName();
  108. }
  109. if (this.nowSelectItem != null)
  110. {
  111. if (this.targetControllerRight.itemDataList.Contains(this.nowSelectItem))
  112. {
  113. this.targetControllerRight.Emulate(this.nowSelectItem);
  114. }
  115. else if (this.targetControllerLeft.itemDataList.Contains(this.nowSelectItem))
  116. {
  117. this.targetControllerLeft.Emulate(this.nowSelectItem);
  118. }
  119. else
  120. {
  121. Debug.LogWarning("コントローラに存在しない項目を更新しているかも");
  122. }
  123. }
  124. }
  125. private void OnClickShortcutButton(PhotoFaceDataShortcut.ItemData item)
  126. {
  127. this.nowSelectItem = item;
  128. this.m_FadeWindowShortcutButtonsRight.Close(this.fadeSpeed, null);
  129. this.m_FadeWindowShortcutButtonsLeft.Close(this.fadeSpeed, null);
  130. this.WaitTime(this.fadeSpeed, delegate
  131. {
  132. this.m_FadeWindowFaceDataList.Open(this.fadeSpeed, null);
  133. });
  134. UIWFTabPanel component = this.m_WindowListFaceData.viewer.parentItemArea.GetComponent<UIWFTabPanel>();
  135. UIWFTabButton selectButtonObject = component.GetSelectButtonObject();
  136. if (selectButtonObject != null)
  137. {
  138. selectButtonObject.SetSelect(false);
  139. }
  140. component.ResetSelect();
  141. component.UpdateChildren();
  142. this.UpdateCheckBoxAddOption(item);
  143. }
  144. private void OnClickFaceListOK()
  145. {
  146. this.m_FadeWindowFaceDataList.Close(this.fadeSpeed, null);
  147. this.WaitTime(this.fadeSpeed, delegate
  148. {
  149. this.m_FadeWindowShortcutButtonsRight.Open(this.fadeSpeed, null);
  150. this.m_FadeWindowShortcutButtonsLeft.Open(this.fadeSpeed, null);
  151. });
  152. ControllerShortcutSettingData.config.Write();
  153. }
  154. private void ApplyItemData(PhotoFaceDataShortcut.ItemData itemData, PhotoFaceData data, TMorph.AddBlendType blendType)
  155. {
  156. if (itemData == null)
  157. {
  158. Debug.Log("コントローラの項目の参照がありませんでした");
  159. return;
  160. }
  161. if (data == null)
  162. {
  163. Debug.Log("表情データがnullらしい");
  164. }
  165. itemData.data = data;
  166. itemData.blendType = blendType;
  167. itemData.isOpenMouth = this.IsOpenMouth();
  168. }
  169. private TMorph.AddBlendType ConvertBlendType()
  170. {
  171. TMorph.AddBlendType addBlendType = TMorph.AddBlendType.None;
  172. Dictionary<string, TMorph.AddBlendType> dictionary = new Dictionary<string, TMorph.AddBlendType>
  173. {
  174. {
  175. "頬染め1",
  176. TMorph.AddBlendType.Cheek1
  177. },
  178. {
  179. "頬染め2",
  180. TMorph.AddBlendType.Cheek2
  181. },
  182. {
  183. "頬染め3",
  184. TMorph.AddBlendType.Cheek3
  185. },
  186. {
  187. "涙1",
  188. TMorph.AddBlendType.Tear1
  189. },
  190. {
  191. "涙2",
  192. TMorph.AddBlendType.Tear2
  193. },
  194. {
  195. "涙3",
  196. TMorph.AddBlendType.Tear3
  197. },
  198. {
  199. "涙(玉)",
  200. TMorph.AddBlendType.TearBig
  201. },
  202. {
  203. "涎",
  204. TMorph.AddBlendType.Yodare
  205. },
  206. {
  207. "赤面",
  208. TMorph.AddBlendType.Blush
  209. },
  210. {
  211. "ショック",
  212. TMorph.AddBlendType.Shock
  213. }
  214. };
  215. foreach (KeyValuePair<string, TMorph.AddBlendType> keyValuePair in dictionary)
  216. {
  217. if (this.m_AddFaceOptionDic.ContainsKey(keyValuePair.Key) && this.m_AddFaceOptionDic[keyValuePair.Key].check)
  218. {
  219. addBlendType |= keyValuePair.Value;
  220. }
  221. }
  222. return addBlendType;
  223. }
  224. private bool IsOpenMouth()
  225. {
  226. return this.m_AddFaceOptionDic["口を開く"].check;
  227. }
  228. private void UpdateCheckBoxAddOption(PhotoFaceDataShortcut.ItemData itemData)
  229. {
  230. if (itemData == null || itemData.data == null)
  231. {
  232. Debug.Log("表情データが空だったので、追加表情データの表示は最後の状態を引き継ぐ");
  233. return;
  234. }
  235. Dictionary<string, TMorph.AddBlendType> dictionary = new Dictionary<string, TMorph.AddBlendType>
  236. {
  237. {
  238. "頬染め1",
  239. TMorph.AddBlendType.Cheek1
  240. },
  241. {
  242. "頬染め2",
  243. TMorph.AddBlendType.Cheek2
  244. },
  245. {
  246. "頬染め3",
  247. TMorph.AddBlendType.Cheek3
  248. },
  249. {
  250. "涙1",
  251. TMorph.AddBlendType.Tear1
  252. },
  253. {
  254. "涙2",
  255. TMorph.AddBlendType.Tear2
  256. },
  257. {
  258. "涙3",
  259. TMorph.AddBlendType.Tear3
  260. },
  261. {
  262. "涙(玉)",
  263. TMorph.AddBlendType.TearBig
  264. },
  265. {
  266. "涎",
  267. TMorph.AddBlendType.Yodare
  268. },
  269. {
  270. "赤面",
  271. TMorph.AddBlendType.Blush
  272. },
  273. {
  274. "ショック",
  275. TMorph.AddBlendType.Shock
  276. }
  277. };
  278. foreach (KeyValuePair<string, TMorph.AddBlendType> keyValuePair in dictionary)
  279. {
  280. this.m_AddFaceOptionDic[keyValuePair.Key].check = ((itemData.blendType & keyValuePair.Value) != TMorph.AddBlendType.None);
  281. }
  282. }
  283. private void OnClickCheckBoxAddOption(WFCheckBox check_box)
  284. {
  285. string[] array = new string[]
  286. {
  287. "頬染め1",
  288. "頬染め2",
  289. "頬染め3"
  290. };
  291. string[] array2 = new string[]
  292. {
  293. "涙1",
  294. "涙2",
  295. "涙3"
  296. };
  297. string[][] array3 = new string[][]
  298. {
  299. array,
  300. array2
  301. };
  302. foreach (KeyValuePair<string, WFCheckBox> keyValuePair in this.m_AddFaceOptionDic)
  303. {
  304. if (keyValuePair.Value == check_box)
  305. {
  306. foreach (string array4 in array3)
  307. {
  308. if (0 <= Array.IndexOf<string>(array4, keyValuePair.Key))
  309. {
  310. for (int j = 0; j < array4.Length; j++)
  311. {
  312. if (!(array4[j] == keyValuePair.Key))
  313. {
  314. if (this.m_AddFaceOptionDic[array4[j]].check)
  315. {
  316. this.m_AddFaceOptionDic[array4[j]].check = false;
  317. }
  318. }
  319. }
  320. }
  321. }
  322. }
  323. }
  324. if (this.nowSelectItem != null && this.nowSelectItem.data != null)
  325. {
  326. this.ApplyItemData(this.nowSelectItem, this.nowSelectItem.data, this.ConvertBlendType());
  327. if (this.nowSelectItem != null)
  328. {
  329. if (this.targetControllerRight.itemDataList.Contains(this.nowSelectItem))
  330. {
  331. this.targetControllerRight.Emulate(this.nowSelectItem);
  332. }
  333. else if (this.targetControllerLeft.itemDataList.Contains(this.nowSelectItem))
  334. {
  335. this.targetControllerLeft.Emulate(this.nowSelectItem);
  336. }
  337. else
  338. {
  339. Debug.LogWarning("コントローラに存在しない項目を更新しているかもしれない");
  340. }
  341. }
  342. }
  343. }
  344. private void WaitTime(float time, Action onFinish)
  345. {
  346. base.StartCoroutine(this.CoWaitTime(time, onFinish));
  347. }
  348. private IEnumerator CoWaitTime(float time, Action onFinish)
  349. {
  350. yield return new WaitForSeconds(time);
  351. if (onFinish != null)
  352. {
  353. onFinish();
  354. }
  355. yield break;
  356. }
  357. [SerializeField]
  358. [Range(0.001f, 1f)]
  359. private float m_FadeSpeed = 0.25f;
  360. [SerializeField]
  361. private CircleCommandUI m_ButtonListShortcutRight;
  362. [SerializeField]
  363. private CircleCommandUI m_ButtonListShortcutLeft;
  364. [SerializeField]
  365. private ListViewerWindow m_WindowListFaceData;
  366. [SerializeField]
  367. private GameObject m_ParentAddFaceOptions;
  368. [SerializeField]
  369. private UIButton m_ButtonFaceListOK;
  370. private NGUIWindow m_FadeWindowShortcutButtonsRight;
  371. private NGUIWindow m_FadeWindowShortcutButtonsLeft;
  372. private NGUIWindow m_FadeWindowFaceDataList;
  373. private PhotoFaceDataShortcut.ItemData m_NowSelectItem;
  374. private Dictionary<PhotoFaceDataShortcut.ItemData, PhotoFaceDataShortcutSetter.ItemData> m_ItemPairDic = new Dictionary<PhotoFaceDataShortcut.ItemData, PhotoFaceDataShortcutSetter.ItemData>();
  375. private Dictionary<string, WFCheckBox> m_AddFaceOptionDic = new Dictionary<string, WFCheckBox>();
  376. public class ItemData : MonoBehaviour
  377. {
  378. public UILabel label
  379. {
  380. get
  381. {
  382. return this.m_Label;
  383. }
  384. set
  385. {
  386. this.m_Label = value;
  387. }
  388. }
  389. private UILabel m_Label;
  390. }
  391. }