public void Init(ChunkPrimer chunk) { Debug.Assert(_chunk == null); _chunk = chunk; _chunk.dirty = _dirty = false; _chunk.OnChunkChange += OnBuildChunk; this.OnBuildChunkAsync(); }
public static bool Save(string path, ChunkPrimer map) { UnityEngine.Debug.Assert(map != null); using (var stream = new FileStream(path, FileMode.Create, FileAccess.Write)) { var serializer = new BinaryFormatter(); serializer.Serialize(stream, map); } return(true); }
public override void OnInspectorGUI() { ChunkData data = (ChunkData)target; base.DrawDefaultInspector(); EditorGUILayout.HelpBox("Load & Save chunk of terrain from Asset", MessageType.Info); if (GUILayout.Button("Load...")) { var SelectedPath = EditorUtility.OpenFilePanel("Load Chunk", "", "asset"); if (SelectedPath.Length == 0) { return; } var map = ChunkPrimer.Load(SelectedPath); if (map != null) { data.chunk = map; data.OnBuildChunkAsync(); Debug.Log("Your data of chunk was loaded successfully"); } else { Debug.Log("load Failed"); } } if (GUILayout.Button("Save...")) { var SelectedPath = EditorUtility.SaveFilePanel("Save Chunk", "", "New Resource", "asset"); if (SelectedPath.Length == 0) { return; } var map = data.chunk; if (map != null) { if (ChunkPrimer.Save(SelectedPath, map)) { Debug.Log("Your data of chunk was saved successfully"); } else { Debug.Log("Save Failed"); } } } }
public void Set(int x, int y, int z, ChunkPrimer value) { lock (this) { if (_allocSize == 0) { this.Create(0xFF); } var index = HashInt(x, y, z) & _allocSize; var entry = _data[index]; while (entry != null) { var pos = entry.position; if (pos.x == x && pos.y == y && pos.z == z) { var element = _data[index].value; if (element != value && element != null) { element.InvokeOnChunkDestroy(); } _data[index].value = value; } index = (index + 1) & _allocSize; entry = _data[index]; } if (value != null) { _data[index] = new ChunkNode(new Vector3 <int>(x, y, z), value); _count++; if (_count >= _allocSize) { this.Grow(); } } } }
public bool Get(int x, int y, int z, out ChunkPrimer chunk) { Debug.Assert(_allocSize > 0); var index = HashInt(x, y, z) & _allocSize; var entry = _data[index]; while (entry != null) { var pos = entry.position; if (pos.x == x && pos.y == y && pos.z == z) { chunk = entry.value; return(chunk != null); } index = (index + 1) & _allocSize; entry = _data[index]; } chunk = null; return(false); }
public void Set(Vector3 <int> pos, ChunkPrimer value) { Set(pos.x, pos.y, pos.z, value); }
public bool Get(Vector3 <int> pos, out ChunkPrimer instanceID) { return(this.Get(pos.x, pos.y, pos.z, out instanceID)); }