Exemplo n.º 1
0
 private void InitNPC()
 {
     Debug.Assert(LaneData != null);
     rb.isKinematic = true;
     controller.MainCollider.isTrigger = true;
     controller.ResetLights();
     currentSpeed       = 0f;
     rb.angularVelocity = Vector3.zero;
     rb.velocity        = Vector3.zero;
     CurrentIndex       = 0;
     CurrentLoopIndex   = 0;
     CurrentDeactivate  = LaneDeactivate[CurrentIndex];
     if (IdleCoroutine != null)
     {
         FixedUpdateManager.StopCoroutine(IdleCoroutine);
         IdleCoroutine = null;
     }
     if (MoveCoroutine != null)
     {
         FixedUpdateManager.StopCoroutine(MoveCoroutine);
         MoveCoroutine = null;
     }
     if (TriggerCoroutine != null)
     {
         FixedUpdateManager.StopCoroutine(TriggerCoroutine);
         TriggerCoroutine = null;
     }
     WaypointState = WaypointDriveState.Drive;
 }
 private void InitPedestrian()
 {
     Debug.Assert(LaneData != null);
     RB.isKinematic = true;
     // TODO currentSpeed = 0f;
     RB.angularVelocity = Vector3.zero;
     RB.velocity        = Vector3.zero;
     CurrentIndex       = 0;
     CurrentLoopIndex   = 0;
     if (IdleCoroutine != null)
     {
         FixedUpdateManager.StopCoroutine(IdleCoroutine);
         IdleCoroutine = null;
     }
     if (MoveCoroutine != null)
     {
         FixedUpdateManager.StopCoroutine(MoveCoroutine);
         MoveCoroutine = null;
     }
     if (TriggerCoroutine != null)
     {
         FixedUpdateManager.StopCoroutine(TriggerCoroutine);
         TriggerCoroutine = null;
     }
     WaypointState = WaypointWalkState.Walk;
 }
Exemplo n.º 3
0
    private void EvaluateLane()
    {
        CurrentIndex++; // index can equal laneData.Count so it can finish npc move IE
        if (CurrentIndex < LaneData.Count)
        {
            CurrentTarget            = LaneData[CurrentIndex];
            controller.MovementSpeed = LaneSpeed[CurrentIndex];
            controller.currentSpeed  = LaneSpeed[CurrentIndex];
            controller.steerVector   = (CurrentTarget - controller.frontCenter.position).normalized;
        }

        if (CurrentIndex == LaneData.Count)
        {
            var api = ApiManager.Instance;
            if (WaypointLoop)
            {
                if (CurrentLoopIndex == 0 && api != null)
                {
                    api.AgentTraversedWaypoints(gameObject);
                }
                CurrentLoopIndex++;
                rb.MovePosition(InitPos);
                rb.MoveRotation(InitRot);
                InitNPC();
            }
            else
            {
                if (api != null)
                {
                    api.AgentTraversedWaypoints(gameObject);
                }
                WaypointState = WaypointDriveState.Despawn;
                if (TriggerCoroutine != null)
                {
                    FixedUpdateManager.StopCoroutine(TriggerCoroutine);
                }
                TriggerCoroutine = null;
                if (IdleCoroutine != null)
                {
                    FixedUpdateManager.StopCoroutine(IdleCoroutine);
                }
                IdleCoroutine = null;
                if (MoveCoroutine != null)
                {
                    FixedUpdateManager.StopCoroutine(MoveCoroutine);
                }
                MoveCoroutine = null;
            }
        }
        else
        {
            WaypointState = WaypointDriveState.Drive;
        }
    }