private void Awake() { if (NavCubeWorld.Exist(gameObject.scene)) { navCube = NavCubeWorld.Load(gameObject.scene); } }
public NavCubeWorld LoadWorld() { if (NavCubeWorld.Exist(gameObject.scene)) { return(NavCubeWorld.Load(gameObject.scene)); } return(null); }
private void OnDisable() { NavCubeWorld world = LoadWorld(); if (world != null) { world.RemoveLink(this); } }
private void OnEnable() { NavCubeWorld world = LoadWorld(); if (world != null) { world.AddLink(this); } }
private void Start() { _positionA = transform.position.FloorToInt(); NavCubeWorld world = LoadWorld(); if (world != null) { world.AddLink(this); } }
public void LoadWorld() { if (world != null) { return; } if (NavCubeWorld.Exist(gameObject.scene)) { world = NavCubeWorld.Load(gameObject.scene); } }
public NavCubeChunk(NavCubeWorld world) { data = new NavCubeData[NavCube_ChunkSize, NavCube_ChunkSize, NavCube_ChunkSize]; for (int x = 0; x < NavCube_ChunkSize; x++) { for (int y = 0; y < NavCube_ChunkSize; y++) { for (int z = 0; z < NavCube_ChunkSize; z++) { data[x, y, z] = new NavCubeData(); } } } }
public void MakeRender() { chunkRenderNav.Clear(); NavCubeWorld world = LoadWorld(); if (world == null) { return; } chunkRenderNav.Add(new List <Matrix4x4>()); if (world.chunks == null) { return; } Vector3 offset = Vector3.one * 0.5f; Vector3 size = offset * 0.5f; foreach (NavCubeChunk chunk in world.chunks) { Vector3Int position = chunk.position * NavCubeChunk.NavCube_ChunkSize; for (int x = 0; x < NavCubeChunk.NavCube_ChunkSize; x++) { for (int y = 0; y < NavCubeChunk.NavCube_ChunkSize; y++) { for (int z = 0; z < NavCubeChunk.NavCube_ChunkSize; z++) { //if (chunk.data[x, y, z] != (int)NavCubeType.Blocked) if (chunk.GetData(x, y, z).type != NavCubeType.Blocked) { continue; } List <Matrix4x4> chunkMatrices = chunkRenderNav[chunkRenderNav.Count - 1]; if (chunkMatrices.Count >= 1000) { chunkMatrices = new List <Matrix4x4>(); chunkRenderNav.Add(chunkMatrices); } chunkMatrices.Add(Matrix4x4.TRS( position + new Vector3(x, y, z) + offset, Quaternion.identity, size )); } } } } }
IEnumerator BakeWorld(NavCube navCube, Vector3Int origin, Vector3Int numberChunk, string folderPath) { NavCubeChunk currentChunk; Vector3Int currentChunkPos = new Vector3Int(); NavCubeWorld ncw = NavCubeWorld.LoadOrCreate(folderPath); //LoadOrCreateWorld(folderPath); navCube.world = ncw; //ncw.chunks.Clear(); for (int x = 0; x < numberChunk.x; x++) { currentChunkPos.x = x + origin.x; for (int y = 0; y < numberChunk.y; y++) { currentChunkPos.y = y + origin.y; for (int z = 0; z < numberChunk.z; z++) { currentChunkPos.z = z + origin.z; currentChunk = ncw.LoadOrCreateChunk(currentChunkPos); yield return(navCube.BakeChunk(currentChunk)); ncw.SaveChunk(currentChunk); //EditorUtility.SetDirty(currentChunk); } } } //AssetDatabase.SaveAssets(); //AssetDatabase.Refresh(); yield return(null); IsBaking = false; //navCube.MakeNavCubeRender(); SceneView.RepaintAll(); }
private void OnDrawGizmosSelected() { NavCubeWorld world = LoadWorld(); if (world == null) { return; } Gizmos.color = Color.red; foreach (NavCubeChunk chunk in world.chunks) { Vector3 position = chunk.position * NavCubeChunk.NavCube_ChunkSize; Vector3 size = Vector3.one * NavCubeChunk.NavCube_ChunkSize; Gizmos.DrawWireCube( position + size / 2.0f, size ); } }
public static NavCubeWorld LoadOrCreate(string pathfolder) { if (loadedNavCube == null) { loadedNavCube = new Dictionary <string, NavCubeWorld>(); } string filePath = $"{Application.streamingAssetsPath}/{pathfolder}/ncw.nc"; if (File.Exists(filePath)) { return(Load(pathfolder)); } else { NavCubeWorld world = new NavCubeWorld(); world.folder = pathfolder; world.Save(); loadedNavCube.Add(pathfolder, world); return(world); } }