private void Update() { //Try to get the script in the action scripts resources tool UnityEngine.Object script = null; switch (_script_creation_type) { case ScriptCreationMenu_GS.ScriptCreationType.ScriptC_action: { if (ResourcesTool.action_scripts.TryGetValue(_script_full_path.Substring(7), out script)) { //Allocate a class with the same type of script value Planning.Action_GS _new_script = ProTools.AllocateClass <Planning.Action_GS>(script); //Set new script name _new_script.name = _script_full_path.PathToName(); //Place the new action in the selected action node NodeEditor_GS.Instance.selected_agent.action_nodes[_node_index].action = _new_script; //Set action node editor action editor NodeEditor_GS.Instance.action_node_editors[_node_index].action_editor = new Action_GS_Editor(NodeEditor_GS.Instance.action_node_editors[_node_index]); //This dummy gameobject job is done, we can delete it DestroyImmediate(gameObject); return; } } break; case ScriptCreationMenu_GS.ScriptCreationType.ScriptC_behaviour: { if (ResourcesTool.agent_behaviour_scripts.TryGetValue(_script_full_path.Substring(7), out script)) { //Allocate a class with the same type of script value AI.AgentBehaviour_GS _new_script = ProTools.AllocateClass <AI.AgentBehaviour_GS>(script); //Set new script name _new_script.name = _script_full_path.PathToName(); //Place the new action in the selected action node NodeEditor_GS.Instance.selected_agent.behaviour = _new_script; //Update node planning canvas NodePlanning_GS.Instance.Repaint(); //This dummy gameobject job is done, we can delete it DestroyImmediate(gameObject); } } break; } //Count test try_count += 1; if (try_count > ProTools.TRIES_LIMIT) { //Warning message display Debug.LogWarning("New script: " + _script_full_path.PathToName() + " target not found!"); //Destroy gameobject DestroyImmediate(gameObject); } }
//Loop Methods ================ public override void OnGUI(Rect rect) { editorWindow.minSize = new Vector2(200.0f, 100.0f); editorWindow.maxSize = new Vector2(200.0f, 100.0f); GUILayout.BeginVertical(); //Menu title GUILayout.BeginHorizontal("Box"); GUILayout.FlexibleSpace(); GUILayout.Label("Behaviour Select", UIConfig_GS.Instance.select_menu_title_style, GUILayout.ExpandWidth(true)); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); //Separator EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); //Behaviour select dropdown button ProTools.GenerateButtonDropdownMenu(ref _selected_behaviour_index, ResourcesTool.behaviour_paths, "Select", false, 200.0f, _behaviour_dropdown_slot); if (_selected_behaviour_index != -1) { //Get selected behaviour script Object script = null; ResourcesTool.agent_behaviour_scripts.TryGetValue(ResourcesTool.behaviour_paths[_selected_behaviour_index], out script); //Allocate a class with the same type of script value AgentBehaviour_GS new_script = ProTools.AllocateClass <AgentBehaviour_GS>(script); //Check if the selected behaviour is different to the target agent one if (_target_agent.behaviour == null || new_script.GetType() != _target_agent.behaviour.GetType()) { //Set behaviour name new_script.name = ResourcesTool.behaviour_paths[_selected_behaviour_index].PathToName(); //Set behaviour target agent new_script.agent = _target_agent; //Set agent behaviour _target_agent.behaviour = new_script; //Mark scene dirty EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); //Repaint the node editor to update the UI if (NodePlanning_GS.IsOpen()) { NodePlanning_GS.Instance.Repaint(); } } //Close the pop window at the end of the process editorWindow.Close(); } //Behaviour create button if (GUILayout.Button("Create New", GUILayout.ExpandWidth(true))) { //Add popup close on new behaviour script creation //ScriptCreationMenu_GS.on_script_creation_delegate += () => editorWindow.Close(); //Get mouse current position Vector2 mousePos = Event.current.mousePosition; //Open script creation menu PopupWindow.Show(new Rect(mousePos.x, mousePos.y, 0, 0), new ScriptCreationMenu_GS(ScriptCreationMenu_GS.ScriptCreationType.ScriptC_behaviour)); } GUILayout.EndVertical(); }
//Loop Methods ================ public override void OnGUI(Rect rect) { editorWindow.minSize = new Vector2(200.0f, 100.0f); editorWindow.maxSize = new Vector2(200.0f, 100.0f); GUILayout.BeginVertical(); //Menu title GUILayout.BeginHorizontal("Box"); GUILayout.FlexibleSpace(); GUILayout.Label("Action Select", UIConfig_GS.Instance.select_menu_title_style, GUILayout.ExpandWidth(true)); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); //Separator EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); //Action select dropdown button ProTools.GenerateButtonDropdownMenu(ref _selected_action_index, ResourcesTool.action_paths, "Select", false, 200.0f, _action_dropdown_slot); if (_selected_action_index != -1) { //Get selected action script value Object script = null; ResourcesTool.action_scripts.TryGetValue(ResourcesTool.action_paths[_selected_action_index], out script); //Allocate a class with the same type of script value Action_GS new_script = ProTools.AllocateClass <Action_GS>(script); //Action node case if (_target_action_node != null) { //Check if the selected action is different to the node action if (_target_action_node.action == null || _target_action_node.action.GetType() != new_script.GetType()) { //Set the class name to the new allocated action new_script.name = ResourcesTool.action_paths[_selected_action_index].PathToName(); //Set the allocated class to the action node _target_action_node.action = new_script; //Set new action agent new_script.agent = _target_action_node.agent; //Set target action node editor action editor _target_action_node_editor.action_editor = new Action_GS_Editor(_target_action_node_editor); //Mark scene dirty EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); //Repaint the node editor to update the UI NodeEditor_GS.Instance.Repaint(); } } //Agent idle action case else { Agent_GS target_agent = NodeEditor_GS.Instance.selected_agent; //Check if the selected agent is different to the agent idle action if (target_agent.idle_action == null || target_agent.idle_action.GetType() != new_script.GetType()) { //Set the class name to the new allocated action new_script.name = ResourcesTool.action_paths[_selected_action_index].PathToName(); //Set new action agent new_script.agent = NodeEditor_GS.Instance.selected_agent; //Set the agent idle action target_agent.idle_action = new_script; //Mark scene dirty EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); //Repaint the node editor to update the UI NodePlanning_GS.Instance.Repaint(); } } //Close the pop window at the end of the process editorWindow.Close(); } //Action create button if (GUILayout.Button("Create New", GUILayout.ExpandWidth(true))) { //Get mouse current position Vector2 mousePos = Event.current.mousePosition; //Open script creation menu PopupWindow.Show(new Rect(mousePos.x, mousePos.y, 0, 0), new ScriptCreationMenu_GS(ScriptCreationMenu_GS.ScriptCreationType.ScriptC_action, _target_action_node.index)); } GUILayout.EndVertical(); }