public override void CopyValues(Action_GS copy)
    {
        diamond = ((FindQuarryAction_GS)copy).diamond;
        rock    = ((FindQuarryAction_GS)copy).rock;

        base.CopyValues(copy);
    }
        //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();
        }
Example #3
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();
        }