PhotoFaceDataShortcut.cs 9.7 KB

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