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(this.OnChangetPropInputValue)); } } public void SetFaceWindow(FaceWindow faceWindow) { this.faceWindow = faceWindow; } public void OnDestroy() { } public void OnMaidAddEvent(Maid maid, bool isDeserializeLoad, Dictionary storeData) { if (maid == null || maid.boMAN) { return; } this.SetPhotoFaceData(PhotoFaceData.Get(long.Parse(storeData["id"]))); this.CreateBackupData(maid); List blendDatas = maid.body0.Face.morph.BlendDatas; Dictionary dictionary = new Dictionary(); 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()); } 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]; if (maid.IsCrcBody || !(sliderAndInputSet.Name == "tanga")) { 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]; if (maid.IsCrcBody || !(sliderAndInputSet2.Name == "tanga")) { 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 dictionary = new Dictionary(); foreach (KeyValuePair 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 dictionary = this.backupBlendSets[guid]; foreach (KeyValuePair 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 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; if (maid.IsCrcBody || !(name == "tanga")) { 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> onChangeValue = sliderAndInput.onChangeValue; sliderAndInput.onChangeValue = new List>(); 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 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 blendIdDic = this.blendIdDictionary[maid.status.guid]; return this.selectData.BlendArray(maid)[this.GetBlendIdx(maid.body0.Face, blendIdDic, name)]; } private int GetBlendIdx(TBodySkin face, Dictionary 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> blendIdDictionary = new Dictionary>(); private Dictionary> backupBlendSets = new Dictionary>(); private PhotoFaceData selectData; }