/// <summary> /// Adds a new node to the tree. /// <param name="type">The type of the new node.</param> /// <returns>The new created node.</returns> /// </summary> public ActionNode AddNode(System.Type type) { var node = ActionNode.CreateInstance(type, gameObject, this); if (node != null) { NodeSerialization.idField.SetValue(node, GetNewUniqueID()); GetNodes(); // Add node var nodes = new List <ActionNode>(m_Nodes); nodes.Add(node); m_Nodes = nodes.ToArray(); if (Application.isPlaying) { m_FunctionNodes = this.GetFunctionNodes(); // The tree is enabled? if (this.enabled) { node.OnEnable(); } } HierarchyChanged(); } return(node); }
/// <summary> /// Adds a new node to the tree. /// <param name="type">The type of the new node.</param> /// <returns>The new created node.</returns> /// </summary> public ActionNode AddNode(System.Type type) { var node = ActionNode.CreateInstance(type, gameObject, this); if (node != null) { NodeSerialization.idField.SetValue(node, GetNewUniqueID()); GetNodes(); // Add node var nodes = new List <ActionNode>(m_Nodes); nodes.Add(node); m_Nodes = nodes.ToArray(); this.HierarchyChanged(); } return(node); }
/// <summary> /// Create the runtime lists of nodes. /// </summary> void CreateRuntimeListsOfNodes() { // iterator int i; // OnEnable Nodes var onEnableList = new List <ActionNode>(); for (i = 0; i < m_Nodes.Length; i++) { if (!(m_Nodes[i] is Update)) { onEnableList.Add(m_Nodes[i]); } else { break; } } if (onEnableList.Count > 0) { m_OnEnable = ActionNode.CreateInstance(typeof(OnEnable), gameObject, this) as OnEnable; m_OnEnable.SetChildren(onEnableList.ToArray()); } else { m_OnEnable = null; } // Update Nodes var updateList = new List <ActionNode>(); // FixedUpdate Nodes var fixedUpdateList = new List <ActionNode>(); // GUI Nodes var onGuiList = new List <ActionNode>(); for (int j = i + 1; j < m_Nodes.Length; j++) { // OnGUI if (m_Nodes[j] is IGUINode) { onGuiList.Add(m_Nodes[j]); } // FixedUpdate else if (m_Nodes[j] is IFixedUpdateNode) { fixedUpdateList.Add(m_Nodes[j]); } // Update else { updateList.Add(m_Nodes[j]); } } // FixedUpdate if (fixedUpdateList.Count > 0) { m_FixedUpdate = ActionNode.CreateInstance(typeof(FixedUpdate), gameObject, this) as FixedUpdate; // Call Reset if it's not in editor if (!Application.isEditor) { m_FixedUpdate.Reset(); } m_FixedUpdate.SetChildren(fixedUpdateList.ToArray()); } else { m_FixedUpdate = null; } // Update if (updateList.Count > 0) { m_Update = ActionNode.CreateInstance(typeof(Update), gameObject, this) as Update; // Call Reset if it's not in editor if (!Application.isEditor) { m_Update.Reset(); } m_Update.SetChildren(updateList.ToArray()); } else { m_Update = null; } // OnGUI if (onGuiList.Count > 0) { m_OnGUI = ActionNode.CreateInstance(typeof(OnGUI), gameObject, this) as OnGUI; // Call Reset if it's not in editor if (!Application.isEditor) { m_OnGUI.Reset(); } m_OnGUI.SetChildren(onGuiList.ToArray()); } else { m_OnGUI = null; } }