Beispiel #1
0
        /// <summary>
        /// Add am action to the queue or set it as the current action
        /// </summary>
        /// <param name="actionName">The name of the action in the PossiblActions queue</param>
        /// <param name="addToList">Whether to add it to the list or set as current action</param>
        /// <param name="go">GameObejct to be passed to the action</param>
        /// <param name="vec3">Vector3 to be passed to the action</param>
        /// <param name="integer">Integer to be passed to the action</param>
        public void AddAction(string actionName, bool addToList, GameObject go, Vector3 vec3, int integer)
        {
            // Check whether the action is valid
            if (PossibleActionsDict.ContainsKey(actionName))
            {
                AIAction action = PossibleActionsDict[actionName];

                if (action)
                {
                    // Get a copy
                    action = Instantiate(action);
                    // Initialise
                    action.InitialiseAction(this);

                    // Set the internal data of the action and see if it can be performed
                    if (action.SetVariables(this, go, vec3, integer))
                    {
                        // If it can be performed then handle it appropriately
                        SetAction(action, addToList, false);
                    }
                    else
                    {
                        // Else cancel the action and move on
                        action.CancelAction(this);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Instantiate, initialise and 'select' an action the add to the queue or set as current, will not be added if it's selection fails
        /// </summary>
        /// <param name="action">Action to add</param>
        /// <param name="addToList">Whether to add to the queue or not</param>
        /// <param name="selectAction">Whether to call the SelectAction method on the action or not</param>
        /// <param name="createInstance">Whether or not to instantiate the action</param>
        public void AddAction(AIAction action, bool addToList, bool selectAction = true, bool createInstance = true)
        {
            cachedAction = action;
            if (cachedAction)
            {
                bool selectedPass = false;

                if (createInstance)
                {
                    // Instantiate and initialise the new action
                    cachedAction = Instantiate(cachedAction);
                    cachedAction.InitialiseAction(this);
                }

                if (selectAction)
                {
                    selectedPass = cachedAction.SelectionAction(this);

                    if (!selectedPass)
                    {
                        cachedAction.CancelAction(this);
                    }
                }

                if (selectedPass || !selectAction)
                {
                    SetAction(cachedAction, addToList);
                }
            }
        }