Exemplo n.º 1
0
    ////////////////////////////////////////////////////////////////////////////////////



    ////////////////////////////////////////////////////////////////
    // Use this for initialization
    public void InitializeAgentBrain()
    {
        // NAV MESH AGENT TEST
        GetComponent <NavMeshAgent>().Stop();
        GetComponent <NavMeshAgent>().updatePosition = false;
        GetComponent <NavMeshAgent>().updateRotation = false;

        locomotionSystem = GetComponent <SoldierLocomotion>();

        // initializing neighbor lists
        neighborObstacles = GetComponent <NeighbourObstacles>();
        neighborObstacles.Init();

        neighborAgents = GetComponent <NeighbourAgents>();
        neighborAgents.Init();

        currentState = new State(transform.position);

        if (GlobalNavigator.usingDynamicNavigationMesh)
        {
            currentPolygonIndex = GlobalNavigator.recastSteeringManager.GetClosestPolygon(currentState.getPosition());
        }

        if (goal == null)
        {
            Debug.LogError("Goal has not been initialized for this agent");
        }
        goalState = goal.goalState;

        passableMask = 1;         // this could be part of the goal

        globalPath             = new List <State> ();
        numGlobalPathWaypoints = 0;

        globalPathPolygonIndices = new List <uint> ();

        localPaths                = new List <List <State> > ();
        spaceTimePaths            = new List <List <State> > ();
        currentPlanExecutionIndex = 0;

        offMeshLinkWayPoint = new List <bool>();

        taskManager = new TaskManager();

        // creating global navigation task
        globalNavigationTask = new GlobalNavigationtask(currentState, goalState, passableMask,
                                                        TaskPriority.RealTime, taskManager);
        globalNavigationTask.taskName = "globalNavigationTask";

        // EVENT: AgentBrain is triggered by the globalNavigationTask when GLOBAL_PATH_CHANGED
        globalNavigationTask.registerObserver(Event.GLOBAL_PATH_CHANGED, this);


        gridNavigationTasks = new List <GridNavigationTask>();

        // creating grid navigation and grid time tasks for each statically allocated global waypoint
        // -- we can statically allocate how many ever we want
        for (int i = 0; i < 1; i++)
        {
            _addNewEmptyGlobalPathWayPointAtIndex(i);
        }


        curves    = new AnimationCurve[4];
        curves[0] = new AnimationCurve();         // x
        curves[1] = new AnimationCurve();         // y
        curves[2] = new AnimationCurve();         // z
        curves[3] = new AnimationCurve();         // speed
    }
Exemplo n.º 2
0
    ////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////
    // Use this for initialization
    public void InitializeAgentBrain()
    {
        // NAV MESH AGENT TEST
        GetComponent<NavMeshAgent>().Stop ();
        GetComponent<NavMeshAgent>().updatePosition = false;
        GetComponent<NavMeshAgent>().updateRotation = false;

        locomotionSystem = GetComponent<SoldierLocomotion>();

        // initializing neighbor lists
        neighborObstacles =  GetComponent<NeighbourObstacles>();
        neighborObstacles.Init ();

        neighborAgents = GetComponent<NeighbourAgents>();
        neighborAgents.Init();

        currentState = new State(transform.position);

        if (GlobalNavigator.usingDynamicNavigationMesh)
        {
            currentPolygonIndex = GlobalNavigator.recastSteeringManager.GetClosestPolygon(currentState.getPosition());
        }

        if ( goal == null ) Debug.LogError("Goal has not been initialized for this agent");
        goalState = goal.goalState;

        passableMask = 1; // this could be part of the goal

        globalPath = new List<State> ();
        numGlobalPathWaypoints = 0;

        globalPathPolygonIndices = new List<uint> ();

        localPaths = new List<List<State>> ();
        spaceTimePaths = new List<List<State>> ();
        currentPlanExecutionIndex = 0;

        offMeshLinkWayPoint = new List<bool>();

        taskManager = new TaskManager ();

        // creating global navigation task
         globalNavigationTask = new GlobalNavigationtask(currentState,goalState,passableMask,
            TaskPriority.RealTime, taskManager);
        globalNavigationTask.taskName = "globalNavigationTask";

        // EVENT: AgentBrain is triggered by the globalNavigationTask when GLOBAL_PATH_CHANGED
        globalNavigationTask.registerObserver(Event.GLOBAL_PATH_CHANGED, this);

        gridNavigationTasks = new List<GridNavigationTask>();

        // creating grid navigation and grid time tasks for each statically allocated global waypoint
        // -- we can statically allocate how many ever we want
        for (int i=0; i < 1; i ++ )
        {
            _addNewEmptyGlobalPathWayPointAtIndex(i);
        }

        curves = new AnimationCurve[4];
        curves[0] = new AnimationCurve(); // x
        curves[1] = new AnimationCurve(); // y
        curves[2] = new AnimationCurve(); // z
        curves[3] = new AnimationCurve(); // speed
    }