コード例 #1
0
        //Loop Methods ================
        public override void OnGUI(Rect rect)
        {
            //Menu title
            GUILayout.BeginHorizontal("Box");
            GUILayout.FlexibleSpace();
            GUILayout.Label("Variable Select", UIConfig_GS.Instance.select_menu_title_style, GUILayout.ExpandWidth(true));
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

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

            //Variable name field
            GUILayout.BeginHorizontal();
            GUILayout.Label("Name", GUILayout.ExpandWidth(true));
            _variable_name = EditorGUILayout.TextField(_variable_name, GUILayout.ExpandWidth(true));
            GUILayout.EndHorizontal();

            //Variable type field
            GUILayout.BeginHorizontal();
            GUILayout.Label("Type", GUILayout.ExpandWidth(true));
            VariableType current_type = _variable_type;

            _variable_type = (VariableType)EditorGUILayout.EnumPopup(_variable_type, GUILayout.Width(150), GUILayout.ExpandWidth(true));
            //Check if var type is changed
            if (current_type != _variable_type)
            {
                //Allocate value from variable type
                ProTools.AllocateFromVariableType(_variable_type, ref _variable_value);

                //Get all the properties in the agent gameobject
                PropertyInfo[] _properties_info = ProTools.FindConcretePropertiesInGameObject(NodeEditor_GS.Instance.selected_agent.gameObject, _variable_type.ToSystemType());
                //Get all fields in th agent gameobject
                FieldInfo[] _fields_info = ProTools.FindConcreteFieldsInGameObject(NodeEditor_GS.Instance.selected_agent.gameObject, _variable_type.ToSystemType());

                //Allocate strings arrays
                _variable_dropdown_data.paths         = new string[_properties_info.Length + _fields_info.Length];
                _variable_dropdown_data.display_paths = new string[_properties_info.Length + _fields_info.Length];
                //Generate properties paths
                for (int k = 0; k < _properties_info.Length; k++)
                {
                    _variable_dropdown_data.paths[k]         = string.Format("{0}.{1}", _properties_info[k].ReflectedType.FullName, _properties_info[k].Name);
                    _variable_dropdown_data.display_paths[k] = _variable_dropdown_data.paths[k].Replace('.', '/');
                }
                //Generate fields paths
                int fields_k = 0; //Index to iterate fields info array
                for (int k = _properties_info.Length; k < _properties_info.Length + _fields_info.Length; k++)
                {
                    _variable_dropdown_data.paths[k]         = string.Format("{0}.{1}", _fields_info[fields_k].ReflectedType.FullName, _fields_info[fields_k].Name);
                    _variable_dropdown_data.display_paths[k] = _variable_dropdown_data.paths[k].Replace('.', '/');
                    fields_k += 1;//Update fields index
                }
            }
            GUILayout.EndHorizontal();

            //Custom field value
            if (_variable_type != VariableType._undefined_var_type)
            {
                GUILayout.BeginVertical();

                //Show variable value or info label if the variable is binded
                if (_variable_dropdown_data.selected_index != -1)
                {
                    GUILayout.Label("Value=" + bind_selected_display_path, UIConfig_GS.Instance.node_elements_style, GUILayout.ExpandWidth(true));
                }
                else
                {
                    //Define horizontal area
                    GUILayout.BeginHorizontal(GUILayout.MaxWidth(150.0f));

                    //Value label
                    GUILayout.Label("Value", GUILayout.MaxWidth(40.0f));

                    //Generate an input field adapted to the type of the variable
                    ProTools.ValueFieldByVariableType(_variable_type, ref _variable_value);

                    GUILayout.EndHorizontal();
                }

                //Bind variable
                GUILayout.BeginHorizontal();
                //Generate bind selection dropdown

                /*ProTools.GenerateButtonDropdownMenu(ref _variable_dropdown_data.selected_index, _variable_dropdown_data.display_paths, "Bind", false, 90.0f, _variable_dropdown_data.dropdown_slot);
                 * //UnBind button
                 * if (GUILayout.Button("UnBind"))
                 * {
                 *  //Reset variable dropdown
                 *  ProTools.SetDropdownIndex(_variable_dropdown_data.dropdown_slot, -1);
                 * }
                 * GUILayout.EndHorizontal();
                 *
                 * //Show selected bind path
                 * if (_variable_dropdown_data.selected_index == -1) GUILayout.Label(bind_selected_display_path);*/

                GUILayout.EndVertical();
            }

            //Separation
            GUILayout.FlexibleSpace();

            GUILayout.BeginHorizontal();
            //Add button
            if (GUILayout.Button("Add", UIConfig_GS.Instance.node_modify_button_style, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)))
            {
                //Add the new variable if the data is correct
                if (!string.IsNullOrEmpty(_variable_name) && _variable_type != VariableType._undefined_var_type && _variable_value != null)
                {
                    //Send info to the bb to generate the variable
                    Variable_GS new_variable = null;
                    //Local case
                    if (_global_blackboard == false)
                    {
                        new_variable = NodeEditor_GS.Instance.selected_agent.blackboard.AddVariable(_variable_name, _variable_type, _variable_value);
                    }
                    //Global case
                    else
                    {
                        new_variable = GlobalBlackboard_GS.blackboard.AddVariable(_variable_name, _variable_type, _variable_value);
                    }

                    //If add var return null is because the name is invalid(exists a variable with the same name)
                    if (new_variable != null)
                    {
                        //Check if var have to be bind
                        if (_variable_dropdown_data.selected_index != -1)
                        {
                            //Bind new variable
                            new_variable.BindField(_variable_dropdown_data.paths[_variable_dropdown_data.selected_index]);
                        }
                        //Send the new variable to the blackboard editor to generate the variable editor
                        //Local case
                        if (_global_blackboard == false)
                        {
                            NodeEditor_GS.Instance.blackboard_editor.AddVariableEditor(new_variable);
                        }
                        //Global case
                        else
                        {
                            GlobalBlackboard_GS_Editor.blackboard_editor.AddVariableEditor(new_variable);
                        }
                        //Close this popup and updat bb window
                        editorWindow.Close();
                        NodeEditor_GS.Instance.Repaint();
                    }
                    else
                    {
                        //Add a rep prefix to the variable name, so the user can see that the name is repeated
                        _variable_name = "Rep:" + _variable_name;
                    }
                }
            }
            //Close button
            if (GUILayout.Button("Close", UIConfig_GS.Instance.node_modify_button_style, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)))
            {
                editorWindow.Close();
            }
            GUILayout.EndHorizontal();
        }
コード例 #2
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();
        }
コード例 #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
        //Constructor =================
        public MethodSelectMenu_GS(Variable_GS target_variable)
        {
            //Set the target variable
            _target_variable = target_variable;
            //Get method info
            _target_method = ProTools.FindMethodFromPath(_target_variable.binded_method_path, target_variable.system_type, NodeEditor_GS.Instance.selected_agent.gameObject).Key;
            //Get method parameters
            method_parameters = _target_method.GetParameters();
            //Allocate input array in null case
            if (_target_variable.binded_method_input == null)
            {
                _target_variable.binded_method_input = new KeyValuePair <string, object> [method_parameters.Length];
                //Allocate input data from type

                for (int k = 0; k < method_parameters.Length; k++)
                {
                    KeyValuePair <string, object> input = _target_variable.binded_method_input[k];
                    if (string.IsNullOrEmpty(input.Key) && input.Value == null)
                    {
                        object temp_value = new object();
                        ProTools.AllocateFromVariableType(method_parameters[k].ParameterType.ToVariableType(), ref temp_value);
                        _target_variable.binded_method_input[k] = new KeyValuePair <string, object>("", temp_value);
                    }
                }
            }
            //Allocate editor values and dropdowns
            local_values    = new object[method_parameters.Length];
            input_dropdowns = new ProTools.DropDownData_GS[method_parameters.Length];
            for (int k = 0; k < method_parameters.Length; k++)
            {
                //Initialize local value
                if (_target_variable.binded_method_input[k].Value != null)
                {
                    local_values[k] = _target_variable.binded_method_input[k].Value;
                }
                else
                {
                    ProTools.AllocateFromVariableType(method_parameters[k].ParameterType.ToVariableType(), ref local_values[k]);
                }

                //Generate the new dropdown data
                ProTools.DropDownData_GS new_dropdown = new ProTools.DropDownData_GS();
                new_dropdown.dropdown_slot = ProTools.GetDropdownSlot();

                //Get local and global variables
                string[] local_keys  = NodeEditor_GS.Instance.selected_agent.blackboard.GetKeysByVariableType(method_parameters[k].ParameterType.ToVariableType());
                string[] global_keys = GlobalBlackboard_GS.blackboard.GetKeysByVariableType(method_parameters[k].ParameterType.ToVariableType());

                //Generate dropdown paths
                new_dropdown.paths         = new string[local_keys.Length + global_keys.Length];
                new_dropdown.display_paths = new string[local_keys.Length + global_keys.Length];

                //Add the local keys with a prefix for the dropdown
                for (int j = 0; j < local_keys.Length; j++)
                {
                    new_dropdown.display_paths[j] = "Local/" + local_keys[j];
                    new_dropdown.paths[j]         = local_keys[j];
                }

                //Add the global keys with a prefix for the dropdown
                for (int j = local_keys.Length, s = 0; j < new_dropdown.paths.Length; j++, s++)
                {
                    new_dropdown.display_paths[j] = "Global/" + global_keys[s];
                    new_dropdown.paths[j]         = global_keys[s];
                }

                //Add the generated dropdown
                input_dropdowns[k] = new_dropdown;
            }
        }