コード例 #1
0
        //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();
        }
コード例 #2
0
        private void ShowBindOptions()
        {
            //Bind variable
            GUILayout.BeginHorizontal();

            if (!_target_variable.is_field_binded && !_target_variable.is_method_binded)
            {
                //Free space margin
                GUILayout.FlexibleSpace();

                //Generate variable bind selection dropdown
                ProTools.GenerateButtonDropdownMenu(ref _variable_dropdown_data.selected_index, _variable_dropdown_data.display_paths, "V", false, 40.0f, _variable_dropdown_data.dropdown_slot);

                //Generate method bind selection dropdown
                ProTools.GenerateButtonDropdownMenu(ref _method_dropdown_data.selected_index, _method_dropdown_data.display_paths, "M", false, 40.0f, _method_dropdown_data.dropdown_slot);

                if (_variable_dropdown_data.selected_index > -1)
                {
                    //Bind variable to the new field using the selected path
                    EditorApplication.delayCall += () => _target_variable.BindField(_variable_dropdown_data.paths[_variable_dropdown_data.selected_index]);
                }
                else if (_method_dropdown_data.selected_index > -1)
                {
                    //Bind the variable to the new method using the selected path
                    EditorApplication.delayCall += () => _target_variable.BindMethod(_method_dropdown_data.paths[_method_dropdown_data.selected_index]);
                    EditorApplication.delayCall += () => _has_method_parameters = ProTools.FindMethodFromPath(_target_variable.binded_method_path, _target_variable.system_type, _target_blackboard.target_agent.gameObject).Key.GetParameters().Length > 0;
                }
            }
            else
            {
                //Show current variable bind
                if (target_variable.is_field_binded)
                {
                    GUILayout.Label(_target_variable.binded_field_short_path, GUILayout.MaxWidth(90.0f));
                }
                //Show current method bind
                else
                {
                    if (_has_method_parameters)
                    {
                        //If the variables is method binded we show the field inheritance path
                        if (GUILayout.Button(_target_variable.binded_method_short_path, GUILayout.MaxWidth(90.0f)))
                        {
                            Vector2 mousePos = Event.current.mousePosition;
                            PopupWindow.Show(new Rect(mousePos.x, mousePos.y, 0, 0), new MethodSelectMenu_GS(_target_variable));
                        }
                    }
                    else
                    {
                        GUILayout.Label(_target_variable.binded_method_short_path, GUILayout.MaxWidth(90.0f));
                    }
                }

                //Free space margin
                GUILayout.FlexibleSpace();

                //UnBind button
                if (GUILayout.Button("UnBind", GUILayout.MaxWidth(50.0f)))
                {
                    if (_target_variable.is_field_binded)
                    {
                        //Unbind varaible resetting  getter/setter and field path
                        _target_variable.UnbindField();
                        //Reset path index in the variables dropdown
                        ProTools.SetDropdownIndex(_variable_dropdown_data.dropdown_slot, -1);
                    }
                    else
                    {
                        //Unbind method rersetting getter and method info
                        _target_variable.UnbindMethod();
                        _has_method_parameters = false;
                        //Reset path index in the methods dropdown
                        ProTools.SetDropdownIndex(_method_dropdown_data.dropdown_slot, -1);
                    }
                }
            }
            GUILayout.EndHorizontal();
        }
コード例 #3
0
        //Loop Methods ================
        public override void OnGUI(Rect rect)
        {
            editorWindow.maxSize = new Vector2(200.0f, 170.0f);
            editorWindow.minSize = new Vector2(200.0f, 170.0f);

            GUILayout.BeginVertical();

            //Menu title
            GUILayout.BeginHorizontal("Box");
            GUILayout.FlexibleSpace();
            GUILayout.Label(_menu_title, UIConfig_GS.Instance.select_menu_title_style, GUILayout.ExpandWidth(true));
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            //Separator
            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);


            //Variable select
            GUILayout.BeginHorizontal();
            GUILayout.Label("Variable:", GUILayout.MaxWidth(60.0f));
            //Generate dropdown with the variables in the target blackboard
            ProTools.GenerateButtonDropdownMenu(ref _selected_A_key_index, _A_variable_keys, "Not Set", true, 120.0f, _A_key_dropdown_slot);

            //Check variable selection change
            if (prev_selected_variable_index != _selected_A_key_index)
            {
                if (_selected_A_key_index != -1)
                {
                    //If the selected index is valid we get the variable type
                    if (_selected_A_key_index + 1 > NodeEditor_GS.Instance.selected_agent.blackboard.variables.Count)
                    {
                        //Global variable case
                        _selected_variable_type = GlobalBlackboard_GS.blackboard.variables[_original_A_variable_keys[_selected_A_key_index]].type;
                    }
                    else
                    {
                        //Local variable case
                        _selected_variable_type = NodeEditor_GS.Instance.selected_agent.blackboard.variables[_original_A_variable_keys[_selected_A_key_index]].type;
                    }

                    //Then we can allocate the property value with the variable type
                    ProTools.AllocateFromVariableType(_selected_variable_type, ref _selected_value);
                    //Get valid operators
                    //Need to check if si a condition or an effect
                    if (_property_UI_mode == PropertyUIMode.IS_CONDITION)
                    {
                        //Condition passive operators case
                        _valid_operators = _selected_variable_type.GetValidPassiveOperatorTypes();
                    }
                    else if (_property_UI_mode == PropertyUIMode.IS_EFFECT)
                    {
                        //Effect active operators case
                        _valid_operators = _selected_variable_type.GetValidActiveOperatorTypes();
                    }
                    //Reset operator selected
                    _selected_operator_index = -1;

                    //Get local blackboard variables keys with the same type
                    string[] local_keys = NodeEditor_GS.Instance.selected_agent.blackboard.GetKeysByVariableType(_selected_variable_type);
                    //Get global blackboard variables keys with the same type
                    string[] global_keys = GlobalBlackboard_GS.blackboard.GetKeysByVariableType(_selected_variable_type);
                    //Allocate string array to store all the keys
                    _B_variable_keys          = new string[local_keys.Length + global_keys.Length];
                    _original_B_variable_keys = new string[local_keys.Length + global_keys.Length];
                    //Add the local keys with a prefix for the dropdown
                    for (int k = 0; k < local_keys.Length; k++)
                    {
                        _B_variable_keys[k]          = "Local/" + local_keys[k];
                        _original_B_variable_keys[k] = local_keys[k];
                    }
                    //Add the global keys with a prefix for the dropdown
                    for (int k = local_keys.Length, i = 0; k < _B_variable_keys.Length; k++, i++)
                    {
                        _B_variable_keys[k]          = "Global/" + global_keys[i];
                        _original_B_variable_keys[k] = global_keys[i];
                    }

                    //Reset B key selected
                    _selected_B_key_index = -1;
                }
                else
                {
                    //In non valid index case we reset the property data
                    _selected_variable_type  = VariableType._undefined_var_type;
                    _selected_value          = null;
                    _valid_operators         = null;
                    _selected_operator_index = -1;
                }
                prev_selected_variable_index = _selected_A_key_index;
            }
            GUILayout.EndHorizontal();

            //Operator select
            GUILayout.BeginHorizontal();
            if (_valid_operators != null)
            {
                GUILayout.Label("Operator:", GUILayout.MaxWidth(60.0f));
                //Generate enumerator popup with the operator type
                ProTools.GenerateButtonDropdownMenu(ref _selected_operator_index, _valid_operators.ToShortStrings(), "Not Set", true, 120.0f, _operator_dropdown_slot);
            }
            GUILayout.EndHorizontal();

            //Value area
            //Target select
            GUILayout.BeginVertical();
            if (_selected_A_key_index != -1)
            {
                if (_value_or_key == 0 || _value_or_key == 1)
                {
                    if (GUILayout.Button("Use Variable", GUILayout.MaxWidth(100.0f)))
                    {
                        _value_or_key = 2;
                    }
                }
                else if (_value_or_key == 2)
                {
                    if (GUILayout.Button("Use Value", GUILayout.MaxWidth(100.0f)))
                    {
                        _value_or_key = 1;
                    }
                }
            }
            //Value select
            GUILayout.BeginHorizontal();
            if (_selected_A_key_index != -1)
            {
                if (_value_or_key == 0 || _value_or_key == 1)
                {
                    GUILayout.Label("Value:", GUILayout.MaxWidth(60.0f));
                }
                else if (_value_or_key == 2)
                {
                    GUILayout.Label("Variable:", GUILayout.MaxWidth(60.0f));
                }

                //Show input field in value case
                if (_value_or_key == 1 || _value_or_key == 0)
                {
                    //Show field on valid index case
                    ProTools.ValueFieldByVariableType(_selected_variable_type, ref _selected_value);
                }
                //Show input field in variable case
                else if (_value_or_key == 2)
                {
                    //Generate enumerator popup with the avaliable B keys
                    ProTools.GenerateButtonDropdownMenu(ref _selected_B_key_index, _B_variable_keys, "Not Set", true, 120.0f, _B_key_dropdown_slot);
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();

            //Separation
            GUILayout.FlexibleSpace();

            //Add/Close buttons
            GUILayout.BeginHorizontal();
            //Add button
            if (GUILayout.Button("Add", UIConfig_GS.Instance.node_modify_button_style, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)))
            {
                //First we need to check if all the fields are correctly filled
                if (_selected_A_key_index == -1 || _selected_operator_index == -1 || (_value_or_key == 2 && _selected_B_key_index == -1))
                {
                    Debug.LogWarning("Fields are not filled correctly!");
                }
                //If everithing is correct we generate the condition
                else
                {
                    //First allocate the property class
                    Property_GS new_property = new Property_GS();
                    //Set A key
                    new_property.A_key = _A_variable_keys[_selected_A_key_index];
                    //Set variable type
                    new_property.variable_type = _selected_variable_type;
                    //Set operator type
                    new_property.operator_type = _valid_operators[_selected_operator_index];
                    //Set value or key in property B part
                    if (_value_or_key == 2)
                    {
                        new_property.B_key = _B_variable_keys[_selected_B_key_index];
                        //Set value as B variable
                        string[] B_key_info = new_property.B_key.Split('/');
                        if (string.Compare(B_key_info[0], "Global") == 0)
                        {
                            new_property.value = GlobalBlackboard_GS.blackboard.GetObjectVariable(B_key_info[1]);
                        }
                        else
                        {
                            new_property.value = NodeEditor_GS.Instance.selected_agent.blackboard.GetObjectVariable(B_key_info[1]);
                        }
                    }
                    else
                    {
                        new_property.value = _selected_value;
                    }
                    //Add property to the action node we are working with
                    //Need to check if is a condition or an effect
                    if (_property_UI_mode == PropertyUIMode.IS_CONDITION)
                    {
                        //Add condition case
                        _target_action_node_editor.AddCondition(new_property);
                    }
                    else if (_property_UI_mode == PropertyUIMode.IS_EFFECT)
                    {
                        //Add effect case
                        _target_action_node_editor.AddEffect(new_property);
                    }
                    //Close this menu
                    editorWindow.Close();
                    //Update node editor
                    NodeEditor_GS.Instance.Repaint();
                }
            }
            //Close button
            if (GUILayout.Button("Close", UIConfig_GS.Instance.node_modify_button_style, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)))
            {
                editorWindow.Close();
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
        }
コード例 #4
0
        private void DrawInEdit()
        {
            GUILayout.BeginHorizontal();

            //Edit button, swap between edit and show state
            if (GUILayout.Button("-", GUILayout.Width(30), GUILayout.Height(20), GUILayout.ExpandWidth(false)) || Application.isPlaying)
            {
                //Change UI mode
                _UI_mode = EditorUIMode.SET_STATE;
                //Set input focus to null
                GUI.FocusControl("null");
                //Free dropdown slots
                ProTools.FreeDropdownSlot(_operator_dropdown.dropdown_slot);
                ProTools.FreeDropdownSlot(_B_variable_dropdown.dropdown_slot);
                _operator_dropdown   = null;
                _B_variable_dropdown = null;
                //Check B key
                if (edit_value)
                {
                    //If property B key is not ser property will use value
                    _target_property.B_key = null;
                    //If value is different we update the variable value
                    if (value != _target_property.value)
                    {
                        _target_property.value = value;
                    }
                    ;
                }
                return;
            }

            //A key label
            GUILayout.Label(_target_property.A_key, UIConfig_GS.center_normal_style, GUILayout.MaxWidth(200.0f), GUILayout.ExpandWidth(true));

            //Operator dropdown
            ProTools.GenerateButtonDropdownMenu(ref _operator_dropdown.selected_index, _operator_dropdown.paths, _operator_dropdown.paths[_operator_dropdown.selected_index], true, 30.0f, _operator_dropdown.dropdown_slot);
            //Check operator change
            if (_operator_dropdown.selected_index != -1 && _valid_operators[_operator_dropdown.selected_index] != _target_property.operator_type)
            {
                _target_property.operator_type = _valid_operators[_operator_dropdown.selected_index];
            }

            //Value area
            //First check if the target property uses a value or a variable
            if (edit_value)
            {
                //Generate UI field from type
                ProTools.ValueFieldByVariableType(_target_property.variable_type, ref value);

                //Change to variable button
                if (GUILayout.Button(new GUIContent(" ", "Change to variable"), GUILayout.MaxWidth(10.0f)))
                {
                    edit_value = false;
                }
            }
            else
            {
                //Generate enumerator popup with the avaliable B keys
                ProTools.GenerateButtonDropdownMenu(ref _B_variable_dropdown.selected_index, _B_variable_dropdown.paths, "Not Set", _B_variable_dropdown.selected_index != -1, 80.0f, _B_variable_dropdown.dropdown_slot);
                //Check B key change
                if (_B_variable_dropdown.selected_index != -1 && string.Compare(_target_property.B_key, _B_variable_dropdown.paths[_B_variable_dropdown.selected_index]) != 0)
                {
                    //Update B key on change
                    _target_property.B_key = _B_variable_dropdown.paths[_B_variable_dropdown.selected_index];
                    //Set value as B variable
                    string[] B_key_info = _target_property.B_key.Split('/');
                    if (string.Compare(B_key_info[0], "Global") == 0)
                    {
                        _target_property.value = GlobalBlackboard_GS.blackboard.GetObjectVariable(B_key_info[1]);
                    }
                    else
                    {
                        _target_property.value = NodeEditor_GS.Instance.selected_agent.blackboard.GetObjectVariable(B_key_info[1]);
                    }
                }

                //Change to value button
                if (GUILayout.Button(new GUIContent(" ", "Change to value"), GUILayout.MaxWidth(10.0f)))
                {
                    edit_value             = true;
                    _target_property.B_key = null;
                    ProTools.AllocateFromVariableType(_target_property.variable_type, ref value);
                }
            }
            GUILayout.EndHorizontal();
        }
コード例 #5
0
        //Loop Methods ================
        public override void OnGUI(Rect rect)
        {
            //Menu title
            GUILayout.BeginHorizontal("Box");
            GUILayout.FlexibleSpace();
            GUILayout.Label("Method Input", UIConfig_GS.Instance.select_menu_title_style, GUILayout.ExpandWidth(true));
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            //Separator
            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

            GUILayout.BeginVertical();

            //Method name
            GUILayout.Label(_target_method.Name, UIConfig_GS.left_bold_style);

            //Method inputs
            for (int k = 0; k < method_parameters.Length; k++)
            {
                GUILayout.BeginHorizontal();

                //Input type
                GUILayout.Label(method_parameters[k].ParameterType.ToShortString(), UIConfig_GS.left_bold_style, GUILayout.MaxWidth(80), GUILayout.ExpandWidth(true));
                //Not binded input case
                if (string.IsNullOrEmpty(_target_variable.binded_method_input[k].Key))
                {
                    //Input value
                    ProTools.ValueFieldByVariableType(method_parameters[k].ParameterType.ToVariableType(), ref local_values[k]);

                    //Bind dropdown
                    ProTools.GenerateButtonDropdownMenu(ref input_dropdowns[k].selected_index, input_dropdowns[k].display_paths, "Bind", false, 40.0f, input_dropdowns[k].dropdown_slot);

                    //On variable selected we update the method input of the target variable
                    if (input_dropdowns[k].selected_index > -1)
                    {
                        //Generate the new method input with the bind path
                        _target_variable.binded_method_input[k] = new KeyValuePair <string, object>(input_dropdowns[k].display_paths[input_dropdowns[k].selected_index], null);
                    }
                }
                //Binded input case
                else
                {
                    //Binded input path
                    GUILayout.Label(_target_variable.binded_method_input[k].Key, GUILayout.MaxWidth(80.0f));
                    //Unbind button
                    if (GUILayout.Button("UnBind", GUILayout.MaxWidth(50.0f)))
                    {
                        //Remove method input path string and place tje local correct type value
                        _target_variable.binded_method_input[k] = new KeyValuePair <string, object>("", local_values[k]);
                        //Reset the dropdown selected index
                        ProTools.SetDropdownIndex(input_dropdowns[k].dropdown_slot, -1);
                    }
                }
                //Binded input case
                GUILayout.EndHorizontal();
            }

            GUILayout.BeginHorizontal();

            //Apply changes button
            if (GUILayout.Button("Apply", UIConfig_GS.Instance.node_modify_button_style, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)))
            {
                for (int k = 0; k < method_parameters.Length; k++)
                {
                    if (string.IsNullOrEmpty(_target_variable.binded_method_input[k].Key))
                    {
                        //Local object values are applied to the non binded method input parameters
                        _target_variable.binded_method_input[k] = new KeyValuePair <string, object>("", local_values[k]);
                    }
                }

                //Release the allocated dropdown slots
                for (int k = 0; k < input_dropdowns.Length; k++)
                {
                    ProTools.FreeDropdownSlot(input_dropdowns[k].dropdown_slot);
                }

                //Close popupwindow
                editorWindow.Close();
            }

            //Close button
            if (GUILayout.Button("Close", UIConfig_GS.Instance.node_modify_button_style, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)))
            {
                //Release the allocated dropdown slots
                for (int k = 0; k < input_dropdowns.Length; k++)
                {
                    ProTools.FreeDropdownSlot(input_dropdowns[k].dropdown_slot);
                }

                //Close popupwindow
                editorWindow.Close();
            }

            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
        }
コード例 #6
0
        //Loop Methods ================
        public override void OnGUI(Rect rect)
        {
            editorWindow.minSize = new Vector2(200.0f, 120.0f);
            editorWindow.maxSize = new Vector2(200.0f, 120.0f);

            GUILayout.BeginVertical();

            //Menu title
            GUILayout.BeginHorizontal("Box");
            GUILayout.FlexibleSpace();
            GUILayout.Label(_window_title + "Script Creation", UIConfig_GS.Instance.select_menu_title_style, GUILayout.ExpandWidth(true));
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            //Separator
            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

            //Folder area
            GUILayout.BeginHorizontal();
            //Folder label
            GUILayout.Label("Folder:", GUILayout.MaxWidth(50.0f));
            //Folder dropdown button
            ProTools.GenerateButtonDropdownMenu(ref _folder_selected_index, ResourcesTool.assets_folders, _folder_selected_index == -1 ? "Not Set" : ResourcesTool.assets_folders[_folder_selected_index].FolderToName(), false, 150.0f, _folder_dropdown_slot);
            GUILayout.EndHorizontal();

            //Name Text field
            GUILayout.BeginHorizontal();
            GUILayout.Label("Name:", GUILayout.MaxWidth(50.0f));
            _new_script_name = EditorGUILayout.TextField("", _new_script_name, GUILayout.MaxWidth(140.0f));
            GUILayout.EndHorizontal();

            //Flexible space separation
            GUILayout.FlexibleSpace();

            //Create/Cancel buttons
            GUILayout.BeginHorizontal();
            //Create
            if (GUILayout.Button("Create", UIConfig_GS.Instance.node_modify_button_style, GUILayout.Width(30), GUILayout.ExpandWidth(true)) &&
                _folder_selected_index != -1 && //Path is set
                !string.IsNullOrEmpty(_new_script_name))    //Name is set
            {
                //Adapt class name (class name can't have spaces)
                _new_script_name = _new_script_name.Replace(' ', '_');
                //Generate new script path
                _new_script_full_path = ResourcesTool.assets_folders[_folder_selected_index] + '/' + _new_script_name + ".cs";
                //Check if the file exists
                if (File.Exists(_new_script_full_path) == true)
                {
                    //Script already exists case
                    Debug.LogWarning("Already exists a script named: " + _new_script_name + "in the folder: " + ResourcesTool.assets_folders[_folder_selected_index]);
                }
                else
                {
                    //New script case
                    using (StreamWriter new_script = new StreamWriter(_new_script_full_path))
                    {
                        switch (_script_creation_type)
                        {
                        case ScriptCreationType.ScriptC_action:
                        {
                            //Set new action script code
                            new_script.WriteLine("using UnityEngine;");
                            new_script.WriteLine("using GOAP_S.Planning;");
                            new_script.WriteLine("public class " + _new_script_name + " : Action_GS");
                            new_script.WriteLine("{");
                            //TODO
                            new_script.WriteLine("}");
                        }
                        break;

                        case ScriptCreationType.ScriptC_behaviour:
                        {
                            //Set new behaiour script code
                            new_script.WriteLine("using UnityEngine;");
                            new_script.WriteLine("using GOAP_S.AI;");
                            new_script.WriteLine("public class " + _new_script_name + " : AgentBehaviour_GS");
                            new_script.WriteLine("{");
                            //TODO
                            new_script.WriteLine("}");
                        }
                        break;
                        }
                    }

                    //Refresh assets
                    AssetDatabase.Refresh();
                    //Load asset and save it in the generated script static object to use it in future actions
                    GameObject temp_compilation_obj = new GameObject();
                    temp_compilation_obj.transform.parent = Selection.activeGameObject.transform;

                    ScriptCreationSetter_GS temp_comp = temp_compilation_obj.AddComponent <ScriptCreationSetter_GS>();
                    temp_comp._script_full_path     = _new_script_full_path;
                    temp_comp._script_creation_type = _script_creation_type;
                    temp_comp._node_index           = _node_index;
                }

                //Close popup window
                editorWindow.Close();
            }
            //Cancel
            if (GUILayout.Button("Cancel", UIConfig_GS.Instance.node_modify_button_style, GUILayout.Width(30), GUILayout.ExpandWidth(true)))
            {
                //First check if there's a method to call
                if (on_script_creation_cancel_delegate != null)
                {
                    //Call the script creation cancel delegate
                    on_script_creation_cancel_delegate();
                    //Reset on script creation cancel delegate
                    on_script_creation_cancel_delegate = null;
                }

                //Close popup window
                editorWindow.Close();
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
        }
コード例 #7
0
        //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();
        }