123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- 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<string, float>(this.SetPropValueBoneMorph));
- this.chara.body0.onVertexMorphApply.Remove(new Action<string, float>(this.SetPropValueVerTex));
- }
- this.chara = chara;
- this.chara.body0.onBoneMorphApply.Add(new Action<string, float>(this.SetPropValueBoneMorph), false);
- this.chara.body0.onVertexMorphApply.Add(new Action<string, float>(this.SetPropValueVerTex), false);
- this.InitPropValue(this.maidPropStatus.centerMpnList);
- this.InitPropValue(this.maidPropStatus.startRadiusMpnList);
- this.InitPropValue(this.maidPropStatus.endRadiusMpnList);
- }
- private void InitPropValue(List<MPN> 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> 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<NativeMaidPropColliderStatus>(writer);
- }
- public override void Load(StreamReader reader, Transform parent_search_root)
- {
- base.Load<NativeMaidPropColliderStatus>(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<MPN, float> PropValueDic = new Dictionary<MPN, float>();
- }
- }
|