MegaMorphBase.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. public class MegaMorphBase : MegaModifier
  4. {
  5. public List<MegaMorphChan> chanBank = new List<MegaMorphChan>();
  6. public MegaMorphAnimType animtype = MegaMorphAnimType.Bezier;
  7. public override void PostCopy(MegaModifier src)
  8. {
  9. MegaMorphBase mor = (MegaMorphBase)src;
  10. chanBank = new List<MegaMorphChan>();
  11. for ( int c = 0; c < mor.chanBank.Count; c++ )
  12. {
  13. MegaMorphChan chan = new MegaMorphChan();
  14. MegaMorphChan.Copy(mor.chanBank[c], chan);
  15. chanBank.Add(chan);
  16. }
  17. }
  18. public string[] GetChannelNames()
  19. {
  20. string[] names = new string[chanBank.Count];
  21. for ( int i = 0; i < chanBank.Count; i++ )
  22. names[i] = chanBank[i].mName;
  23. return names;
  24. }
  25. public MegaMorphChan GetChannel(string name)
  26. {
  27. for ( int i = 0; i < chanBank.Count; i++ )
  28. {
  29. if ( chanBank[i].mName == name )
  30. return chanBank[i];
  31. }
  32. return null;
  33. }
  34. public int NumChannels()
  35. {
  36. return chanBank.Count;
  37. }
  38. public void SetPercent(int i, float percent)
  39. {
  40. if ( i >= 0 && i < chanBank.Count )
  41. chanBank[i].Percent = percent;
  42. }
  43. public void SetPercentLim(int i, float alpha)
  44. {
  45. if ( i >= 0 && i < chanBank.Count )
  46. {
  47. if ( chanBank[i].mUseLimit )
  48. chanBank[i].Percent = chanBank[i].mSpinmin + ((chanBank[i].mSpinmax - chanBank[i].mSpinmin) * alpha);
  49. else
  50. chanBank[i].Percent = alpha * 100.0f;
  51. }
  52. }
  53. public void SetPercent(int i, float percent, float speed)
  54. {
  55. chanBank[i].SetTarget(percent, speed);
  56. }
  57. public void ResetPercent(int[] channels, float speed)
  58. {
  59. for ( int i = 0; i < channels.Length; i++ )
  60. {
  61. int chan = channels[i];
  62. chanBank[chan].SetTarget(0.0f, speed);
  63. }
  64. }
  65. public float GetPercent(int i)
  66. {
  67. if ( i >= 0 && i < chanBank.Count )
  68. return chanBank[i].Percent;
  69. return 0.0f;
  70. }
  71. public void SetAnim(float t)
  72. {
  73. if ( animtype == MegaMorphAnimType.Bezier )
  74. {
  75. for ( int i = 0; i < chanBank.Count; i++ )
  76. {
  77. if ( chanBank[i].control != null )
  78. {
  79. if ( chanBank[i].control.Times != null )
  80. {
  81. if ( chanBank[i].control.Times.Length > 0 )
  82. chanBank[i].Percent = chanBank[i].control.GetFloat(t); //, 0.0f, 100.0f);
  83. }
  84. }
  85. }
  86. }
  87. else
  88. {
  89. for ( int i = 0; i < chanBank.Count; i++ )
  90. {
  91. if ( chanBank[i].control != null )
  92. {
  93. if ( chanBank[i].control.Times != null )
  94. {
  95. if ( chanBank[i].control.Times.Length > 0 )
  96. chanBank[i].Percent = chanBank[i].control.GetHermiteFloat(t); //, 0.0f, 100.0f);
  97. }
  98. }
  99. }
  100. }
  101. }
  102. [System.Serializable]
  103. public class MegaMorphBlend
  104. {
  105. public float t;
  106. public float weight;
  107. }
  108. public int numblends;
  109. public List<MegaMorphBlend> blends; // = new List<MegaMorphBlend>();
  110. public void SetAnimBlend(float t, float weight)
  111. {
  112. if ( blends == null )
  113. {
  114. blends = new List<MegaMorphBlend>();
  115. for ( int i = 0; i < 4; i++ )
  116. {
  117. blends.Add(new MegaMorphBlend());
  118. }
  119. }
  120. blends[numblends].t = t;
  121. blends[numblends].weight = weight;
  122. numblends++;
  123. }
  124. public void ClearBlends()
  125. {
  126. numblends = 0;
  127. }
  128. public void SetChannels()
  129. {
  130. float tweight = 0.0f;
  131. for ( int i = 0; i < numblends; i++ )
  132. {
  133. tweight += blends[i].weight;
  134. }
  135. for ( int b = 0; b < numblends; b++ )
  136. {
  137. for ( int c = 0; c < chanBank.Count; c++ )
  138. {
  139. if ( animtype == MegaMorphAnimType.Bezier )
  140. {
  141. if ( chanBank[c].control != null )
  142. {
  143. if ( chanBank[c].control.Times != null )
  144. {
  145. if ( chanBank[c].control.Times.Length > 0 )
  146. {
  147. if ( b == 0 )
  148. chanBank[c].Percent = chanBank[c].control.GetFloat(blends[b].t) * (blends[b].weight / tweight); //, 0.0f, 100.0f);
  149. else
  150. chanBank[c].Percent += chanBank[c].control.GetFloat(blends[b].t) * (blends[b].weight / tweight); //, 0.0f, 100.0f);
  151. }
  152. }
  153. }
  154. }
  155. else
  156. {
  157. if ( chanBank[c].control != null )
  158. {
  159. if ( chanBank[c].control.Times != null )
  160. {
  161. if ( chanBank[c].control.Times.Length > 0 )
  162. {
  163. if ( b == 0 )
  164. chanBank[c].Percent = chanBank[c].control.GetHermiteFloat(blends[b].t) * (blends[b].weight / tweight); //, 0.0f, 100.0f);
  165. else
  166. chanBank[c].Percent += chanBank[c].control.GetHermiteFloat(blends[b].t) * (blends[b].weight / tweight); //, 0.0f, 100.0f);
  167. }
  168. }
  169. }
  170. }
  171. }
  172. }
  173. }
  174. }