123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using UnityEngine;
- [Serializable]
- public class AMEventKey : AMKey
- {
- public MethodInfo methodInfo
- {
- get
- {
- if (this.component == null)
- {
- return null;
- }
- if (this.cachedMethodInfo != null)
- {
- return this.cachedMethodInfo;
- }
- if (this.methodName == null)
- {
- return null;
- }
- try
- {
- this.cachedMethodInfo = this.component.GetType().GetMethod(this.methodName);
- }
- catch
- {
- this.cachedMethodInfo = null;
- Debug.LogError("MonoBehaviorでなければいけません。");
- }
- return this.cachedMethodInfo;
- }
- set
- {
- if (value != null)
- {
- this.methodName = value.Name;
- }
- else
- {
- this.methodName = null;
- }
- this.cachedMethodInfo = value;
- }
- }
- public bool setMethodInfo(Component component, MethodInfo methodInfo, ParameterInfo[] cachedParameterInfos)
- {
- if (this.methodInfo != methodInfo || this.component != component)
- {
- this.component = component;
- this.methodInfo = methodInfo;
- this.destroyParameters();
- this.parameters = new List<AMEventParameter>();
- for (int i = 0; i < cachedParameterInfos.Length; i++)
- {
- AMEventParameter ameventParameter = ScriptableObject.CreateInstance<AMEventParameter>();
- ameventParameter.setValueType(cachedParameterInfos[i].ParameterType);
- this.parameters.Add(ameventParameter);
- }
- return true;
- }
- return false;
- }
- public bool setUseSendMessage(bool useSendMessage)
- {
- if (this.useSendMessage != useSendMessage)
- {
- this.useSendMessage = useSendMessage;
- return true;
- }
- return false;
- }
- public void destroyParameters()
- {
- if (this.parameters == null)
- {
- return;
- }
- foreach (AMEventParameter ameventParameter in this.parameters)
- {
- ameventParameter.destroy();
- }
- }
- public override void destroy()
- {
- this.destroyParameters();
- base.destroy();
- }
- public List<GameObject> getDependencies()
- {
- List<GameObject> list = new List<GameObject>();
- foreach (AMEventParameter ameventParameter in this.parameters)
- {
- list = list.Union(ameventParameter.getDependencies()).ToList<GameObject>();
- }
- return list;
- }
- public bool updateDependencies(List<GameObject> newReferences, List<GameObject> oldReferences, bool didUpdateObj, GameObject obj)
- {
- if (didUpdateObj && this.component)
- {
- string name = this.component.GetType().Name;
- this.component = obj.GetComponent(name);
- if (!this.component)
- {
- Debug.LogError(string.Concat(new string[]
- {
- "Animator: Component '",
- name,
- "' not found on new reference for GameObject '",
- obj.name,
- "'. Some event track data may be lost."
- }));
- }
- this.cachedMethodInfo = null;
- }
- bool flag = false;
- foreach (AMEventParameter ameventParameter in this.parameters)
- {
- if (ameventParameter.updateDependencies(newReferences, oldReferences) && !flag)
- {
- flag = true;
- }
- }
- return flag;
- }
- public override AMKey CreateClone()
- {
- AMEventKey ameventKey = ScriptableObject.CreateInstance<AMEventKey>();
- ameventKey.frame = this.frame;
- ameventKey.component = this.component;
- ameventKey.useSendMessage = this.useSendMessage;
- ameventKey.methodName = this.methodName;
- ameventKey.methodInfo = this.methodInfo;
- foreach (AMEventParameter ameventParameter in this.parameters)
- {
- ameventKey.parameters.Add(ameventParameter.CreateClone());
- }
- return ameventKey;
- }
- public override void CreateFromStringData(string data_text)
- {
- string[] array = data_text.Split(new char[]
- {
- ':'
- });
- if (array.Length == 0 || array[0] != "Event")
- {
- return;
- }
- NDebug.Assert(this.obj != null, "AMEventKey::CreateFromStringData\nobjがnullです");
- int num = 1;
- this.frame = int.Parse(array[num++]);
- this.useSendMessage = bool.Parse(array[num++]);
- string str = array[num++];
- this.methodName = array[num++];
- this.component = this.obj.GetComponent<DanceMain>();
- NDebug.Assert(this.component != null, "AMEventKey::CreateFromStringData\n" + str + "が見つかりませんでした");
- this.methodInfo = this.component.GetType().GetMethod(this.methodName);
- this.parameters.Clear();
- int num2 = int.Parse(array[num++]);
- this.parameters = new List<AMEventParameter>();
- for (int i = 0; i < num2; i++)
- {
- this.parameters.Add(AMEventParameter.CreateFromStringData(array[num++]));
- }
- }
- public override string ToStringData()
- {
- List<string> list = new List<string>();
- list.Add("Event");
- list.Add(this.frame.ToString());
- list.Add(this.useSendMessage.ToString());
- list.Add(this.component.name);
- list.Add(this.methodName.ToString());
- list.Add(this.parameters.Count.ToString());
- for (int i = 0; i < this.parameters.Count; i++)
- {
- list.Add(this.parameters[i].ToStringData());
- }
- string text = list[0];
- for (int j = 1; j < list.Count; j++)
- {
- text = text + ":" + list[j];
- }
- return text;
- }
- public GameObject obj;
- public Component component;
- public bool useSendMessage = true;
- public List<AMEventParameter> parameters = new List<AMEventParameter>();
- public string methodName;
- private MethodInfo cachedMethodInfo;
- }
|