コード例 #1
0
    public void functionality()
    {
        AI_Action action = myAgent.currentActions.Peek();

        if (action.requiresInRange() && action.target == null)
        {
            Debug.Log("toPlan");

            toPlan();
        }
        else
        {
            //Debug.Log("Moving State");
            //myAgent.transform.position = action.target.transform.position - myAgent.transform.position * Time.deltaTime;
            Debug.Log("IN MOVE STATE");
            myAgent.transform.position = Vector3.Lerp(myAgent.transform.position, action.target.transform.position, .01f);
            distance = Vector3.Distance(myAgent.transform.position, action.target.transform.position);
            //Debug.Log(distance);
            //Debug.Log(distance);
            if (distance < 10)
            {
                //Debug.Log("Distance < 10");
                action.setInRange(true);
            }
            if (action.isInRange())
            {
                Debug.Log("MoveTo STATE:: -> PerformActionState");
                toDoAction();
            }
        }
    }
コード例 #2
0
    public void functionality()
    {
        if (!myAgent.hasActionQueue())
        {
            Debug.Log("ACTION STATE:: No actions to Perform!! -> PlanState");

            myAgent.dataProvider.actionsFinished();
            toPlan();
        }

        AI_Action action = myAgent.currentActions.Peek();

        if (action.isDone())
        {
            myAgent.currentActions.Dequeue();
        }

        if (myAgent.hasActionQueue())
        {
            //Debug.Log("Still have Actions to DO!");
            action = myAgent.currentActions.Peek();
            bool inRange = action.requiresInRange() ? action.isInRange() : true;

            if (inRange)
            {
                bool success = action.performAction(myAgent.gameObject);

                if (!success)
                {
                    myAgent.dataProvider.planAborted(action);
                    Debug.Log("ACTION STATE:: Plan Failed!! -> PlanState");

                    toPlan();
                }
            }
            else
            {
                Debug.Log("ACTION STATE:: Received moveTo!! -> MoveToState");

                toMoveTo();
            }
        }
        else
        {
            Debug.Log("ACTION STATE:: Action Queue Finished!! -> PlanState");
            myAgent.dataProvider.actionsFinished();
            toPlan();
        }
    }