public bool RemoveVariableEditorPlanning(string key) { //Remove the target variable from the agent planning editors //Used when a blackboard variable is removed bool ret = false; //Iterate the agent action nodes for (int k = 0; k < NodeEditor_GS.Instance.action_node_editors_num; k++) { //Focused action node ActionNode_GS_Editor target_node = NodeEditor_GS.Instance.action_node_editors[k]; //Iterate the action node conditions for (int n = 0; n < target_node.condition_editors_num; n++) { Property_GS target_condition = target_node.condition_editors[n].target_property; //Check if the condition uses the target variable if (string.Compare(key, target_condition.A_key) == 0 || string.Compare(key, target_condition.B_key) == 0) { //Delete the condition if the target variable is in target_node.RemoveConditionEditor(target_node.condition_editors[n]); ret = true; } } //Iterate the action node effects for (int n = 0; n < target_node.effect_editors_num; n++) { Property_GS target_effect = target_node.effect_editors[n].target_property; //Check if the effect uses the target variable if (string.Compare(key, target_effect.A_key) == 0 || string.Compare(key, target_effect.B_key) == 0) { //Delete the effect if the target variable is in target_node.RemoveEffectEditor(target_node.effect_editors[n]); ret = true; } } } return(ret); }
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(); }