123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- 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);
- List<BlendData> blendDatas = maid.body0.Face.morph.BlendDatas;
- Dictionary<string, int> dictionary = new Dictionary<string, int>();
- for (int i = 0; i < blendDatas.Count; i++)
- {
- if (blendDatas[i] != null)
- {
- if (!dictionary.ContainsKey(blendDatas[i].name))
- {
- dictionary.Add(blendDatas[i].name, i);
- }
- }
- }
- if (!this.blendIdDictionary.ContainsKey(maid.status.guid))
- {
- this.blendIdDictionary.Add(maid.status.guid, new Dictionary<string, int>());
- }
- this.blendIdDictionary[maid.status.guid] = dictionary;
- if (!isDeserializeLoad)
- {
- for (int j = 0; j < this.propValInput.Length; j++)
- {
- for (int k = 0; k < this.propValInput[j].SliderAndInput.Length; k++)
- {
- WindowPartsInputSliderSet.SliderAndInputSet sliderAndInputSet = this.propValInput[j].SliderAndInput[k];
- storeData.Add("morph_val_" + sliderAndInputSet.Name, this.GetValue(maid, sliderAndInputSet.Name).ToString("G9"));
- }
- }
- }
- else
- {
- for (int l = 0; l < this.propValInput.Length; l++)
- {
- for (int m = 0; m < this.propValInput[l].SliderAndInput.Length; m++)
- {
- WindowPartsInputSliderSet.SliderAndInputSet sliderAndInputSet2 = this.propValInput[l].SliderAndInput[m];
- 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;
- }
- Dictionary<string, int> blendIdDic = this.blendIdDictionary[maid.status.guid];
- 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.GetBlendIdx(maid.body0.Face, blendIdDic, name)];
- List<Action<float>> onChangeValue = sliderAndInput.onChangeValue;
- sliderAndInput.onChangeValue = new List<Action<float>>();
- sliderAndInput.value = this.GetValue(maid, name);
- sliderAndInput.onChangeValue = onChangeValue;
- 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;
- }
- Dictionary<string, int> blendIdDic = this.blendIdDictionary[maid.status.guid];
- this.selectData.BlendArray(maid)[this.GetBlendIdx(maid.body0.Face, blendIdDic, name)] = val;
- }
- private float GetValue(Maid maid, string name)
- {
- if (maid == null || maid.body0 == null || maid.body0.Face == null)
- {
- return 0f;
- }
- Dictionary<string, int> blendIdDic = this.blendIdDictionary[maid.status.guid];
- return this.selectData.BlendArray(maid)[this.GetBlendIdx(maid.body0.Face, blendIdDic, name)];
- }
- private int GetBlendIdx(TBodySkin face, Dictionary<string, int> blendIdDic, string name)
- {
- if (120 <= face.PartsVersion && name.IndexOf("eyeclose") == 0)
- {
- string text = name;
- if (text == "eyeclose")
- {
- text += "1";
- }
- TMorph.GP01FB_FACE_TYPE faceTypeGP01FB = face.morph.GetFaceTypeGP01FB();
- text += TMorph.crcFaceTypesStr[(int)faceTypeGP01FB];
- if (blendIdDic.ContainsKey(text))
- {
- name = text;
- }
- }
- return blendIdDic[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, Dictionary<string, int>> blendIdDictionary = new Dictionary<string, Dictionary<string, int>>();
- private Dictionary<string, Dictionary<string, float[]>> backupBlendSets = new Dictionary<string, Dictionary<string, float[]>>();
- private PhotoFaceData selectData;
- }
|