WindowPartsFaceMorph.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class WindowPartsFaceMorph : MonoBehaviour
  5. {
  6. public void Awake()
  7. {
  8. for (int i = 0; i < this.propValInput.Length; i++)
  9. {
  10. this.propValInput[i].onChangeValue.Add(new Action<WindowPartsInputSliderSet.SliderAndInputSet, float>(this.OnChangetPropInputValue));
  11. }
  12. }
  13. public void SetFaceWindow(FaceWindow faceWindow)
  14. {
  15. this.faceWindow = faceWindow;
  16. }
  17. public void OnDestroy()
  18. {
  19. }
  20. public void OnMaidAddEvent(Maid maid, bool isDeserializeLoad, Dictionary<string, string> storeData)
  21. {
  22. if (maid == null || maid.boMAN)
  23. {
  24. return;
  25. }
  26. this.SetPhotoFaceData(PhotoFaceData.Get(long.Parse(storeData["id"])));
  27. this.CreateBackupData(maid);
  28. List<BlendData> blendDatas = maid.body0.Face.morph.BlendDatas;
  29. Dictionary<string, int> dictionary = new Dictionary<string, int>();
  30. for (int i = 0; i < blendDatas.Count; i++)
  31. {
  32. if (blendDatas[i] != null)
  33. {
  34. if (!dictionary.ContainsKey(blendDatas[i].name))
  35. {
  36. dictionary.Add(blendDatas[i].name, i);
  37. }
  38. }
  39. }
  40. if (!this.blendIdDictionary.ContainsKey(maid.status.guid))
  41. {
  42. this.blendIdDictionary.Add(maid.status.guid, new Dictionary<string, int>());
  43. }
  44. this.blendIdDictionary[maid.status.guid] = dictionary;
  45. if (!isDeserializeLoad)
  46. {
  47. for (int j = 0; j < this.propValInput.Length; j++)
  48. {
  49. for (int k = 0; k < this.propValInput[j].SliderAndInput.Length; k++)
  50. {
  51. WindowPartsInputSliderSet.SliderAndInputSet sliderAndInputSet = this.propValInput[j].SliderAndInput[k];
  52. storeData.Add("morph_val_" + sliderAndInputSet.Name, this.GetValue(maid, sliderAndInputSet.Name).ToString("G9"));
  53. }
  54. }
  55. }
  56. else
  57. {
  58. for (int l = 0; l < this.propValInput.Length; l++)
  59. {
  60. for (int m = 0; m < this.propValInput[l].SliderAndInput.Length; m++)
  61. {
  62. WindowPartsInputSliderSet.SliderAndInputSet sliderAndInputSet2 = this.propValInput[l].SliderAndInput[m];
  63. this.SetValue(maid, sliderAndInputSet2.Name, float.Parse(storeData["morph_val_" + sliderAndInputSet2.Name]));
  64. }
  65. }
  66. }
  67. }
  68. public void CreateBackupData(Maid maid)
  69. {
  70. if (maid == null || maid.boMAN)
  71. {
  72. return;
  73. }
  74. string guid = maid.status.guid;
  75. this.RemoveBackupData(maid);
  76. Dictionary<string, float[]> dictionary = new Dictionary<string, float[]>();
  77. foreach (KeyValuePair<string, float[]> keyValuePair in maid.body0.Face.morph.dicBlendSet)
  78. {
  79. float[] array = new float[keyValuePair.Value.Length];
  80. keyValuePair.Value.CopyTo(array, 0);
  81. dictionary.Add(keyValuePair.Key, array);
  82. }
  83. this.backupBlendSets.Add(guid, dictionary);
  84. }
  85. public void ApplyBackupData(Maid maid)
  86. {
  87. if (maid == null)
  88. {
  89. return;
  90. }
  91. string guid = maid.status.guid;
  92. if (this.backupBlendSets.ContainsKey(guid))
  93. {
  94. Dictionary<string, float[]> dictionary = this.backupBlendSets[guid];
  95. foreach (KeyValuePair<string, float[]> keyValuePair in maid.body0.Face.morph.dicBlendSet)
  96. {
  97. dictionary[keyValuePair.Key].CopyTo(maid.body0.Face.morph.dicBlendSet[keyValuePair.Key], 0);
  98. }
  99. }
  100. else
  101. {
  102. Debug.Log("FaceMorphのバックアップデータが見つかりませんでした");
  103. }
  104. }
  105. public bool RemoveBackupData(Maid maid)
  106. {
  107. if (maid == null)
  108. {
  109. return false;
  110. }
  111. bool result = false;
  112. string guid = maid.status.guid;
  113. if (this.backupBlendSets.ContainsKey(guid))
  114. {
  115. this.backupBlendSets.Remove(guid);
  116. result = true;
  117. }
  118. return result;
  119. }
  120. public void Apply(Maid maid)
  121. {
  122. if (maid == null)
  123. {
  124. return;
  125. }
  126. this.UpdateGui(maid);
  127. }
  128. public void OnChangetPropInputValue(WindowPartsInputSliderSet.SliderAndInputSet input_object, float val)
  129. {
  130. if (this.faceWindow == null || this.faceWindow.mgr.select_maid == null)
  131. {
  132. return;
  133. }
  134. string name = input_object.Name;
  135. this.SetValue(this.faceWindow.mgr.select_maid, name, val);
  136. this.faceWindow.GetMaidStoreData(this.faceWindow.mgr.select_maid)["morph_val_" + name] = val.ToString("G9");
  137. }
  138. public void UpdateGui(Maid maid)
  139. {
  140. if (maid == null)
  141. {
  142. return;
  143. }
  144. Dictionary<string, int> blendIdDic = this.blendIdDictionary[maid.status.guid];
  145. for (int i = 0; i < this.propValInput.Length; i++)
  146. {
  147. for (int j = 0; j < this.propValInput[i].SliderAndInput.Length; j++)
  148. {
  149. string name = this.propValInput[i].SliderAndInput[j].Name;
  150. PhotoSliderAndInput sliderAndInput = this.propValInput[i].GetSliderAndInput(name);
  151. sliderAndInput.ResetNum = this.backupBlendSets[maid.status.guid][this.selectData.setting_name][this.GetBlendIdx(maid.body0.Face, blendIdDic, name)];
  152. List<Action<float>> onChangeValue = sliderAndInput.onChangeValue;
  153. sliderAndInput.onChangeValue = new List<Action<float>>();
  154. sliderAndInput.value = this.GetValue(maid, name);
  155. sliderAndInput.onChangeValue = onChangeValue;
  156. this.faceWindow.GetMaidStoreData(maid)["morph_val_" + name] = sliderAndInput.value.ToString("G9");
  157. }
  158. }
  159. }
  160. public void SetPhotoFaceData(PhotoFaceData data)
  161. {
  162. this.selectData = data;
  163. }
  164. private void SetValue(Maid maid, string name, float val)
  165. {
  166. if (maid == null || maid.body0 == null || maid.body0.Face == null)
  167. {
  168. return;
  169. }
  170. Dictionary<string, int> blendIdDic = this.blendIdDictionary[maid.status.guid];
  171. this.selectData.BlendArray(maid)[this.GetBlendIdx(maid.body0.Face, blendIdDic, name)] = val;
  172. }
  173. private float GetValue(Maid maid, string name)
  174. {
  175. if (maid == null || maid.body0 == null || maid.body0.Face == null)
  176. {
  177. return 0f;
  178. }
  179. Dictionary<string, int> blendIdDic = this.blendIdDictionary[maid.status.guid];
  180. return this.selectData.BlendArray(maid)[this.GetBlendIdx(maid.body0.Face, blendIdDic, name)];
  181. }
  182. private int GetBlendIdx(TBodySkin face, Dictionary<string, int> blendIdDic, string name)
  183. {
  184. if (120 <= face.PartsVersion && name.IndexOf("eyeclose") == 0)
  185. {
  186. string text = name;
  187. if (text == "eyeclose")
  188. {
  189. text += "1";
  190. }
  191. TMorph.GP01FB_FACE_TYPE faceTypeGP01FB = face.morph.GetFaceTypeGP01FB();
  192. text += TMorph.crcFaceTypesStr[(int)faceTypeGP01FB];
  193. if (blendIdDic.ContainsKey(text))
  194. {
  195. name = text;
  196. }
  197. }
  198. return blendIdDic[name];
  199. }
  200. public bool visible
  201. {
  202. get
  203. {
  204. return base.gameObject.activeSelf;
  205. }
  206. set
  207. {
  208. base.gameObject.SetActive(value);
  209. }
  210. }
  211. [SerializeField]
  212. private WindowPartsInputSliderSet[] propValInput;
  213. [HideInInspector]
  214. public bool isFacialUpdate;
  215. private FaceWindow faceWindow;
  216. private Dictionary<string, Dictionary<string, int>> blendIdDictionary = new Dictionary<string, Dictionary<string, int>>();
  217. private Dictionary<string, Dictionary<string, float[]>> backupBlendSets = new Dictionary<string, Dictionary<string, float[]>>();
  218. private PhotoFaceData selectData;
  219. }