WindowPartsFaceMorph.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. if (maid.IsCrcBody || !(sliderAndInputSet.Name == "tanga"))
  53. {
  54. storeData.Add("morph_val_" + sliderAndInputSet.Name, this.GetValue(maid, sliderAndInputSet.Name).ToString("G9"));
  55. }
  56. }
  57. }
  58. }
  59. else
  60. {
  61. for (int l = 0; l < this.propValInput.Length; l++)
  62. {
  63. for (int m = 0; m < this.propValInput[l].SliderAndInput.Length; m++)
  64. {
  65. WindowPartsInputSliderSet.SliderAndInputSet sliderAndInputSet2 = this.propValInput[l].SliderAndInput[m];
  66. if (maid.IsCrcBody || !(sliderAndInputSet2.Name == "tanga"))
  67. {
  68. this.SetValue(maid, sliderAndInputSet2.Name, float.Parse(storeData["morph_val_" + sliderAndInputSet2.Name]));
  69. }
  70. }
  71. }
  72. }
  73. }
  74. public void CreateBackupData(Maid maid)
  75. {
  76. if (maid == null || maid.boMAN)
  77. {
  78. return;
  79. }
  80. string guid = maid.status.guid;
  81. this.RemoveBackupData(maid);
  82. Dictionary<string, float[]> dictionary = new Dictionary<string, float[]>();
  83. foreach (KeyValuePair<string, float[]> keyValuePair in maid.body0.Face.morph.dicBlendSet)
  84. {
  85. float[] array = new float[keyValuePair.Value.Length];
  86. keyValuePair.Value.CopyTo(array, 0);
  87. dictionary.Add(keyValuePair.Key, array);
  88. }
  89. this.backupBlendSets.Add(guid, dictionary);
  90. }
  91. public void ApplyBackupData(Maid maid)
  92. {
  93. if (maid == null)
  94. {
  95. return;
  96. }
  97. string guid = maid.status.guid;
  98. if (this.backupBlendSets.ContainsKey(guid))
  99. {
  100. Dictionary<string, float[]> dictionary = this.backupBlendSets[guid];
  101. foreach (KeyValuePair<string, float[]> keyValuePair in maid.body0.Face.morph.dicBlendSet)
  102. {
  103. dictionary[keyValuePair.Key].CopyTo(maid.body0.Face.morph.dicBlendSet[keyValuePair.Key], 0);
  104. }
  105. }
  106. else
  107. {
  108. Debug.Log("FaceMorphのバックアップデータが見つかりませんでした");
  109. }
  110. }
  111. public bool RemoveBackupData(Maid maid)
  112. {
  113. if (maid == null)
  114. {
  115. return false;
  116. }
  117. bool result = false;
  118. string guid = maid.status.guid;
  119. if (this.backupBlendSets.ContainsKey(guid))
  120. {
  121. this.backupBlendSets.Remove(guid);
  122. result = true;
  123. }
  124. return result;
  125. }
  126. public void Apply(Maid maid)
  127. {
  128. if (maid == null)
  129. {
  130. return;
  131. }
  132. this.UpdateGui(maid);
  133. }
  134. public void OnChangetPropInputValue(WindowPartsInputSliderSet.SliderAndInputSet input_object, float val)
  135. {
  136. if (this.faceWindow == null || this.faceWindow.mgr.select_maid == null)
  137. {
  138. return;
  139. }
  140. string name = input_object.Name;
  141. this.SetValue(this.faceWindow.mgr.select_maid, name, val);
  142. this.faceWindow.GetMaidStoreData(this.faceWindow.mgr.select_maid)["morph_val_" + name] = val.ToString("G9");
  143. }
  144. public void UpdateGui(Maid maid)
  145. {
  146. if (maid == null)
  147. {
  148. return;
  149. }
  150. Dictionary<string, int> blendIdDic = this.blendIdDictionary[maid.status.guid];
  151. for (int i = 0; i < this.propValInput.Length; i++)
  152. {
  153. for (int j = 0; j < this.propValInput[i].SliderAndInput.Length; j++)
  154. {
  155. string name = this.propValInput[i].SliderAndInput[j].Name;
  156. if (maid.IsCrcBody || !(name == "tanga"))
  157. {
  158. PhotoSliderAndInput sliderAndInput = this.propValInput[i].GetSliderAndInput(name);
  159. sliderAndInput.ResetNum = this.backupBlendSets[maid.status.guid][this.selectData.setting_name][this.GetBlendIdx(maid.body0.Face, blendIdDic, name)];
  160. List<Action<float>> onChangeValue = sliderAndInput.onChangeValue;
  161. sliderAndInput.onChangeValue = new List<Action<float>>();
  162. sliderAndInput.value = this.GetValue(maid, name);
  163. sliderAndInput.onChangeValue = onChangeValue;
  164. this.faceWindow.GetMaidStoreData(maid)["morph_val_" + name] = sliderAndInput.value.ToString("G9");
  165. }
  166. }
  167. }
  168. }
  169. public void SetPhotoFaceData(PhotoFaceData data)
  170. {
  171. this.selectData = data;
  172. }
  173. private void SetValue(Maid maid, string name, float val)
  174. {
  175. if (maid == null || maid.body0 == null || maid.body0.Face == null)
  176. {
  177. return;
  178. }
  179. Dictionary<string, int> blendIdDic = this.blendIdDictionary[maid.status.guid];
  180. this.selectData.BlendArray(maid)[this.GetBlendIdx(maid.body0.Face, blendIdDic, name)] = val;
  181. }
  182. private float GetValue(Maid maid, string name)
  183. {
  184. if (maid == null || maid.body0 == null || maid.body0.Face == null)
  185. {
  186. return 0f;
  187. }
  188. Dictionary<string, int> blendIdDic = this.blendIdDictionary[maid.status.guid];
  189. return this.selectData.BlendArray(maid)[this.GetBlendIdx(maid.body0.Face, blendIdDic, name)];
  190. }
  191. private int GetBlendIdx(TBodySkin face, Dictionary<string, int> blendIdDic, string name)
  192. {
  193. if (120 <= face.PartsVersion && name.IndexOf("eyeclose") == 0)
  194. {
  195. string text = name;
  196. if (text == "eyeclose")
  197. {
  198. text += "1";
  199. }
  200. TMorph.GP01FB_FACE_TYPE faceTypeGP01FB = face.morph.GetFaceTypeGP01FB();
  201. text += TMorph.crcFaceTypesStr[(int)faceTypeGP01FB];
  202. if (blendIdDic.ContainsKey(text))
  203. {
  204. name = text;
  205. }
  206. }
  207. return blendIdDic[name];
  208. }
  209. public bool visible
  210. {
  211. get
  212. {
  213. return base.gameObject.activeSelf;
  214. }
  215. set
  216. {
  217. base.gameObject.SetActive(value);
  218. }
  219. }
  220. [SerializeField]
  221. private WindowPartsInputSliderSet[] propValInput;
  222. [HideInInspector]
  223. public bool isFacialUpdate;
  224. private FaceWindow faceWindow;
  225. private Dictionary<string, Dictionary<string, int>> blendIdDictionary = new Dictionary<string, Dictionary<string, int>>();
  226. private Dictionary<string, Dictionary<string, float[]>> backupBlendSets = new Dictionary<string, Dictionary<string, float[]>>();
  227. private PhotoFaceData selectData;
  228. }