Ejemplo n.º 1
0
        //在Start里面进行的初始化
        public bool MakeInitialize()
        {
            //NavManager.ActiveManager的获取还需要一个更好的设计
            if (!enabled)
            {
                Debug.LogError(this.name + ": is not enabled ");
                return(false);
            }

            if (NavManager.ActiveManager == null)
            {
                Debug.LogError(this.name + ": no activeManager ");
                return(false);
            }
            mNavManager = NavManager.ActiveManager;
            //建立navAgent,这是真正用于移动的agent
            mNavAgent           = mNavManager.CreateAgent(agentGroup, transform);
            mNavAgent.moveSpeed = this.moveSpeed;
            if (mNavAgent == null)
            {
                Debug.LogError(this.name + ": agent create failed");
                enabled = false;
                return(false);
            }
            mNavAgent.rotation = transform.rotation;
            mNavAgent.position = mNavAgent.GetPointSearch(transform.position);
            if (mNavAgent.position.polyRef == 0)
            {
                mNavAgent = null;
                Debug.LogError(this.name + ": take agent into navmesh failed: " + mNavAgent.position);
                enabled = false;
                return(false);
            }

            //planner是底层计算推进(可以考虑多线程)
            //mover是unity位置改变,只能在主线程
            planner = new NavPlanner(mNavAgent);
            //用于表现,也就是修改Unity中的移动的move
            //UnitySimpleMovePlan unityMovePlan  = new UnitySimpleMovePlan();
            UnityMoveWithFixdRoute unityMovePlan = new UnityMoveWithFixdRoute();

            unityMovePlan.SetNavAgent(mNavAgent);
            unityMovePlan.yAxisFreeze = this.yAxisFreeze;
            mover         = unityMovePlan;
            mManagerIndex = mNavManager.AddAgent(planner, unityMovePlan);
            if (mManagerIndex == -1)
            {
                Debug.LogError(this.name + ": add agent to navigation manager failed");
                enabled = false;
                return(false);
            }
            Stop();
            return(true);
        }
Ejemplo n.º 2
0
 public void SetNavAgent(NavAgent agent)
 {
     theNavAgent = agent;
 }
Ejemplo n.º 3
0
 public NavPlanner(NavAgent theAgentIn)
 {
     theAgent     = theAgentIn;
     mSimpleMover = new SimpleMovePlan(theAgentIn);
     mCrowdMover  = new CrowdMovePlan(theAgentIn);
 }
Ejemplo n.º 4
0
 //构造的时候必须要获得这个agent
 public SimpleMovePlan(NavAgent theAgentIn)
 {
     theAgent = theAgentIn;
 }
Ejemplo n.º 5
0
 public CrowdMovePlan(NavAgent theAgentIn)
 {
     theAgent = theAgentIn;
 }