void Awake() { NavManagerProvider provider = (NavManagerProvider)FindObjectOfType(typeof(NavManagerProvider)); if (provider == null) { Debug.LogError(string.Format("{0}: There is no {1} in the scene." , name, typeof(NavManagerProvider).Name)); return; } NavManager manager = provider.CreateManager(); if (manager == null) { Debug.LogError(string.Format("{0}: Could not get the navigation manager.", name)); return; } mHelper = manager.NavGroup; //mPath = new BufferHandler<uint>(); isInit = true; }
/// <summary> /// Copy constructor. /// </summary> /// <param name="copy">The group to copy.</param> /// <param name="cloneFilter"> /// If true, the filter will be cloned. Otherwise it will be referenced. /// </param> public NavGroup(NavGroup copy, bool cloneFilter) { this.mesh = copy.mesh; this.query = copy.query; this.crowd = copy.crowd; this.filter = (cloneFilter ? copy.filter.Clone() : copy.filter); this.extents = copy.extents; }
/// <summary> /// Constructor /// </summary> /// <param name="group">The navigation mesh group the agent /// belongs to.</param> /// <param name="transform">The agent's transform.</param> public NavAgent(Transform transform, NavGroup navGroup, NavAgentGroup agentGroup) { this.agentGroup = agentGroup; this.navGroup = new NavGroup(navGroup, false); this.transform = transform; this.wideExtents = navGroup.extents * 10; RevertToAgentGroup(); }
private NavManager(int maxAgents , NavGroup navGroup, Dictionary<byte, NavAgentGroup> agentGroups) { maxAgents = Mathf.Max(1, maxAgents); mPlanners = new IState[maxAgents]; mMovers = new IState[maxAgents]; mNavGroup = navGroup; mAgentGroups = new Dictionary<byte, NavAgentGroup>(agentGroups); }
private NavManager(int maxAgents , NavGroup navGroup, Dictionary <byte, NavAgentGroup> agentGroups) { maxAgents = Mathf.Max(1, maxAgents); mPlanners = new IState[maxAgents]; mMovers = new IState[maxAgents]; mNavGroup = navGroup; mAgentGroups = new Dictionary <byte, NavAgentGroup>(agentGroups); }
private bool FindPath( NavGroup helper , ref Vector3 start , ref Vector3 end ) { NavmeshPoint startPoint, endPoint; helper.query.GetNearestPoint(start, helper.extents, helper.filter, out startPoint); helper.query.GetNearestPoint(end, helper.extents, helper.filter, out endPoint); float hitPar; int hitCount; Vector3 hitNor; helper.query.Raycast(startPoint, end, helper.filter, out hitPar, out hitNor, mPath, out hitCount); if (hitNor.x != 0f || hitNor.y != 0f) { // 多路径 helper.query.FindPath(ref startPoint, ref endPoint, helper.extents, helper.filter, mPath, out hitCount); helper.query.GetStraightPath(start, end, mPath, 0, hitCount, mStraightPath, null, null, out mStraightCount); mStraightIndex = 0; while (mStraightIndex < mStraightCount && (Mathf.Abs(mStraightPath[mStraightIndex].x - start.x) < 0.001f && Mathf.Abs(mStraightPath[mStraightIndex].y - start.y) < 0.001f)) mStraightIndex++; //if (mStraightIndex < mStraightCount) //{ //} //else //{ //} } else { // 单一路经 mStraightCount = 1; mStraightIndex = 0; mStraightPath[0] = end; } return true; //resultPath = new uint[] { }; //NavStatus status = helper.query.FindPath(ref startPoint, ref endPoint, helper.extents, helper.filter, mPath, out count); //if (NavUtil.Failed(status)) // return SearchResult.HitGeometry; //return SearchResult.HitNavmesh; }
public static NavManager Create(int maxAgents , NavGroup navGroup, Dictionary<byte, NavAgentGroup> agentGroups) { if (navGroup.crowd == null || navGroup.crowd.IsDisposed || navGroup.mesh == null || navGroup.mesh.IsDisposed || navGroup.query == null || navGroup.query.IsDisposed || agentGroups == null || agentGroups.Count == 0) { return null; } return new NavManager(maxAgents, navGroup, agentGroups); }
public static NavManager Create(int maxAgents , NavGroup navGroup, Dictionary <byte, NavAgentGroup> agentGroups) { if (navGroup.crowd == null || navGroup.crowd.IsDisposed || navGroup.mesh == null || navGroup.mesh.IsDisposed || navGroup.query == null || navGroup.query.IsDisposed || agentGroups == null || agentGroups.Count == 0) { return(null); } return(new NavManager(maxAgents, navGroup, agentGroups)); }
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); }
private SearchResult NearestPoint( NavGroup helper , ref Vector3 geomPoint , out NavmeshPoint navPoint ) { NavStatus status = helper.query.GetNearestPoint(hitPosition, helper.extents, helper.filter, out navPoint); if (NavUtil.Failed(status)) return SearchResult.HitGeometry; if (navPoint.polyRef == 0) { return SearchResult.HitGeometry; } return SearchResult.HitNavmesh; }