Beispiel #1
0
        public void AddTargetAgentActionNodeEditor(ActionNode_GS new_node)
        {
            //Set new node agent
            new_node.agent = _selected_agent;

            //Check if we need to allocate more items in the array
            if (_action_node_editors_num == _action_node_editors.Length)
            {
                //Double array capacity
                ActionNode_GS_Editor[] new_array = new ActionNode_GS_Editor[_action_node_editors_num * 2];
                //Copy values
                for (int k = 0; k < _action_node_editors_num; k++)
                {
                    new_array[k] = _action_node_editors[k];
                }
                //Set new array
                _action_node_editors = new_array;
            }

            //Generate the new action node editor
            ActionNode_GS_Editor new_node_editor = new ActionNode_GS_Editor(new_node);

            //Add it to the array
            _action_node_editors[_action_node_editors_num] = new_node_editor;
            //Update editors num
            _action_node_editors_num += 1;
        }
 //Constructors ================
 public ActionSelectMenu_GS(ActionNode_GS_Editor new_target_action_node_editor)
 {
     if (new_target_action_node_editor != null)
     {
         //Focus the action node
         _target_action_node_editor = new_target_action_node_editor;
         _target_action_node        = _target_action_node_editor.target_action_node;
     }
     //Get dropdown slot for action select
     _action_dropdown_slot = ProTools.GetDropdownSlot();
 }
        private int _B_key_dropdown_slot    = -1;                                        //B key dropdown slot

        //Contructors =================
        public PropertySelectMenu_GS(ActionNode_GS_Editor new_target_action_node_editor, PropertyUIMode new_property_UI_mode)
        {
            //Set property UI mode
            _property_UI_mode = new_property_UI_mode;
            //Set menu title
            if (_property_UI_mode == PropertyUIMode.IS_CONDITION)
            {
                //Condition title case
                _menu_title = "Condition Select";
            }
            else if (_property_UI_mode == PropertyUIMode.IS_EFFECT)
            {
                //Effect title case
                _menu_title = "Effect Select";
            }
            //Set the action node is this menu working with
            _target_action_node_editor = new_target_action_node_editor;

            //Get local blackboard variables keys
            string[] local_keys = NodeEditor_GS.Instance.selected_agent.blackboard.GetKeys();

            //Get global blackboard variables keys
            string[] global_keys = GlobalBlackboard_GS.blackboard.GetKeys();

            //Allocate string array to store all the keys
            _A_variable_keys          = new string[local_keys.Length + global_keys.Length];
            _original_A_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++)
            {
                _A_variable_keys[k]          = "Local/" + local_keys[k];
                _original_A_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 < _A_variable_keys.Length; k++, i++)
            {
                _A_variable_keys[k]          = "Global/" + global_keys[i];
                _original_A_variable_keys[k] = global_keys[i];
            }

            //Get dropdown slots
            _A_key_dropdown_slot    = ProTools.GetDropdownSlot();
            _operator_dropdown_slot = ProTools.GetDropdownSlot();
            _B_key_dropdown_slot    = ProTools.GetDropdownSlot();
        }
        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 object value = null;                                            //Value selected by user in property using value case

        //Constructors
        public Property_GS_Editor(Property_GS new_property, ActionNode_GS_Editor new_action_node_editor, Blackboard_GS new_bb, PropertyUIMode new_ui_mode)
        {
            //Set target property
            _target_property = new_property;
            //Set target action node editor
            _target_action_node_editor = new_action_node_editor;
            //Set property editor UI mode
            _property_UI_mode = new_ui_mode;
            //Allocate the valid operators
            if (_property_UI_mode == PropertyUIMode.IS_CONDITION)
            {
                _valid_operators = _target_property.variable_type.GetValidPassiveOperatorTypes();
            }
            else if (_property_UI_mode == PropertyUIMode.IS_EFFECT)
            {
                _valid_operators = _target_property.variable_type.GetValidActiveOperatorTypes();
            }
            //Check if the target property has a B key to adapt UI
            edit_value = string.IsNullOrEmpty(_target_property.B_key);
        }
Beispiel #6
0
        private void GenerateTargetAgentUI()
        {
            //Alloc node editors array
            _action_node_editors_num = 0;
            _action_node_editors     = new ActionNode_GS_Editor[_selected_agent.action_nodes_num == 0 ? ProTools.INITIAL_ARRAY_SIZE : _selected_agent.action_nodes_num];

            //Generate action nodes editors
            for (int k = 0; k < _selected_agent.action_nodes_num; k++)
            {
                //Allocate action node editor
                ActionNode_GS_Editor new_node_editor = new ActionNode_GS_Editor(_selected_agent.action_nodes[k]);
                //Add on the node editor
                _action_node_editors[_action_node_editors_num] = new_node_editor;
                //Update nodes count
                _action_node_editors_num += 1;
            }

            //Generate blackboard editor
            _blackboard_editor             = new Blackboard_GS_Editor(_selected_agent.blackboard);
            _blackboard_editor.window_size = new Vector2(ProTools.BLACKBOARD_MARGIN, 100);
        }
Beispiel #7
0
 public void RemoveTargetAgentActionNodeEditor(ActionNode_GS_Editor target_node_editor)
 {
     for (int k = 0; k < _action_node_editors_num; k++)
     {
         if (_action_node_editors[k] == target_node_editor)
         {
             if (k == _action_node_editors.Length - 1)
             {
                 _action_node_editors[k] = null;
             }
             else
             {
                 for (int i = k; i < _action_node_editors_num - 1; i++)
                 {
                     _action_node_editors[i] = _action_node_editors[i + 1];
                 }
             }
             //Update node count
             _action_node_editors_num -= 1;
         }
     }
 }
Beispiel #8
0
        private void OnGUI()
        {
            //Draw background texture
            GUI.DrawTexture(new Rect(0, 0, position.width, position.height), back_texture, ScaleMode.StretchToFill);

            //Check if there is an agent selected
            if (_selected_agent == null)
            {
                //Handle no agent input
                HandleNoAgentInput();
                return;
            }

            //Zoomable layout
            BeginZoomableLayout();

            //Zoomable layout area
            Rect area_rect = new Rect(-_zoom_position.x, -_zoom_position.y, ProTools.NODE_EDITOR_CANVAS_SIZE, ProTools.NODE_EDITOR_CANVAS_SIZE);

            GUILayout.BeginArea(area_rect);

            //Temp for guide
            for (int k = 0; k < area_rect.width; k += 200)
            {
                for (int y = 0; y < area_rect.height; y += 200)
                {
                    GUI.Label(new Rect(y, k, 120.0f, 25.0f), y + "||" + k);
                }
            }

            //Mark the beginning area of the popup windows
            BeginWindows();


            //Draw action nodes
            for (int k = 0; k < _action_node_editors_num; k++)
            {
                //Focus action node
                ActionNode_GS node = _selected_agent.action_nodes[k];
                //Focus action node editor
                ActionNode_GS_Editor node_editor = _action_node_editors[k];
                //Show node window
                node.window_rect = GUILayout.Window(node.id, node.window_rect, node_editor.DrawUI, node.name, UIConfig_GS.Instance.node_window_style, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                //Show description label
                GUI.Label(new Rect(node.window_position.x - node_editor.label_size.x, node.window_position.y, node_editor.label_size.x, node_editor.label_size.y), node.description, UIConfig_GS.left_white_style);
            }

            //Reset matrix to keep blackboard window scale
            GUI.matrix = Matrix4x4.identity;

            //Selection change can generate null blackboard
            if (_blackboard_editor == null)
            {
                GenerateTargetAgentUI();
            }
            else
            {
                //Update blackboard window to simulate static position
                _blackboard_editor.window_position = new Vector2(_zoom_position.x + position.width - ProTools.BLACKBOARD_MARGIN, 0 + _zoom_position.y);
                //Display blackboard window
                GUILayout.Window(_blackboard_editor.id, _blackboard_editor.window, _blackboard_editor.DrawUI, "Blackboard", UIConfig_GS.canvas_window_style, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
            }

            //End area of popup windows
            EndWindows();

            //End zoomable layout area
            GUILayout.EndArea();

            //End zoomable layout
            EndZoomableLayout();

            //Handle input
            HandleInput();
        }
Beispiel #9
0
        private object[] _values = null;                         //All the selected values (properties + fields)

        //Contructors =================
        public Action_GS_Editor(ActionNode_GS_Editor target)
        {
            //Set target node
            _target_node_editor = target;
            //Set target action
            _target_action = _target_node_editor.target_action_node.action;

            //Temporal values list
            List <object> temp_value_list = new List <object>();

            //Get action properties info
            PropertyInfo[]      all_properties   = _target_action.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
            List <PropertyInfo> valid_properties = new List <PropertyInfo>();

            //Iterate all the action properties
            foreach (PropertyInfo property in all_properties)
            {
                //Blocked properties are not stored
                object[] blocked_attribute = property.GetCustomAttributes(typeof(BlockedProperty_GS), true);
                if (blocked_attribute.Length != 0)
                {
                    continue;
                }
                //Add the non blocked property to the list
                if (property.CanRead)
                {
                    //Add the property value
                    temp_value_list.Add(property.GetGetMethod().Invoke(_target_action, null));
                }
                else
                {
                    //Add null value to mantain a logic index
                    temp_value_list.Add(null);
                }
                //Add the non blocked property
                valid_properties.Add(property);
            }
            //Finally tranform the generated list to an array and store it
            _properties = valid_properties.ToArray();

            //Get fields info
            FieldInfo[]      all_fields   = _target_action.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
            List <FieldInfo> valid_fields = new List <FieldInfo>();

            //Iterate all the action fields
            foreach (FieldInfo field in all_fields)
            {
                //Blocked fields are not stored
                object[] block_attribute = field.GetCustomAttributes(typeof(BlockedField_GS), true);
                if (block_attribute.Length != 0)
                {
                    continue;
                }
                //Add the non blocked field to the list
                temp_value_list.Add(field.GetValue(_target_action));
                //Add the non blocked field
                valid_fields.Add(field);
            }
            //Finally transform the generated list to an array and store it
            _fields = valid_fields.ToArray();

            //Store the temp values list to the final array
            _values = temp_value_list.ToArray();
        }