PhotoFaceDataShortcut.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. using System;
  2. using System.Collections.Generic;
  3. using I2.Loc;
  4. using UnityEngine;
  5. using UnityEngine.Events;
  6. using UnityEngine.UI;
  7. public class PhotoFaceDataShortcut : MonoBehaviour
  8. {
  9. public List<PhotoFaceDataShortcut.ItemData> itemDataList
  10. {
  11. get
  12. {
  13. return this.m_ItemDataList;
  14. }
  15. }
  16. public bool IsLeftHand
  17. {
  18. get
  19. {
  20. return this.m_IsLeftHand;
  21. }
  22. set
  23. {
  24. this.m_IsLeftHand = value;
  25. }
  26. }
  27. public void Init(bool isLeftHand)
  28. {
  29. this.m_IsLeftHand = isLeftHand;
  30. CircleCommandUI circleCommandUI = this.m_CircleList.circleCommandUI;
  31. circleCommandUI.onSelect.AddListener(new UnityAction<GameObject>(this.OnSelectItem));
  32. circleCommandUI.onDeselect.AddListener(new UnityAction<GameObject>(this.OnDeselectItem));
  33. circleCommandUI.onDecide.AddListener(new UnityAction<GameObject>(this.OnDecide));
  34. this.m_CircleList.controller = ((!isLeftHand) ? GameMain.Instance.OvrMgr.ovr_obj.right_controller.controller : GameMain.Instance.OvrMgr.ovr_obj.left_controller.controller);
  35. this.m_CircleList.SetActiveUI(true);
  36. GameObject childObject = UTY.GetChildObject(base.gameObject, "CircleCommandUI/text right hand", false);
  37. childObject.GetComponent<Text>().text = ((!isLeftHand) ? "右" : "左");
  38. childObject.GetComponent<Localize>().SetTerm("System/" + ((!isLeftHand) ? "右" : "左"));
  39. }
  40. public void CreateItemList(int count)
  41. {
  42. CircleCommandUI circleCommandUI = this.m_CircleList.circleCommandUI;
  43. GameObject tempItem = circleCommandUI.listViewer.tempItem;
  44. Transform transform = tempItem.transform;
  45. transform.localScale = Vector3.one * 0.5f;
  46. this.itemDataList.Clear();
  47. PhotoFaceData.Create();
  48. circleCommandUI.Show<Transform>(count, delegate(int index, Transform trans)
  49. {
  50. Text componentInChildren = trans.GetComponentInChildren<Text>();
  51. Localize componentInChildren2 = trans.GetComponentInChildren<Localize>();
  52. PhotoFaceDataShortcut.ItemData itemData = trans.gameObject.AddComponent<PhotoFaceDataShortcut.ItemData>();
  53. itemData.handController = this;
  54. itemData.index = index;
  55. itemData.text = componentInChildren;
  56. itemData.localize = componentInChildren2;
  57. this.itemDataList.Add(itemData);
  58. });
  59. ControllerShortcutSettingData.LoadDefault();
  60. if (this.m_IsLeftHand)
  61. {
  62. List<PhotoFaceDataShortcut.FaceData> faceListLeft = ControllerShortcutSettingData.config.faceListLeft;
  63. for (int i = 0; i < faceListLeft.Count; i++)
  64. {
  65. if (i < this.itemDataList.Count)
  66. {
  67. this.itemDataList[i].faceData = faceListLeft[i];
  68. }
  69. }
  70. }
  71. else
  72. {
  73. List<PhotoFaceDataShortcut.FaceData> faceListRight = ControllerShortcutSettingData.config.faceListRight;
  74. for (int j = 0; j < faceListRight.Count; j++)
  75. {
  76. if (j < this.itemDataList.Count)
  77. {
  78. this.itemDataList[j].faceData = faceListRight[j];
  79. }
  80. }
  81. }
  82. }
  83. private void OnSelectItem(GameObject item)
  84. {
  85. if (item == null)
  86. {
  87. return;
  88. }
  89. Graphic component = item.GetComponent<Graphic>();
  90. if (component != null)
  91. {
  92. component.color = Color.red;
  93. }
  94. item.transform.localScale = Vector3.one;
  95. item.transform.SetAsLastSibling();
  96. if (ControllerShortcutSettingData.config.isDirectMode)
  97. {
  98. PhotoFaceDataShortcut.ItemData component2 = item.GetComponent<PhotoFaceDataShortcut.ItemData>();
  99. if (component2 != null)
  100. {
  101. this.ApplyMaidFace(this.GetMaid(), component2);
  102. }
  103. }
  104. }
  105. private void OnDeselectItem(GameObject item)
  106. {
  107. if (item == null)
  108. {
  109. return;
  110. }
  111. Graphic component = item.GetComponent<Graphic>();
  112. if (component != null)
  113. {
  114. Color white = Color.white;
  115. white.a = 0.5f;
  116. component.color = white;
  117. }
  118. item.transform.localScale = Vector3.one * 0.5f;
  119. }
  120. private void OnDecide(GameObject selectItem)
  121. {
  122. if (selectItem == null)
  123. {
  124. Debug.LogWarning("選択項目にnullが入った");
  125. return;
  126. }
  127. this.OnDeselectItem(selectItem);
  128. if (!ControllerShortcutSettingData.config.isEveryShowMode)
  129. {
  130. this.m_CircleList.SetActiveUI(false);
  131. }
  132. if (ControllerShortcutSettingData.config.isDirectMode)
  133. {
  134. return;
  135. }
  136. PhotoFaceDataShortcut.ItemData component = selectItem.GetComponent<PhotoFaceDataShortcut.ItemData>();
  137. if (component != null)
  138. {
  139. this.ApplyMaidFace(this.GetMaid(), component);
  140. }
  141. }
  142. private void ApplyMaidFace(Maid maid, PhotoFaceDataShortcut.ItemData itemData)
  143. {
  144. if (itemData == null || itemData.data == null)
  145. {
  146. Debug.Log("表情データにnullが指定されました。");
  147. return;
  148. }
  149. if (maid == null)
  150. {
  151. Debug.Log("メイドにnullが指定されました。");
  152. return;
  153. }
  154. maid.FaceAnime(itemData.data.setting_name, 0.5f, 0);
  155. maid.body0.Face.morph.SetValueOriginalBlendSet(itemData.blendType);
  156. maid.FaceBlend("オリジナル");
  157. maid.OpenMouth(itemData.isOpenMouth);
  158. Debug.Log(string.Concat(new object[]
  159. {
  160. "基本表情:",
  161. itemData.data.name,
  162. "\n追加表情:",
  163. itemData.blendType
  164. }));
  165. }
  166. public void Emulate(PhotoFaceDataShortcut.ItemData itemData)
  167. {
  168. if (!this.itemDataList.Contains(itemData))
  169. {
  170. Debug.Log("コントローラ上に存在しないデータを選んだ");
  171. return;
  172. }
  173. this.ApplyMaidFace(this.GetMaid(), itemData);
  174. }
  175. private Maid GetMaid()
  176. {
  177. CharacterMgr characterMgr = GameMain.Instance.CharacterMgr;
  178. return characterMgr.GetMaid(0);
  179. }
  180. [SerializeField]
  181. private CircleListSelectUI m_CircleList;
  182. private List<PhotoFaceDataShortcut.ItemData> m_ItemDataList = new List<PhotoFaceDataShortcut.ItemData>();
  183. private bool m_IsLeftHand;
  184. [Serializable]
  185. public class FaceData
  186. {
  187. public string dataName
  188. {
  189. get
  190. {
  191. return this.m_strData;
  192. }
  193. }
  194. public PhotoFaceData data
  195. {
  196. get
  197. {
  198. return this.m_Data;
  199. }
  200. set
  201. {
  202. this.m_Data = value;
  203. if (value == null)
  204. {
  205. this.m_strData = PhotoFaceDataShortcut.FaceData.strDataNull;
  206. }
  207. else
  208. {
  209. this.m_strData = value.setting_name;
  210. }
  211. }
  212. }
  213. public TMorph.AddBlendType blendType
  214. {
  215. get
  216. {
  217. return this.m_BlendType;
  218. }
  219. set
  220. {
  221. this.m_BlendType = value;
  222. }
  223. }
  224. public bool isOpenMouth
  225. {
  226. get
  227. {
  228. return this.m_IsOpenMouth;
  229. }
  230. set
  231. {
  232. this.m_IsOpenMouth = value;
  233. }
  234. }
  235. public static PhotoFaceDataShortcut.FaceData defaultData
  236. {
  237. get
  238. {
  239. if (PhotoFaceDataShortcut.FaceData.m_DefaultData == null)
  240. {
  241. PhotoFaceData.Create();
  242. PhotoFaceDataShortcut.FaceData.m_DefaultData = new PhotoFaceDataShortcut.FaceData();
  243. PhotoFaceDataShortcut.FaceData.m_DefaultData.data = PhotoFaceData.init_data;
  244. PhotoFaceDataShortcut.FaceData.m_DefaultData.m_strData = PhotoFaceDataShortcut.FaceData.strDataNull;
  245. PhotoFaceDataShortcut.FaceData.m_DefaultData.blendType = TMorph.AddBlendType.None;
  246. PhotoFaceDataShortcut.FaceData.m_DefaultData.isOpenMouth = false;
  247. }
  248. return PhotoFaceDataShortcut.FaceData.m_DefaultData;
  249. }
  250. }
  251. private PhotoFaceData m_Data;
  252. [SerializeField]
  253. private TMorph.AddBlendType m_BlendType;
  254. [SerializeField]
  255. private bool m_IsOpenMouth;
  256. [SerializeField]
  257. private string m_strData;
  258. private static string strDataNull = "通常";
  259. private static PhotoFaceDataShortcut.FaceData m_DefaultData;
  260. }
  261. public class ItemData : MonoBehaviour
  262. {
  263. public PhotoFaceDataShortcut handController { get; set; }
  264. public int index { get; set; }
  265. public PhotoFaceDataShortcut.FaceData faceData
  266. {
  267. get
  268. {
  269. return this.m_FaceData;
  270. }
  271. set
  272. {
  273. this.m_FaceData = value;
  274. this.UpdateData();
  275. }
  276. }
  277. public PhotoFaceData data
  278. {
  279. get
  280. {
  281. return this.m_FaceData.data;
  282. }
  283. set
  284. {
  285. this.m_FaceData.data = value;
  286. this.UpdateText();
  287. this.UpdateConfigData();
  288. }
  289. }
  290. public Text text
  291. {
  292. get
  293. {
  294. return this.m_Text;
  295. }
  296. set
  297. {
  298. this.m_Text = value;
  299. }
  300. }
  301. public Localize localize
  302. {
  303. get
  304. {
  305. return this.m_Localize;
  306. }
  307. set
  308. {
  309. this.m_Localize = value;
  310. }
  311. }
  312. public TMorph.AddBlendType blendType
  313. {
  314. get
  315. {
  316. return this.m_FaceData.blendType;
  317. }
  318. set
  319. {
  320. this.m_FaceData.blendType = value;
  321. }
  322. }
  323. public bool isOpenMouth
  324. {
  325. get
  326. {
  327. return this.m_FaceData.isOpenMouth;
  328. }
  329. set
  330. {
  331. this.m_FaceData.isOpenMouth = value;
  332. }
  333. }
  334. private void UpdateText()
  335. {
  336. if (this.text == null)
  337. {
  338. return;
  339. }
  340. this.text.text = this.GetDataName();
  341. this.localize.SetTerm(this.GetDataTermName());
  342. }
  343. public string GetDataName()
  344. {
  345. if (this.data == null)
  346. {
  347. return "無し";
  348. }
  349. return this.data.name;
  350. }
  351. public string GetDataTermName()
  352. {
  353. if (this.data == null)
  354. {
  355. return "無し";
  356. }
  357. return this.data.termName;
  358. }
  359. private void UpdateConfigData()
  360. {
  361. if (this.handController.IsLeftHand)
  362. {
  363. if (ControllerShortcutSettingData.config.faceListLeft.Count <= this.index)
  364. {
  365. return;
  366. }
  367. ControllerShortcutSettingData.config.faceListLeft[this.index] = this.faceData;
  368. }
  369. else
  370. {
  371. if (ControllerShortcutSettingData.config.faceListRight.Count <= this.index)
  372. {
  373. return;
  374. }
  375. ControllerShortcutSettingData.config.faceListRight[this.index] = this.faceData;
  376. }
  377. }
  378. private void UpdateData()
  379. {
  380. PhotoFaceDataShortcut.ItemData.CreatePhotoFaceDataNameDic();
  381. int num;
  382. if (PhotoFaceDataShortcut.ItemData.photoFaceDataNameDic.TryGetValue(this.faceData.dataName, out num))
  383. {
  384. this.data = PhotoFaceData.Get((long)num);
  385. }
  386. else
  387. {
  388. this.data = null;
  389. }
  390. }
  391. private static void CreatePhotoFaceDataNameDic()
  392. {
  393. if (PhotoFaceDataShortcut.ItemData.m_PhotoFaceDataNameDic != null && PhotoFaceDataShortcut.ItemData.m_PhotoFaceDataNameDic.Count > 0)
  394. {
  395. return;
  396. }
  397. PhotoFaceData.Create();
  398. PhotoFaceDataShortcut.ItemData.m_PhotoFaceDataNameDic = new SortedDictionary<string, int>();
  399. foreach (PhotoFaceData photoFaceData in PhotoFaceData.data)
  400. {
  401. PhotoFaceDataShortcut.ItemData.m_PhotoFaceDataNameDic.Add(photoFaceData.setting_name, photoFaceData.id);
  402. }
  403. }
  404. public static SortedDictionary<string, int> photoFaceDataNameDic
  405. {
  406. get
  407. {
  408. PhotoFaceDataShortcut.ItemData.CreatePhotoFaceDataNameDic();
  409. return PhotoFaceDataShortcut.ItemData.m_PhotoFaceDataNameDic;
  410. }
  411. private set
  412. {
  413. PhotoFaceDataShortcut.ItemData.m_PhotoFaceDataNameDic = value;
  414. }
  415. }
  416. private PhotoFaceDataShortcut.FaceData m_FaceData = new PhotoFaceDataShortcut.FaceData();
  417. private Text m_Text;
  418. private Localize m_Localize;
  419. private static SortedDictionary<string, int> m_PhotoFaceDataNameDic;
  420. }
  421. }