NativeMaidPropCollider.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. namespace kt.Physics
  6. {
  7. public class NativeMaidPropCollider : NativeCapsuleCollider
  8. {
  9. public Maid chara { get; private set; }
  10. public NativeMaidPropColliderStatus maidPropStatus
  11. {
  12. get
  13. {
  14. return this.MaidPropStatus;
  15. }
  16. }
  17. public override NativeCapsuleColliderStatus capsuleStatus
  18. {
  19. get
  20. {
  21. return this.MaidPropStatus;
  22. }
  23. }
  24. public override NativeColliderStatus status
  25. {
  26. get
  27. {
  28. return this.MaidPropStatus;
  29. }
  30. protected set
  31. {
  32. this.MaidPropStatus = (value as NativeMaidPropColliderStatus);
  33. }
  34. }
  35. public override Vector3 worldCenter
  36. {
  37. get
  38. {
  39. float maxPropValue = this.GetMaxPropValue(this.maidPropStatus.centerMpnList);
  40. return base.transform.TransformPoint(Vector3.Lerp(this.maidPropStatus.center, this.maidPropStatus.centerRateMax, maxPropValue));
  41. }
  42. }
  43. public float startRadiusRate
  44. {
  45. get
  46. {
  47. return this.GetMaxPropValue(this.maidPropStatus.startRadiusMpnList);
  48. }
  49. }
  50. public override float startRadius
  51. {
  52. get
  53. {
  54. return Mathf.Lerp(this.maidPropStatus.startRadius, this.maidPropStatus.maxStartRadius, this.startRadiusRate) * base.GetLossyScale();
  55. }
  56. }
  57. public float endRadiusRate
  58. {
  59. get
  60. {
  61. return this.GetMaxPropValue(this.maidPropStatus.endRadiusMpnList);
  62. }
  63. }
  64. public override float endRadius
  65. {
  66. get
  67. {
  68. return Mathf.Lerp(this.maidPropStatus.endRadius, this.maidPropStatus.maxEndRadius, this.endRadiusRate) * base.GetLossyScale();
  69. }
  70. }
  71. public void SetChara(Maid chara)
  72. {
  73. if (!chara)
  74. {
  75. return;
  76. }
  77. if (this.chara)
  78. {
  79. this.chara.body0.onBoneMorphApply.Remove(new Action<string, float>(this.SetPropValueBoneMorph));
  80. this.chara.body0.onVertexMorphApply.Remove(new Action<string, float>(this.SetPropValueVerTex));
  81. }
  82. this.chara = chara;
  83. this.chara.body0.onBoneMorphApply.Add(new Action<string, float>(this.SetPropValueBoneMorph), false);
  84. this.chara.body0.onVertexMorphApply.Add(new Action<string, float>(this.SetPropValueVerTex), false);
  85. this.InitPropValue(this.maidPropStatus.centerMpnList);
  86. this.InitPropValue(this.maidPropStatus.startRadiusMpnList);
  87. this.InitPropValue(this.maidPropStatus.endRadiusMpnList);
  88. }
  89. private void InitPropValue(List<MPN> mpn_list)
  90. {
  91. foreach (MPN mpn in mpn_list)
  92. {
  93. MaidProp prop = this.chara.GetProp(mpn);
  94. if (prop != null)
  95. {
  96. this.PropValueDic[mpn] = Mathf.InverseLerp((float)prop.min, (float)prop.max, (float)prop.value);
  97. }
  98. }
  99. }
  100. private void SetPropValue(MPN mpn, float val)
  101. {
  102. if (!this.PropValueDic.ContainsKey(mpn))
  103. {
  104. return;
  105. }
  106. MaidProp prop = this.chara.GetProp(mpn);
  107. if (prop != null)
  108. {
  109. this.PropValueDic[mpn] = Mathf.InverseLerp((float)prop.min, (float)prop.max, (float)prop.value);
  110. }
  111. }
  112. private void SetPropValueBoneMorph(string tag, float val)
  113. {
  114. foreach (MPN mpn in this.PropValueDic.Keys)
  115. {
  116. if (tag == mpn.ToString())
  117. {
  118. this.SetPropValue(mpn, val);
  119. break;
  120. }
  121. }
  122. }
  123. private void SetPropValueVerTex(string tag, float val)
  124. {
  125. foreach (MPN mpn in this.PropValueDic.Keys)
  126. {
  127. if (tag == mpn.ToString().ToLower())
  128. {
  129. this.SetPropValue(mpn, val);
  130. break;
  131. }
  132. }
  133. }
  134. private float GetMaxPropValue(List<MPN> mpn_list)
  135. {
  136. float num = 0f;
  137. foreach (MPN key in mpn_list)
  138. {
  139. if (this.PropValueDic.ContainsKey(key))
  140. {
  141. num = Mathf.Max(num, this.PropValueDic[key]);
  142. }
  143. }
  144. return num;
  145. }
  146. public override void Save(StreamWriter writer)
  147. {
  148. base.Save<NativeMaidPropColliderStatus>(writer);
  149. }
  150. public override void Load(StreamReader reader, Transform parent_search_root)
  151. {
  152. base.Load<NativeMaidPropColliderStatus>(reader, parent_search_root);
  153. }
  154. public override void SetStatus(NativeColliderStatus status, Transform parent_search_root = null)
  155. {
  156. base.SetStatus(status, parent_search_root);
  157. this.PropValueDic.Clear();
  158. this.InitPropValue(this.maidPropStatus.centerMpnList);
  159. this.InitPropValue(this.maidPropStatus.startRadiusMpnList);
  160. this.InitPropValue(this.maidPropStatus.endRadiusMpnList);
  161. }
  162. [SerializeField]
  163. private NativeMaidPropColliderStatus MaidPropStatus = new NativeMaidPropColliderStatus();
  164. private Dictionary<MPN, float> PropValueDic = new Dictionary<MPN, float>();
  165. }
  166. }