void SetTreeForward(Tree tree, BTAction action) { try { int index = (int)System.Enum.Parse(tree.LibraryActions, action.Name); MethodInfo start = action.GetType().GetMethod("Start", BindingFlags.NonPublic | BindingFlags.Instance); MethodInfo init = action.GetType().GetMethod("Init", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(Tree) }, null); MethodInfo Tick = action.GetType().GetMethod("Tick", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(Tree) }, null); MethodInfo Reset = action.GetType().GetMethod("Reset", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(Tree) }, null); if (start != null) { start.Invoke(action, null); } if (init != null) { tree.SetInitForward(index, Delegate.CreateDelegate(typeof(TickForward), action, init) as TickForward); } if (Tick != null) { tree.SetTickForward(index, Delegate.CreateDelegate(typeof(TickForward), action, Tick) as TickForward); } if (Reset != null) { tree.SetResetForward(index, Delegate.CreateDelegate(typeof(ResetForward), action, Reset) as ResetForward); } } catch (Exception) { //Debug.LogWarning(e); } }
static void InitData(string btPath, BTAction action, XmlElement e) { if (!s_Fields.ContainsKey(action.Name)) { s_Fields.Add(action.Name, new List <FieldInfo>()); } if (action != null && e != null) { //foreach (FieldInfo field in action.GetType().GetFields()) //{ // foreach (object attribute in field.GetCustomAttributes(true)) // { // if (typeof(BehaveAttribute).IsInstanceOfType(attribute)) // { // string error = SetValue(field, action, e); // if (error != "") // { // //Debug.LogError("Action : " + action.Name + "["+ error +"]"); // } // continue; // } // } //} //Profiler.BeginSample("Resolver"); object[] members = action.GetType().GetCustomAttributes(true); for (int i = 0; i < members.Length; i++) { if (typeof(BehaveAction).IsInstanceOfType(members[i])) { BehaveAction behave = members[i] as BehaveAction; XmlNodeList nodes = e.GetElementsByTagName("Data"); for (int j = 0; j < nodes.Count; j++) { XmlElement d = nodes[j] as XmlElement; if (behave.dataType != null) { object obj = System.Activator.CreateInstance(behave.dataType); string dataName = XmlUtil.GetAttributeString(d, "Name"); FieldInfo[] fields = obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public); for (int k = 0; k < fields.Length; k++) { FieldInfo field = fields[k]; object[] attrs = field.GetCustomAttributes(true); for (int n = 0; n < attrs.Length; n++) { if (typeof(BehaveAttribute).IsInstanceOfType(attrs[n])) { if (s_Fields[action.Name].Find(ret => ret.Name == field.Name) == null) { s_Fields[action.Name].Add(field); } string error = SetValue(field, obj, d); if (error != "") { Debug.LogError(btPath + "-" + "Action:" + action.Name + "-" + "Data : " + dataName + "-" + "[" + error + "]"); } continue; } } } action.AddData(dataName, obj); } } } } //Profiler.EndSample(); } }