123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- public class WindowPartsFaceMorph : MonoBehaviour
- {
- public void Awake()
- {
- for (int i = 0; i < this.propValInput.Length; i++)
- {
- this.propValInput[i].onChangeValue.Add(new Action<WindowPartsInputSliderSet.SliderAndInputSet, float>(this.OnChangetPropInputValue));
- }
- }
- public void SetFaceWindow(FaceWindow faceWindow)
- {
- this.faceWindow = faceWindow;
- }
- public void OnDestroy()
- {
- }
- public void OnMaidAddEvent(Maid maid, bool isDeserializeLoad, Dictionary<string, string> storeData)
- {
- if (maid == null || maid.boMAN)
- {
- return;
- }
- this.SetPhotoFaceData(PhotoFaceData.Get(long.Parse(storeData["id"])));
- this.CreateBackupData(maid);
- if (!isDeserializeLoad)
- {
- for (int i = 0; i < this.propValInput.Length; i++)
- {
- for (int j = 0; j < this.propValInput[i].SliderAndInput.Length; j++)
- {
- WindowPartsInputSliderSet.SliderAndInputSet sliderAndInputSet = this.propValInput[i].SliderAndInput[j];
- storeData.Add("morph_val_" + sliderAndInputSet.Name, this.GetValue(maid, sliderAndInputSet.Name).ToString("G9"));
- }
- }
- }
- else
- {
- for (int k = 0; k < this.propValInput.Length; k++)
- {
- for (int l = 0; l < this.propValInput[k].SliderAndInput.Length; l++)
- {
- WindowPartsInputSliderSet.SliderAndInputSet sliderAndInputSet2 = this.propValInput[k].SliderAndInput[l];
- this.SetValue(maid, sliderAndInputSet2.Name, float.Parse(storeData["morph_val_" + sliderAndInputSet2.Name]));
- }
- }
- }
- }
- public void CreateBackupData(Maid maid)
- {
- if (maid == null || maid.boMAN)
- {
- return;
- }
- string guid = maid.status.guid;
- this.RemoveBackupData(maid);
- Dictionary<string, float[]> dictionary = new Dictionary<string, float[]>();
- foreach (KeyValuePair<string, float[]> keyValuePair in maid.body0.Face.morph.dicBlendSet)
- {
- float[] array = new float[keyValuePair.Value.Length];
- keyValuePair.Value.CopyTo(array, 0);
- dictionary.Add(keyValuePair.Key, array);
- }
- this.backupBlendSets.Add(guid, dictionary);
- }
- public void ApplyBackupData(Maid maid)
- {
- if (maid == null)
- {
- return;
- }
- string guid = maid.status.guid;
- if (this.backupBlendSets.ContainsKey(guid))
- {
- Dictionary<string, float[]> dictionary = this.backupBlendSets[guid];
- foreach (KeyValuePair<string, float[]> keyValuePair in maid.body0.Face.morph.dicBlendSet)
- {
- dictionary[keyValuePair.Key].CopyTo(maid.body0.Face.morph.dicBlendSet[keyValuePair.Key], 0);
- }
- }
- else
- {
- Debug.Log("FaceMorphのバックアップデータが見つかりませんでした");
- }
- }
- public bool RemoveBackupData(Maid maid)
- {
- if (maid == null)
- {
- return false;
- }
- bool result = false;
- string guid = maid.status.guid;
- if (this.backupBlendSets.ContainsKey(guid))
- {
- this.backupBlendSets.Remove(guid);
- result = true;
- }
- return result;
- }
- public void Apply(Maid maid)
- {
- if (maid == null)
- {
- return;
- }
- this.UpdateGui(maid);
- }
- public void OnChangetPropInputValue(WindowPartsInputSliderSet.SliderAndInputSet input_object, float val)
- {
- if (this.faceWindow == null || this.faceWindow.mgr.select_maid == null)
- {
- return;
- }
- string name = input_object.Name;
- this.SetValue(this.faceWindow.mgr.select_maid, name, val);
- this.faceWindow.GetMaidStoreData(this.faceWindow.mgr.select_maid)["morph_val_" + name] = val.ToString("G9");
- }
- public void UpdateGui(Maid maid)
- {
- if (maid == null)
- {
- return;
- }
- for (int i = 0; i < this.propValInput.Length; i++)
- {
- for (int j = 0; j < this.propValInput[i].SliderAndInput.Length; j++)
- {
- string name = this.propValInput[i].SliderAndInput[j].Name;
- PhotoSliderAndInput sliderAndInput = this.propValInput[i].GetSliderAndInput(name);
- sliderAndInput.ResetNum = this.backupBlendSets[maid.status.guid][this.selectData.setting_name][this.blendIdDictionary[name]];
- sliderAndInput.value = this.GetValue(maid, name);
- this.faceWindow.GetMaidStoreData(maid)["morph_val_" + name] = sliderAndInput.value.ToString("G9");
- }
- }
- }
- public void SetPhotoFaceData(PhotoFaceData data)
- {
- this.selectData = data;
- }
- private void SetValue(Maid maid, string name, float val)
- {
- if (maid == null || maid.body0 == null || maid.body0.Face == null)
- {
- return;
- }
- if (this.blendIdDictionary.Count <= 0)
- {
- List<BlendData> blendDatas = maid.body0.Face.morph.BlendDatas;
- for (int i = 0; i < blendDatas.Count; i++)
- {
- if (blendDatas[i] != null)
- {
- if (!this.blendIdDictionary.ContainsKey(blendDatas[i].name))
- {
- this.blendIdDictionary.Add(blendDatas[i].name, i);
- }
- }
- }
- }
- this.selectData.BlendArray(maid)[this.blendIdDictionary[name]] = val;
- }
- private float GetValue(Maid maid, string name)
- {
- if (maid == null || maid.body0 == null || maid.body0.Face == null)
- {
- return 0f;
- }
- if (this.blendIdDictionary.Count <= 0)
- {
- List<BlendData> blendDatas = maid.body0.Face.morph.BlendDatas;
- for (int i = 0; i < blendDatas.Count; i++)
- {
- if (blendDatas[i] != null)
- {
- if (!this.blendIdDictionary.ContainsKey(blendDatas[i].name))
- {
- this.blendIdDictionary.Add(blendDatas[i].name, i);
- }
- }
- }
- }
- return this.selectData.BlendArray(maid)[this.blendIdDictionary[name]];
- }
- public bool visible
- {
- get
- {
- return base.gameObject.activeSelf;
- }
- set
- {
- base.gameObject.SetActive(value);
- }
- }
- [SerializeField]
- private WindowPartsInputSliderSet[] propValInput;
- [HideInInspector]
- public bool isFacialUpdate;
- private FaceWindow faceWindow;
- private Dictionary<string, int> blendIdDictionary = new Dictionary<string, int>();
- private Dictionary<string, Dictionary<string, float[]>> backupBlendSets = new Dictionary<string, Dictionary<string, float[]>>();
- private PhotoFaceData selectData;
- }
|