public NavAgentGroup CreateAgentGroup(int index, int maxPath, int maxStraightPath , out byte group) { group = mGroups[index * 2 + 0]; CrowdAgentParams cap = new CrowdAgentParams(); cap.avoidanceType = mGroups[index * 2 + 1]; cap.collisionQueryRange = mGroupData[index * GroupStide + QueryOffset]; cap.height = mGroupData[index * GroupStide + HeightOffset]; cap.maxAcceleration = mGroupData[index * GroupStide + AccelOffset]; cap.maxSpeed = mGroupData[index * GroupStide + JogOffset]; cap.pathOptimizationRange = mGroupData[index * GroupStide + OptiOffset]; cap.radius = mGroupData[index * GroupStide + RadiusOffset]; cap.separationWeight = mGroupData[index * GroupStide + SepOffset]; cap.updateFlags = mUpdateFlags[index]; NavAgentGroup result = new NavAgentGroup( cap, maxPath, maxStraightPath, mPoolData[index * 2 + 0], mPoolData[index * 2 + 1]); result.jogSpeed = mGroupData[index * GroupStide + JogOffset]; result.maxTurnSpeed = mGroupData[index * GroupStide + TurnOffset]; result.runSpeed = mGroupData[index * GroupStide + RunOffset]; result.walkSpeed = mGroupData[index * GroupStide + WalkOffset]; return(result); }
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)); }