public void LoadNode(Task task, BehaviorSource behaviorSource, Vector2 offset, ref int id) { mTask = task; mTask.Owner = (behaviorSource.Owner as Behavior); mTask.ID = id++; mTask.NodeData = new NodeData(); mTask.NodeData.Offset = offset; mTask.NodeData.NodeDesigner = this; LoadTaskIcon(); Init(); mTask.FriendlyName = taskName; RequiredComponentAttribute[] array; if (mTask.Owner != null && (array = (mTask.GetType().GetCustomAttributes(typeof(RequiredComponentAttribute), true) as RequiredComponentAttribute[])).Length > 0) { Type componentType = array[0].ComponentType; if (typeof(Component).IsAssignableFrom(componentType) && mTask.Owner.gameObject.GetComponent(componentType) == null) { mTask.Owner.gameObject.AddComponent(componentType); } } List <Type> baseClasses = FieldInspector.GetBaseClasses(mTask.GetType()); BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; for (int i = baseClasses.Count - 1; i > -1; i--) { FieldInfo[] fields = baseClasses[i].GetFields(bindingAttr); for (int j = 0; j < fields.Length; j++) { if (typeof(SharedVariable).IsAssignableFrom(fields[j].FieldType) && !fields[j].FieldType.IsAbstract) { SharedVariable sharedVariable = fields[j].GetValue(mTask) as SharedVariable; if (sharedVariable == null) { sharedVariable = (Activator.CreateInstance(fields[j].FieldType) as SharedVariable); } if (TaskUtility.HasAttribute(fields[j], typeof(RequiredFieldAttribute)) || TaskUtility.HasAttribute(fields[j], typeof(SharedRequiredAttribute))) { sharedVariable.IsShared = true; } fields[j].SetValue(mTask, sharedVariable); } } } }
public static object DrawFields(Task task, object obj, GUIContent guiContent) { if (obj == null) { return(null); } List <Type> baseClasses = FieldInspector.GetBaseClasses(obj.GetType()); BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; for (int i = baseClasses.Count - 1; i > -1; i--) { FieldInfo[] fields = baseClasses[i].GetFields(bindingAttr); for (int j = 0; j < fields.Length; j++) { if (!BehaviorDesignerUtility.HasAttribute(fields[j], typeof(NonSerializedAttribute)) && !BehaviorDesignerUtility.HasAttribute(fields[j], typeof(HideInInspector)) && ((!fields[j].IsPrivate && !fields[j].IsFamily) || BehaviorDesignerUtility.HasAttribute(fields[j], typeof(SerializeField))) && (!(obj is ParentTask) || !fields[j].Name.Equals("children"))) { if (guiContent == null) { string name = fields[j].Name; BehaviorDesigner.Runtime.Tasks.TooltipAttribute[] array; if ((array = (fields[j].GetCustomAttributes(typeof(BehaviorDesigner.Runtime.Tasks.TooltipAttribute), false) as BehaviorDesigner.Runtime.Tasks.TooltipAttribute[])).Length > 0) { guiContent = new GUIContent(BehaviorDesignerUtility.SplitCamelCase(name), array[0].Tooltip); } else { guiContent = new GUIContent(BehaviorDesignerUtility.SplitCamelCase(name)); } } EditorGUI.BeginChangeCheck(); object value = FieldInspector.DrawField(task, guiContent, fields[j], fields[j].GetValue(obj)); if (EditorGUI.EndChangeCheck()) { fields[j].SetValue(obj, value); GUI.changed = true; } guiContent = null; } } } return(obj); }
public void LoadTask(Task task, Behavior owner, ref int id) { if (task == null) { return; } mTask = task; mTask.Owner = owner; mTask.ID = id++; mTask.NodeData.NodeDesigner = this; mTask.NodeData.InitWatchedFields(mTask); if (!mTask.NodeData.FriendlyName.Equals(string.Empty)) { mTask.FriendlyName = mTask.NodeData.FriendlyName; mTask.NodeData.FriendlyName = string.Empty; } LoadTaskIcon(); Init(); RequiredComponentAttribute[] array; if (mTask.Owner != null && (array = (mTask.GetType().GetCustomAttributes(typeof(RequiredComponentAttribute), true) as RequiredComponentAttribute[])).Length > 0) { Type componentType = array[0].ComponentType; if (typeof(Component).IsAssignableFrom(componentType) && mTask.Owner.gameObject.GetComponent(componentType) == null) { mTask.Owner.gameObject.AddComponent(componentType); } } List <Type> baseClasses = FieldInspector.GetBaseClasses(mTask.GetType()); BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; for (int i = baseClasses.Count - 1; i > -1; i--) { FieldInfo[] fields = baseClasses[i].GetFields(bindingAttr); for (int j = 0; j < fields.Length; j++) { if (typeof(SharedVariable).IsAssignableFrom(fields[j].FieldType) && !fields[j].FieldType.IsAbstract) { SharedVariable sharedVariable = fields[j].GetValue(mTask) as SharedVariable; if (sharedVariable == null) { sharedVariable = (Activator.CreateInstance(fields[j].FieldType) as SharedVariable); } if (TaskUtility.HasAttribute(fields[j], typeof(RequiredFieldAttribute)) || TaskUtility.HasAttribute(fields[j], typeof(SharedRequiredAttribute))) { sharedVariable.IsShared = true; } fields[j].SetValue(mTask, sharedVariable); } } } if (isParent) { ParentTask parentTask = this.mTask as ParentTask; if (parentTask.Children != null) { for (int k = 0; k < parentTask.Children.Count; k++) { NodeDesigner nodeDesigner = CreateInstance <NodeDesigner>(); nodeDesigner.LoadTask(parentTask.Children[k], owner, ref id); NodeConnection nodeConnection = CreateInstance <NodeConnection>(); nodeConnection.LoadConnection(this, NodeConnectionType.Fixed); AddChildNode(nodeDesigner, nodeConnection, true, true, k); } } mConnectionIsDirty = true; } }