Пример #1
0
 public override void Disable(Agent agent)
 {
     if (useRootMotion)
     {
         RootMotionMovement rootMotionMovement = agent.GetComponent <RootMotionMovement>();
         rootMotionMovement.enabled = false;
     }
     else
     {
         NonRootMotionMovement nonRootMotionMovement = agent.GetComponent <NonRootMotionMovement>();
         nonRootMotionMovement.enabled = false;
     }
     navMeshAgents[agent].enabled = false;
 }
Пример #2
0
        public override void SetupAgent(Agent agent)
        {
            if (surface == null)
            {
                surface = FindObjectOfType <NavMeshSurface>();
                if (surface == null)
                {
                    Debug.LogError(agent.name + ": Is using UnityNavMeshMT which requires a NavMeshSurface in the Scene.  Please add.");
                    return;
                }
            }

            // Needed to clear out Dicts after playing for AgentView Editor Window
            if (!Application.isPlaying && navMeshAgents != null && navMeshAgents.ContainsKey(agent))
            {
                OnEnable();
            }

            NavMeshAgent navMeshAgent = agent.GetComponent <NavMeshAgent>();

            if (navMeshAgent == null)
            {
                Debug.LogError(agent.name + ": Is using UnityNavMeshMT which requires a NavMeshAgent Component.  Please add to Agent.");
                return;
            }
            else if (Mathf.Abs(navMeshAgent.baseOffset) > .25f)
            {
                Debug.LogWarning("NavMeshAgent has a large baseOffset - Please make sure Agent's root transform is on the NavMesh. " +
                                 "(It should be on the ground at the Agent's feet.)");
            }
            navMeshAgents.Add(agent, navMeshAgent);
            pathCache.Add(agent, new Dictionary <Vector3, PathCache>());

            agent.movementType.NavMeshAgentUpdateRotation(agent, navAgentUpdateRotation);
            agent.movementType.NavMeshAgentUpdatePosition(agent, navAgentUpdatePosition);

            if (useRootMotion)
            {
                RootMotionMovement rootMotionMovement = agent.GetComponent <RootMotionMovement>();
                if (rootMotionMovement == null)
                {
                    Debug.LogError(agent.name + ": Using UnityNavMeshMT with Root Motion which requires a RootMotionMovement component.  " +
                                   "Please add to agent.");
                }
                else
                {
                    rootMotionMovement.Initialize(agent);
                }
            }
            else
            {
                NonRootMotionMovement nonRootMotionMovement = agent.GetComponent <NonRootMotionMovement>();
                if (nonRootMotionMovement == null)
                {
                    Debug.LogError(agent.name + ": Using UnityNavMeshMT with No Root Motion which requires a NonRootMotionMovement component.  " +
                                   "Please add to agent.");
                }
                else
                {
                    nonRootMotionMovement.Initialize(agent);
                }
            }
        }