public ExtractedTerrainManager(string dataPath, TileIdentifier tileId) { _mapId = tileId.MapId; _baseDirectory = dataPath; _adtManager = new ExtractedADTManager(this, _baseDirectory, _mapId); _m2Manager = new ExtractedM2Manager(_baseDirectory, _mapId); _wmoManager = new ExtractedWMOManager(_baseDirectory, _mapId); _meshManager = new NavMeshManager(); _selectedTriangleManager = new SelectedTriangleManager(_adtManager); }
void Awake() { if (singleton == null) { singleton = this; } else { Debug.LogError("Duplicate NavMeshManager!"); } }
private void Awake() { if (main != null && main != this) { Destroy(this); } if (main == null) { main = this; } NavMap = GetComponent <NodeMap>(); }
public override void OnInspectorGUI() { DrawDefaultInspector(); NavMeshManager manager = (NavMeshManager)target; if (GUILayout.Button("Show Unpathable")) { manager.EnableMeshes(_goList); } if (GUILayout.Button("Hide Unpathable")) { manager.DisableMeshes(_goList); } }
/// <summary> /// Resets the game world. /// Removes and reloads all entities. /// </summary> public void resetWorld() { if (fileLoadedFrom == null) { return; } entityManager.player.deleteBody(name); physicsWorld = new Box2D.XNA.World(new Vector2(0, 0f), true); physicsWorld.ContactFilter = new PCContactFilter(); navStuff = new NavMeshManager((int)sizeInPixels.X, (int)sizeInPixels.Y, game); viewport = new Viewport(0, 0, game.GraphicsDevice.Viewport.Width, game.GraphicsDevice.Viewport.Height); entities = new List <Entity>(); bodyDict = new Dictionary <string, Body>(); checkpoints = new List <Vector2>(); idsOfThingsThatDontCollideWithThePlayer = new List <string>(); loadGameWorld(fileLoadedFrom); entityManager.player.enteringWorld = 24; }
void DrawLine() { if (isFindPath) { Profiler.BeginSample(" FindPath"); var time = DateTime.Now; //pathPoints = NavMesh.FindPath(srcPoint.position.ToLVector3(), dstPoint.position.ToLVector3(), path); pathPoints = NavMeshManager.FindPath(srcPoint.position.ToLVector3(), dstPoint.position.ToLVector3()); useTime = (float)(DateTime.Now - time).TotalMilliseconds; Profiler.EndSample(); //isDrawLine = false; } var graph = NavMesh.navMeshGraphPath; if (graph != null) { if (isShowPathResult) { ShowResult(graph); } if (isShowPathProgress) { ShowProgress(graph); } if (isShowAllTriangles) { ShowAllTriangles(graph); } if (isShowTriangleArea) { ShowAllConnections(graph); } if (isShowSingleTriangleConnection) { ShowOneTriangleConnections(graph); } } lineRenderer.positionCount = pathPoints.Count; lineRenderer.widthMultiplier = widthMultiplier; lineRenderer.SetPositions(pathPoints.ToArray().ToVecArray()); }
/// <summary> /// Constructor /// </summary> /// <param name="_game"></param> public GameWorld(Game _game, float width, float height, int tileWidth, String _name) { sizeInPixels = new Vector2(width * tileWidth, height * tileWidth); game = _game; entityManager = EntityManager.getEntityManager(game); entities = new List <Entity>(); physicsWorld = new Box2D.XNA.World(new Vector2(0, 0f), true); physicsWorld.ContactFilter = new PCContactFilter(); physicsWorld.ContactListener = new PCContactListener(); navStuff = new NavMeshManager((int)sizeInPixels.X, (int)sizeInPixels.Y, game); viewport = new Viewport(0, 0, game.GraphicsDevice.Viewport.Width, game.GraphicsDevice.Viewport.Height); name = _name; bodyDict = new Dictionary <string, Body>(); idsOfThingsThatDontCollideWithThePlayer = new List <string>(); entered = false; walls = new bool[4]; checkpoints = new List <Vector2>(); aiDict = new Dictionary <string, AIBase>(); }
//Canvia el material del edificio y setea el nodo a construido public void BuildBuilding(MeshRenderer[] actualMat) { Renderer[] childRenderer = availableBuilding.transform.GetComponentsInChildren <MeshRenderer>(); for (int i = 0; i < childRenderer.Length; i++) { childRenderer[i].material = actualMat[i].sharedMaterial; } SetIsBuilt(true); availableBuilding.transform.tag = "Building"; var navMeshSurface = availableBuilding.GetComponent <NavMeshSurface>(); if (navMeshSurface != null) { NavMeshManager.CalculateNavMesh(navMeshSurface); } if (myBuildingType.GetBuildingType() == BuildingType.EBuildingType.PIPE) { NavMeshManager.AddPipe(myBuildingType.GetComponent <PipeRoom>()); NavMeshManager.CalculateOffMeshLinks(); } }
private void Awake() { instance = this; }
public NavCrowdMapInstance(NavMeshManager navMeshManager) { _NavMeshManager = navMeshManager; Debug.Assert(_NavMeshManager.IsInited); }
public bool CreateNavMesh() { if (_LineGameObj != null) { GameObject.Destroy(_LineGameObj); _LineGameObj = null; } if (_LineGameObj == null) { _LineGameObj = new GameObject("LineGameObj"); } for (int i = 0; i < _navMeshGameObjList.Count; ++i) { GameObject go = _navMeshGameObjList[i]; if (go != null) { GameObject.Destroy(go); } } _navMeshGameObjList.Clear(); LineRenderer lineRenderer = _LineGameObj.AddComponent <LineRenderer>(); lineRenderer.useWorldSpace = true; lineRenderer.startWidth = 0.05f; lineRenderer.endWidth = 0.05f; lineRenderer.enabled = false; CUnityUtil.DisableLightAndShadow(lineRenderer); //ground { LuaInterface.SamplePolyAreas area = LuaInterface.SamplePolyAreas.SAMPLE_POLYAREA_GROUND; Vector3[] vertices; int[] triangles; //Load NavMesh { int vCont; int iCont; NavMeshManager m_navMeshMan = NavMeshManager.Instance; m_navMeshMan.GetNavMeshVertexIndexCount(out vCont, out iCont, area); vertices = new Vector3[vCont]; triangles = new int[iCont]; m_navMeshMan.FillNavMeshVertexIndexBuffer(vertices, vCont, triangles, iCont, area); } CUnityUtil.SMeshData meshData = new CUnityUtil.SMeshData(); meshData.vertices = vertices; meshData.indices = triangles; List <CUnityUtil.SMeshData> listMeshData = new List <CUnityUtil.SMeshData>(); CUnityUtil.SplitMeshData(meshData, listMeshData); Color color = new Color(0, 0.75f, 1.0f); for (int i = 0; i < listMeshData.Count; ++i) { GameObject go = new GameObject(HobaText.Format("NavMeshGameObj_{0}_{1}", (int)area, i)); MeshRenderer meshRenderer = go.AddComponent <MeshRenderer>(); meshRenderer.enabled = false; meshRenderer.name = HobaText.Format("MeshRenderer_{0}_{1}", (int)area, i); meshRenderer.material.shader = Shader.Find("Legacy Shaders/Bumped Diffuse"); meshRenderer.material.color = color; CUnityUtil.DisableLightAndShadow(meshRenderer); MeshFilter meshFilter = go.AddComponent <MeshFilter>(); meshFilter.sharedMesh = new Mesh(); meshFilter.sharedMesh.name = HobaText.Format("MeshFilterMesh_{0}_{1}", (int)area, i); meshFilter.sharedMesh.vertices = listMeshData[i].vertices; meshFilter.sharedMesh.triangles = listMeshData[i].indices; _navMeshGameObjList.Add(go); } } //grass { LuaInterface.SamplePolyAreas area = LuaInterface.SamplePolyAreas.SAMPLE_POLYAREA_GRASS; Vector3[] vertices; int[] triangles; //Load NavMesh { int vCont; int iCont; NavMeshManager m_navMeshMan = NavMeshManager.Instance; m_navMeshMan.GetNavMeshVertexIndexCount(out vCont, out iCont, area); vertices = new Vector3[vCont]; triangles = new int[iCont]; m_navMeshMan.FillNavMeshVertexIndexBuffer(vertices, vCont, triangles, iCont, area); } CUnityUtil.SMeshData meshData = new CUnityUtil.SMeshData(); meshData.vertices = vertices; meshData.indices = triangles; List <CUnityUtil.SMeshData> listMeshData = new List <CUnityUtil.SMeshData>(); CUnityUtil.SplitMeshData(meshData, listMeshData); Color color = new Color(0, 0.75f, 0.25f); for (int i = 0; i < listMeshData.Count; ++i) { GameObject go = new GameObject(HobaText.Format("NavMeshGameObj_{0}_{1}", (int)area, i)); MeshRenderer meshRenderer = go.AddComponent <MeshRenderer>(); meshRenderer.enabled = false; meshRenderer.name = HobaText.Format("MeshRenderer_{0}_{1}", (int)area, i); meshRenderer.material.shader = Shader.Find("Legacy Shaders/Bumped Diffuse"); meshRenderer.material.color = color; CUnityUtil.DisableLightAndShadow(meshRenderer); MeshFilter meshFilter = go.AddComponent <MeshFilter>(); meshFilter.sharedMesh = new Mesh(); meshFilter.sharedMesh.name = HobaText.Format("MeshFilterMesh_{0}_{1}", (int)area, i); meshFilter.sharedMesh.vertices = listMeshData[i].vertices; meshFilter.sharedMesh.triangles = listMeshData[i].indices; _navMeshGameObjList.Add(go); } } //road { LuaInterface.SamplePolyAreas area = LuaInterface.SamplePolyAreas.SAMPLE_POLYAREA_ROAD; Vector3[] vertices; int[] triangles; //Load NavMesh { int vCont; int iCont; NavMeshManager m_navMeshMan = NavMeshManager.Instance; m_navMeshMan.GetNavMeshVertexIndexCount(out vCont, out iCont, area); vertices = new Vector3[vCont]; triangles = new int[iCont]; m_navMeshMan.FillNavMeshVertexIndexBuffer(vertices, vCont, triangles, iCont, area); } CUnityUtil.SMeshData meshData = new CUnityUtil.SMeshData(); meshData.vertices = vertices; meshData.indices = triangles; List <CUnityUtil.SMeshData> listMeshData = new List <CUnityUtil.SMeshData>(); CUnityUtil.SplitMeshData(meshData, listMeshData); Color color = new Color(0.75f, 0.25f, 0f); for (int i = 0; i < listMeshData.Count; ++i) { GameObject go = new GameObject(HobaText.Format("NavMeshGameObj_{0}_{1}", (int)area, i)); MeshRenderer meshRenderer = go.AddComponent <MeshRenderer>(); meshRenderer.enabled = false; meshRenderer.name = HobaText.Format("MeshRenderer_{0}_{1}", (int)area, i); meshRenderer.material.shader = Shader.Find("Legacy Shaders/Bumped Diffuse"); meshRenderer.material.color = color; CUnityUtil.DisableLightAndShadow(meshRenderer); MeshFilter meshFilter = go.AddComponent <MeshFilter>(); meshFilter.sharedMesh = new Mesh(); meshFilter.sharedMesh.name = HobaText.Format("MeshFilterMesh_{0}_{1}", (int)area, i); meshFilter.sharedMesh.vertices = listMeshData[i].vertices; meshFilter.sharedMesh.triangles = listMeshData[i].indices; _navMeshGameObjList.Add(go); } } //Default false /* showNavMesh(true);*/ return(true); }
public async Task <Task> InitializeAsync() { Checksum = ZoneInfo.LuzFile.GenerateChecksum(ZoneInfo.LvlFiles); Logger.Information($"Checksum: 0x{Checksum:X}"); Logger.Information($"Collecting objects for {ZoneId}"); var objects = new List <LevelObjectTemplate>(); foreach (var lvlFile in ZoneInfo.LvlFiles.Where(lvlFile => lvlFile.LevelObjects?.Templates != default)) { objects.AddRange(lvlFile.LevelObjects.Templates); } Logger.Information($"Loading {objects.Count} objects for {ZoneId}"); NavMeshManager = new NavMeshManager(this, UchuServer.Config.GamePlay.PathFinding); if (NavMeshManager.Enabled) { Logger.Information("Generating navigation way points."); await NavMeshManager.GeneratePointsAsync(); Logger.Information("Finished generating navigation way points."); } ZoneId = (ZoneId)ZoneInfo.LuzFile.WorldId; SpawnPosition = ZoneInfo.LuzFile.SpawnPoint; SpawnRotation = ZoneInfo.LuzFile.SpawnRotation; ZoneInfo.LvlFiles = new List <LvlFile>(); ZoneInfo.TerrainFile = default; GC.Collect(); foreach (var levelObject in objects) { if (levelObject.LegoInfo.TryGetValue("trigger_id", out var trigger)) { Logger.Information($"Trigger: {trigger}"); } Logger.Debug($"Loading {levelObject.Lot} [{levelObject.ObjectId}]..."); try { SpawnLevelObject(levelObject); } catch (Exception e) { Logger.Error(e); } } Logger.Information($"Loaded {GameObjects.Length}/{objects.Count} for {ZoneId}"); if (ZoneInfo.LuzFile.PathData != default) { foreach (var path in ZoneInfo.LuzFile.PathData.OfType <LuzSpawnerPath>()) { Logger.Information($"Loading {path.PathName}"); try { SpawnPath(path); } catch (Exception e) { Logger.Error(e); } } } Logger.Information($"Loaded {Objects.Length} objects for {ZoneId}"); // // Load zone scripts // await ScriptManager.LoadDefaultScriptsAsync(); foreach (var scriptPack in ScriptManager.ScriptPacks) { try { Logger.Information($"Running: {scriptPack.Name}"); await scriptPack.LoadAsync(); } catch (Exception e) { Logger.Information(e); } } Loaded = true; objects.Clear(); return(ExecuteUpdateAsync()); }
void OnDestroy() { singleton = null; }