WindowPartsFaceMorph.cs 5.7 KB

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