AMEventKey.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using UnityEngine;
  6. [Serializable]
  7. public class AMEventKey : AMKey
  8. {
  9. public MethodInfo methodInfo
  10. {
  11. get
  12. {
  13. if (this.component == null)
  14. {
  15. return null;
  16. }
  17. if (this.cachedMethodInfo != null)
  18. {
  19. return this.cachedMethodInfo;
  20. }
  21. if (this.methodName == null)
  22. {
  23. return null;
  24. }
  25. try
  26. {
  27. this.cachedMethodInfo = this.component.GetType().GetMethod(this.methodName);
  28. }
  29. catch
  30. {
  31. this.cachedMethodInfo = null;
  32. Debug.LogError("MonoBehaviorでなければいけません。");
  33. }
  34. return this.cachedMethodInfo;
  35. }
  36. set
  37. {
  38. if (value != null)
  39. {
  40. this.methodName = value.Name;
  41. }
  42. else
  43. {
  44. this.methodName = null;
  45. }
  46. this.cachedMethodInfo = value;
  47. }
  48. }
  49. public bool setMethodInfo(Component component, MethodInfo methodInfo, ParameterInfo[] cachedParameterInfos)
  50. {
  51. if (this.methodInfo != methodInfo || this.component != component)
  52. {
  53. this.component = component;
  54. this.methodInfo = methodInfo;
  55. this.destroyParameters();
  56. this.parameters = new List<AMEventParameter>();
  57. for (int i = 0; i < cachedParameterInfos.Length; i++)
  58. {
  59. AMEventParameter ameventParameter = ScriptableObject.CreateInstance<AMEventParameter>();
  60. ameventParameter.setValueType(cachedParameterInfos[i].ParameterType);
  61. this.parameters.Add(ameventParameter);
  62. }
  63. return true;
  64. }
  65. return false;
  66. }
  67. public bool setUseSendMessage(bool useSendMessage)
  68. {
  69. if (this.useSendMessage != useSendMessage)
  70. {
  71. this.useSendMessage = useSendMessage;
  72. return true;
  73. }
  74. return false;
  75. }
  76. public void destroyParameters()
  77. {
  78. if (this.parameters == null)
  79. {
  80. return;
  81. }
  82. foreach (AMEventParameter ameventParameter in this.parameters)
  83. {
  84. ameventParameter.destroy();
  85. }
  86. }
  87. public override void destroy()
  88. {
  89. this.destroyParameters();
  90. base.destroy();
  91. }
  92. public List<GameObject> getDependencies()
  93. {
  94. List<GameObject> list = new List<GameObject>();
  95. foreach (AMEventParameter ameventParameter in this.parameters)
  96. {
  97. list = list.Union(ameventParameter.getDependencies()).ToList<GameObject>();
  98. }
  99. return list;
  100. }
  101. public bool updateDependencies(List<GameObject> newReferences, List<GameObject> oldReferences, bool didUpdateObj, GameObject obj)
  102. {
  103. if (didUpdateObj && this.component)
  104. {
  105. string name = this.component.GetType().Name;
  106. this.component = obj.GetComponent(name);
  107. if (!this.component)
  108. {
  109. Debug.LogError(string.Concat(new string[]
  110. {
  111. "Animator: Component '",
  112. name,
  113. "' not found on new reference for GameObject '",
  114. obj.name,
  115. "'. Some event track data may be lost."
  116. }));
  117. }
  118. this.cachedMethodInfo = null;
  119. }
  120. bool flag = false;
  121. foreach (AMEventParameter ameventParameter in this.parameters)
  122. {
  123. if (ameventParameter.updateDependencies(newReferences, oldReferences) && !flag)
  124. {
  125. flag = true;
  126. }
  127. }
  128. return flag;
  129. }
  130. public override AMKey CreateClone()
  131. {
  132. AMEventKey ameventKey = ScriptableObject.CreateInstance<AMEventKey>();
  133. ameventKey.frame = this.frame;
  134. ameventKey.component = this.component;
  135. ameventKey.useSendMessage = this.useSendMessage;
  136. ameventKey.methodName = this.methodName;
  137. ameventKey.methodInfo = this.methodInfo;
  138. foreach (AMEventParameter ameventParameter in this.parameters)
  139. {
  140. ameventKey.parameters.Add(ameventParameter.CreateClone());
  141. }
  142. return ameventKey;
  143. }
  144. public override void CreateFromStringData(string data_text)
  145. {
  146. string[] array = data_text.Split(new char[]
  147. {
  148. ':'
  149. });
  150. if (array.Length == 0 || array[0] != "Event")
  151. {
  152. return;
  153. }
  154. NDebug.Assert(this.obj != null, "AMEventKey::CreateFromStringData\nobjがnullです");
  155. int num = 1;
  156. this.frame = int.Parse(array[num++]);
  157. this.useSendMessage = bool.Parse(array[num++]);
  158. string str = array[num++];
  159. this.methodName = array[num++];
  160. this.component = this.obj.GetComponent<DanceMain>();
  161. NDebug.Assert(this.component != null, "AMEventKey::CreateFromStringData\n" + str + "が見つかりませんでした");
  162. this.methodInfo = this.component.GetType().GetMethod(this.methodName);
  163. this.parameters.Clear();
  164. int num2 = int.Parse(array[num++]);
  165. this.parameters = new List<AMEventParameter>();
  166. for (int i = 0; i < num2; i++)
  167. {
  168. this.parameters.Add(AMEventParameter.CreateFromStringData(array[num++]));
  169. }
  170. }
  171. public override string ToStringData()
  172. {
  173. List<string> list = new List<string>();
  174. list.Add("Event");
  175. list.Add(this.frame.ToString());
  176. list.Add(this.useSendMessage.ToString());
  177. list.Add(this.component.name);
  178. list.Add(this.methodName.ToString());
  179. list.Add(this.parameters.Count.ToString());
  180. for (int i = 0; i < this.parameters.Count; i++)
  181. {
  182. list.Add(this.parameters[i].ToStringData());
  183. }
  184. string text = list[0];
  185. for (int j = 1; j < list.Count; j++)
  186. {
  187. text = text + ":" + list[j];
  188. }
  189. return text;
  190. }
  191. public GameObject obj;
  192. public Component component;
  193. public bool useSendMessage = true;
  194. public List<AMEventParameter> parameters = new List<AMEventParameter>();
  195. public string methodName;
  196. private MethodInfo cachedMethodInfo;
  197. }