コード例 #1
0
ファイル: ProTools.cs プロジェクト: hofcsabaGit/Unity-GOAP_S
        public static KeyValuePair <MethodInfo, object>[] FindConcreteAgentMethods(AI.Agent_GS target_agent, Type target_return_type)
        {
            //Allocate the methods list
            List <KeyValuePair <MethodInfo, object> > methods_list = new List <KeyValuePair <MethodInfo, object> >();

            //Get action nodes methods
            for (int k = 0; k < target_agent.action_nodes_num; k++)
            {
                //Check action node action
                Planning.Action_GS node_action = target_agent.action_nodes[k].action;
                if (node_action != null)
                {
                    //Get action methods
                    MethodInfo[] action_methods = node_action.GetType().GetMethods();
                    foreach (MethodInfo action_method in action_methods)
                    {
                        //Methods with the same return type as the target are stored in the methods list
                        if (action_method.ReturnType == target_return_type)
                        {
                            methods_list.Add(new KeyValuePair <MethodInfo, object>(action_method, node_action));
                        }
                    }
                }
            }

            //Get behaviour methods
            if (target_agent.behaviour != null)
            {
                MethodInfo[] behaviour_methods = target_agent.behaviour.GetType().GetMethods();
                foreach (MethodInfo behaviour_method in behaviour_methods)
                {
                    //Methods with the same return type as the target are stored in the methods list
                    if (behaviour_method.ReturnType == target_return_type)
                    {
                        methods_list.Add(new KeyValuePair <MethodInfo, object>(behaviour_method, target_agent.behaviour));
                    }
                }
            }

            //Get idle action methods
            if (target_agent.idle_action != null)
            {
                MethodInfo[] idle_action_methods = target_agent.idle_action.GetType().GetMethods();
                foreach (MethodInfo idle_action_method in idle_action_methods)
                {
                    //Methods with the same return type as the target are stored in the methods list
                    if (idle_action_method.ReturnType == target_return_type)
                    {
                        methods_list.Add(new KeyValuePair <MethodInfo, object>(idle_action_method, target_agent.idle_action));
                    }
                }
            }

            //Return the list converted to array
            return(methods_list.ToArray());
        }
コード例 #2
0
        private void Update()
        {
            //Try to get the script in the action scripts resources tool
            UnityEngine.Object script = null;
            switch (_script_creation_type)
            {
            case ScriptCreationMenu_GS.ScriptCreationType.ScriptC_action:
            {
                if (ResourcesTool.action_scripts.TryGetValue(_script_full_path.Substring(7), out script))
                {
                    //Allocate a class with the same type of script value
                    Planning.Action_GS _new_script = ProTools.AllocateClass <Planning.Action_GS>(script);
                    //Set new script name
                    _new_script.name = _script_full_path.PathToName();
                    //Place the new action in the selected action node
                    NodeEditor_GS.Instance.selected_agent.action_nodes[_node_index].action = _new_script;
                    //Set action node editor action editor
                    NodeEditor_GS.Instance.action_node_editors[_node_index].action_editor = new Action_GS_Editor(NodeEditor_GS.Instance.action_node_editors[_node_index]);
                    //This dummy gameobject job is done, we can delete it
                    DestroyImmediate(gameObject);
                    return;
                }
            }
            break;

            case ScriptCreationMenu_GS.ScriptCreationType.ScriptC_behaviour:
            {
                if (ResourcesTool.agent_behaviour_scripts.TryGetValue(_script_full_path.Substring(7), out script))
                {
                    //Allocate a class with the same type of script value
                    AI.AgentBehaviour_GS _new_script = ProTools.AllocateClass <AI.AgentBehaviour_GS>(script);
                    //Set new script name
                    _new_script.name = _script_full_path.PathToName();
                    //Place the new action in the selected action node
                    NodeEditor_GS.Instance.selected_agent.behaviour = _new_script;
                    //Update node planning canvas
                    NodePlanning_GS.Instance.Repaint();
                    //This dummy gameobject job is done, we can delete it
                    DestroyImmediate(gameObject);
                }
            }
            break;
            }
            //Count test
            try_count += 1;
            if (try_count > ProTools.TRIES_LIMIT)
            {
                //Warning message display
                Debug.LogWarning("New script: " + _script_full_path.PathToName() + " target not found!");
                //Destroy gameobject
                DestroyImmediate(gameObject);
            }
        }