Пример #1
0
 //----------------------------方法部分------------------------------//
 public NavAgent(Transform theTransform, NavGroup theGroup, NavAgentGroups theAgentGroup)
 {
     this.agentGroup  = theAgentGroup;
     this.navGroup    = new NavGroup(theGroup, false);
     this.transform   = theTransform;
     this.wideExtents = this.navGroup.extents * 10f;
     RevertToAgentGroup();
 }
Пример #2
0
        public static NavAgentGroups CreateAgentGroup(int index, int maxPath, int maxStraightPath, out byte group)
        {
            GroupSettings    aSetting = new GroupSettings();
            CrowdAgentParams cap      = new CrowdAgentParams();

            cap.collisionQueryRange = aSetting.colisionQueryRange;
            cap.height                = aSetting.height;
            cap.maxAcceleration       = aSetting.maxAcceleration;
            cap.maxSpeed              = aSetting.maxSpeed;
            cap.pathOptimizationRange = aSetting.pathOptimizationRange;
            cap.radius                = aSetting.radius;
            cap.separationWeight      = aSetting.separationWeight;
            cap.updateFlags           = aSetting.updateFlags;
            NavAgentGroups aGroup = new NavAgentGroups(cap, maxPath, maxStraightPath,
                                                       aSetting.maxPoolCorridors, aSetting.maxPoolPaths);

            aGroup.maxTurnSpeed = aSetting.maxTurnSpeed;

            group = mGroup[index];
            return(aGroup);
        }
Пример #3
0
        public NavManager CreateManager()
        {
            CheckCrowdAvoidanceSet();

            if (!(mNavmeshData && NavmeshData.HasNavmesh))
            {
                Debug.LogError("Aborted initialization. Navigation mesh not available.");
                return(null);
            }

            //Debug.Log("NavmeshData-------"+ NavmeshData);
            Navmesh navmesh = NavmeshData.GetNavmesh();

            if (navmesh == null)
            {
                NavStatus theStatus = Navmesh.Create(navMeshData, out navmesh);

                Debug.Log("Navmesh.Create ---->" + theStatus + "---->" + (int)(theStatus & NavStatus.Sucess));
                if (NavUtil.Failed(theStatus))
                {
                    Debug.LogError("NavUtil.Failed(Navmesh.Create(navMeshData, out navmesh) Fail!");
                }
                Debug.Log("--------------------\n" + navMeshData + "---" + navMeshData.Length + "\n-----------------\nNavmesh-------" + navmesh);
            }
            if (navmesh == null)
            {
                Debug.LogError(" navmesh is null");
                return(null);
            }
            NavmeshQuery query;
            NavStatus    status = NavmeshQuery.Create(navmesh, mMaxQueryNodes, out query);

            if ((status & NavStatus.Sucess) == 0)
            {
                Debug.LogError(" Aborted initialization. Failed query creation: " + status.ToString());
                return(null);
            }

            CrowdManager crowd = CrowdManager.Create(mMaxCrowdAgents, mMaxAgentRadius, navmesh);

            if (crowd == null)
            {
                Debug.LogError("Aborted initialization. Failed crowd creation.");
                return(null);
            }

            for (int i = 0; i < CrowdManager.MaxAvoidanceParams; i++)
            {
                crowd.SetAvoidanceConfig(i, CrowdAvoidanceConfig[i]);
            }
            NavGroup mGroup = new NavGroup(navmesh, query, crowd, crowd.QueryFilter, mExtents, false);

            int count = AgentGroupSettingManager.GetGroupCount();
            Dictionary <byte, NavAgentGroups> mAgentGroups = new Dictionary <byte, NavAgentGroups>(count);

            for (int i = 0; i < count; i++)
            {
                byte           groupId;
                NavAgentGroups group = AgentGroupSettingManager.CreateAgentGroup(i, mMaxPath, mMaxStraightPath, out groupId);
                group.angleAt         = mAngleAt;
                group.heightTolerance = mHeightTolerance;
                group.turnThreshold   = mTurnThreshold;

                mAgentGroups.Add(groupId, group);
            }
            return(NavManager.Create(mMaxAgents, mGroup, mAgentGroups));
        }