//Contructors ================= public VariableSelectMenu_GS(bool global = false) { //Set global _global_blackboard = global; //Initialize the variable dropdown data _variable_dropdown_data = new ProTools.DropDownData_GS(); //Get dropdown slots _variable_dropdown_data.dropdown_slot = ProTools.GetDropdownSlot(); }
private bool _has_method_parameters = false; //If the variable is binded with a method without input parameters, the input selection menu is blocked //Constructors ==================== public Variable_GS_Editor(Variable_GS new_variable, Blackboard_GS new_bb) { //Set target variable _target_variable = new_variable; //Set target bb _target_blackboard = new_bb; //Initialize dropdowns data _variable_dropdown_data = new ProTools.DropDownData_GS(); _method_dropdown_data = new ProTools.DropDownData_GS(); //Check for binded method parameters if (string.IsNullOrEmpty(_target_variable.binded_method_path) == false) { _has_method_parameters = ProTools.FindMethodFromPath(_target_variable.binded_method_path, _target_variable.system_type, _target_blackboard.target_agent.gameObject).Key.GetParameters().Length > 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(); }
private void DrawInShow() { GUILayout.BeginHorizontal(); //Edit button, swap between edit and show state(hide on play) if (!Application.isPlaying) { if (GUILayout.Button("O", GUILayout.Width(30), GUILayout.Height(20), GUILayout.ExpandWidth(false))) { //Initialize value value = _target_property.value; //Change UI mode _UI_mode = EditorUIMode.EDIT_STATE; //Allocate B var dropdown _B_variable_dropdown = new ProTools.DropDownData_GS(); //Allocate operator dropdown _operator_dropdown = new ProTools.DropDownData_GS(); //Get dropdown slots _operator_dropdown.dropdown_slot = ProTools.GetDropdownSlot(); _B_variable_dropdown.dropdown_slot = ProTools.GetDropdownSlot(); //Generate operators dropdown data _operator_dropdown.paths = _valid_operators.ToShortStrings(); for (int k = 0; k < _valid_operators.Length; k++) { if (_valid_operators[k] == _target_property.operator_type) { ProTools.SetDropdownIndex(_operator_dropdown.dropdown_slot, k); _operator_dropdown.selected_index = k; } } //Get local blackboard variables keys with the same type string[] local_keys = NodeEditor_GS.Instance.selected_agent.blackboard.GetKeysByVariableType(_target_property.variable_type); //Get global blackboard variables keys with the same type string[] global_keys = GlobalBlackboard_GS.blackboard.GetKeysByVariableType(_target_property.variable_type); //Generate paths _B_variable_dropdown.paths = 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_dropdown.paths[k] = "Local/" + local_keys[k]; } //Add the global keys with a prefix for the dropdown for (int k = local_keys.Length, i = 0; k < _B_variable_dropdown.paths.Length; k++, i++) { _B_variable_dropdown.paths[k] = "Global/" + global_keys[i]; } //Search and set the already selected B key index //Iterate avaliable B keys for (int k = 0; k < _B_variable_dropdown.paths.Length; k++) { if (string.Compare(_B_variable_dropdown.paths[k], _target_property.B_key) == 0) { //When key is found save index and break the iteration ProTools.SetDropdownIndex(_B_variable_dropdown.dropdown_slot, k); _B_variable_dropdown.selected_index = k; break; } } } } //A key label GUILayout.Label(_target_property.A_key, UIConfig_GS.center_normal_style, GUILayout.MaxWidth(200.0f), GUILayout.ExpandWidth(true)); //Operator label GUILayout.Label(" " + _target_property.operator_type.ToShortString() + " ", GUILayout.MaxWidth(30.0f), GUILayout.ExpandWidth(true)); //B value label if (string.IsNullOrEmpty(_target_property.B_key)) { //Value case GUILayout.Label(_target_property.display_value, UIConfig_GS.center_normal_style, GUILayout.MaxWidth(200.0f), GUILayout.ExpandWidth(true)); } else { //Variable case GUILayout.Label(_target_property.B_key, UIConfig_GS.center_normal_style, GUILayout.MaxWidth(200.0f), GUILayout.ExpandWidth(true)); } //Delete button(hide on play) if (!Application.isPlaying) { if (GUILayout.Button(new GUIContent("X", "Remove"), GUILayout.MaxWidth(25.0f))) { //We need to check if the target property is a condition or an effect to delete it from the correct container switch (_property_UI_mode) { case PropertyUIMode.IS_CONDITION: { //Add remove the current property from target action node conditions SecurityAcceptMenu_GS.on_accept_delegate += () => _target_action_node_editor.target_action_node.RemoveCondition(_target_property); //Add remove current property editor from target acton node editor conditions editors SecurityAcceptMenu_GS.on_accept_delegate += () => _target_action_node_editor.RemoveConditionEditor(this); } break; case PropertyUIMode.IS_EFFECT: { //Add remove the current property from target action node effects SecurityAcceptMenu_GS.on_accept_delegate += () => _target_action_node_editor.target_action_node.RemoveEffect(_target_property); //Add remove current property editor from target acton node editor effects editors SecurityAcceptMenu_GS.on_accept_delegate += () => _target_action_node_editor.RemoveEffectEditor(this); break; } } //Get mouse current position Vector2 mousePos = Event.current.mousePosition; //Open security accept menu on mouse position PopupWindow.Show(new Rect(mousePos.x, mousePos.y, 0, 0), new SecurityAcceptMenu_GS()); } } GUILayout.EndHorizontal(); }
//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; } }