using System; using System.Collections.Generic; using System.IO; using UnityEngine; namespace kt.Physics { public class NativeMaidPropCollider : NativeCapsuleCollider { public Maid chara { get; private set; } public NativeMaidPropColliderStatus maidPropStatus { get { return this.MaidPropStatus; } } public override NativeCapsuleColliderStatus capsuleStatus { get { return this.MaidPropStatus; } } public override NativeColliderStatus status { get { return this.MaidPropStatus; } protected set { this.MaidPropStatus = (value as NativeMaidPropColliderStatus); } } public override Vector3 worldCenter { get { float maxPropValue = this.GetMaxPropValue(this.maidPropStatus.centerMpnList); return base.transform.TransformPoint(Vector3.Lerp(this.maidPropStatus.center, this.maidPropStatus.centerRateMax, maxPropValue)); } } public float startRadiusRate { get { return this.GetMaxPropValue(this.maidPropStatus.startRadiusMpnList); } } public override float startRadius { get { return Mathf.Lerp(this.maidPropStatus.startRadius, this.maidPropStatus.maxStartRadius, this.startRadiusRate) * base.GetLossyScale(); } } public float endRadiusRate { get { return this.GetMaxPropValue(this.maidPropStatus.endRadiusMpnList); } } public override float endRadius { get { return Mathf.Lerp(this.maidPropStatus.endRadius, this.maidPropStatus.maxEndRadius, this.endRadiusRate) * base.GetLossyScale(); } } public void SetChara(Maid chara) { if (!chara) { return; } if (this.chara) { this.chara.body0.onBoneMorphApply.Remove(new Action(this.SetPropValueBoneMorph)); this.chara.body0.onVertexMorphApply.Remove(new Action(this.SetPropValueVerTex)); } this.chara = chara; this.chara.body0.onBoneMorphApply.Add(new Action(this.SetPropValueBoneMorph), false); this.chara.body0.onVertexMorphApply.Add(new Action(this.SetPropValueVerTex), false); this.InitPropValue(this.maidPropStatus.centerMpnList); this.InitPropValue(this.maidPropStatus.startRadiusMpnList); this.InitPropValue(this.maidPropStatus.endRadiusMpnList); } private void InitPropValue(List mpn_list) { foreach (MPN mpn in mpn_list) { MaidProp prop = this.chara.GetProp(mpn); if (prop != null) { this.PropValueDic[mpn] = Mathf.InverseLerp((float)prop.min, (float)prop.max, (float)prop.value); } } } private void SetPropValue(MPN mpn, float val) { if (!this.PropValueDic.ContainsKey(mpn)) { return; } MaidProp prop = this.chara.GetProp(mpn); if (prop != null) { this.PropValueDic[mpn] = Mathf.InverseLerp((float)prop.min, (float)prop.max, (float)prop.value); } } private void SetPropValueBoneMorph(string tag, float val) { foreach (MPN mpn in this.PropValueDic.Keys) { if (tag == mpn.ToString()) { this.SetPropValue(mpn, val); break; } } } private void SetPropValueVerTex(string tag, float val) { foreach (MPN mpn in this.PropValueDic.Keys) { if (tag == mpn.ToString().ToLower()) { this.SetPropValue(mpn, val); break; } } } private float GetMaxPropValue(List mpn_list) { float num = 0f; foreach (MPN key in mpn_list) { if (this.PropValueDic.ContainsKey(key)) { num = Mathf.Max(num, this.PropValueDic[key]); } } return num; } public override void Save(StreamWriter writer) { base.Save(writer); } public override void Load(StreamReader reader, Transform parent_search_root) { base.Load(reader, parent_search_root); } public override void SetStatus(NativeColliderStatus status, Transform parent_search_root = null) { base.SetStatus(status, parent_search_root); this.PropValueDic.Clear(); this.InitPropValue(this.maidPropStatus.centerMpnList); this.InitPropValue(this.maidPropStatus.startRadiusMpnList); this.InitPropValue(this.maidPropStatus.endRadiusMpnList); } [SerializeField] private NativeMaidPropColliderStatus MaidPropStatus = new NativeMaidPropColliderStatus(); private Dictionary PropValueDic = new Dictionary(); } }