コード例 #1
0
    public NavManager CreateManager()
    {
        if (!(mNavmeshData && NavmeshData.HasNavmesh))
        {
            Debug.LogError(name + ": Aborted initialization. Navigation mesh not available.");
            return(null);
        }

        if (!mAvoidanceSet || !mGroupsSettings)
        {
            Debug.LogError(
                name + ": Aborted initialization. Avoidance and/or agent groups not available.");
            return(null);
        }

        Navmesh      navmesh = NavmeshData.GetNavmesh();
        NavmeshQuery query;
        NavStatus    status = NavmeshQuery.Create(navmesh, mMaxQueryNodes, out query);

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

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

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

        for (int i = 0; i < CrowdManager.MaxAvoidanceParams; i++)
        {
            crowd.SetAvoidanceConfig(i, mAvoidanceSet[i]);
        }

        NavGroup mGroup = new NavGroup(navmesh, query, crowd, crowd.QueryFilter, mExtents, false);

        int count = mGroupsSettings.GroupCount;
        Dictionary <byte, NavAgentGroup> mAgentGroups = new Dictionary <byte, NavAgentGroup>(count);

        for (int i = 0; i < count; i++)
        {
            byte          groupId;
            NavAgentGroup group =
                mGroupsSettings.CreateAgentGroup(i, mMaxPath, mMaxStraightPath, out groupId);

            group.angleAt         = mAngleAt;
            group.heightTolerance = mHeightTolerance;
            group.radiusAt        = mRadiusAt;
            group.radiusNear      = mRadiusNear;
            group.turnThreshold   = mTurnThreshold;

            mAgentGroups.Add(groupId, group);
        }

        return(NavManager.Create(mMaxAgents, mGroup, mAgentGroups));
    }
コード例 #2
0
    public void CreateQuery(float fMoveSpeed, float fTurnSpeed)
    {
        this.mTurnSpeed = fTurnSpeed;
        this.mMoveSpeed = fMoveSpeed;
        NavStatus status = NavmeshQuery.Create(navmesh, mMaxQueryNodes, out query);

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

        mCrowdManager = CrowdManager.Create(mMaxCrowdAgents, mMaxAgentRadius, navmesh);
        if (mCrowdManager == null)
        {
            Debug.LogError(fileName + ": Aborted initialization. Failed crowd creation.");
        }

        CrowdAvoidanceParams mCrowdParam = CrowdAvoidanceParams.CreateStandardMedium();

        mCrowdManager.SetAvoidanceConfig(0, mCrowdParam);
        mCrowdAgentParams = new CrowdAgentParams();
        mCrowdAgentParams.avoidanceType       = 0;
        mCrowdAgentParams.collisionQueryRange = 3.2f;
        mCrowdAgentParams.height                = 1.8f;
        mCrowdAgentParams.maxAcceleration       = 8.0f;
        mCrowdAgentParams.maxSpeed              = this.mMoveSpeed;
        mCrowdAgentParams.pathOptimizationRange = 12.0f;
        mCrowdAgentParams.radius                = 1.0f;
        mCrowdAgentParams.separationWeight      = 2.0f;
        mCrowdAgentParams.updateFlags           = CrowdUpdateFlags.AnticipateTurns | CrowdUpdateFlags.ObstacleAvoidance | CrowdUpdateFlags.CrowdSeparation | CrowdUpdateFlags.OptimizeVis | CrowdUpdateFlags.OptimizeTopo;

        polyResult        = new uint[300];
        pointResult       = new Vector3[300];
        tileBufferPoints  = new Vector3[3000];
        pointResultBuffer = new Vector3[300];
        polyResultBuffer  = new uint[300];
        NavmeshTile tile  = navmesh.GetTile(0);
        int         count = tile.GetVerts(tileBufferPoints);

        Debug.Log("Tile " + tile.GetTileRef() + " count:" + count);
        if (count > 3000)
        {
            tileBufferPoints = new Vector3[count];
        }
        tileBufferRef = -1;

        //NavmeshPoly[] polys=new NavmeshPoly[3000];
        //int polyCount;
        //polyCount=tile.GetPolys(polys);
        //for (int i = 0; i < polyCount; i++)
        //{
        //    NavmeshPoly poly = polys[i];
        //    //if (poly.Type == NavmeshPolyType.OffMeshConnection)
        //    {
        //        Debug.Log("Poly" + i+"type"+poly.Type.ToString());
        //    }
        //}
    }
コード例 #3
0
 public void Init()
 {
     Clear();
     m_Mgr = CrowdManager.Create(m_MaxAgent, m_MaxAgentRadius, m_NavMesh);
     AddQuailty(m_DefaultQuality, false);
 }
コード例 #4
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));
        }