Пример #1
0
        public void WriteVData()
        {
            if (vd == null)
            {
                if (workFile != "")
                {
                    vd = VolumeData.GetVData(workFile + "_vData.asset");
                }
                else
                {
                    string sPath = Application.dataPath + PathCollect.resourcesPath.Substring(6) + PathCollect.save;
                    sPath = EditorUtility.SaveFilePanel("save vData", sPath, volume.name + "_vData", "asset");
                    sPath = sPath.Substring(sPath.LastIndexOf(PathCollect.resourceSubPath));
                    vd    = VolumeData.GetVData(sPath);
                }

                vd.chunkX     = chunkX;
                vd.chunkY     = chunkY;
                vd.chunkZ     = chunkZ;
                vd.chunkDatas = new List <ChunkData> ();
                foreach (Chunk _chunk in chunks.Values)
                {
                    WorldPos _pos = _chunk.cData.ChunkPos;

                    ChunkData newChunkData = new ChunkData();
                    newChunkData.ChunkPos   = _pos;
                    newChunkData.blocks     = _chunk.cData.blocks;
                    newChunkData.blockAirs  = _chunk.cData.blockAirs;
                    newChunkData.blockHolds = _chunk.cData.blockHolds;

                    vd.chunkDatas.Add(newChunkData);
                    _chunk.cData = newChunkData;
                }
            }
        }
Пример #2
0
        public static VolumeData GetVData(string workFile)
        {
            VolumeData _vData = Resources.Load(workFile, typeof(VolumeData)) as VolumeData;

                        #if UNITY_EDITOR
            if (_vData == null)
            {
                string     bytesPath = PathCollect.resourcesPath + workFile;
                VolumeData vd        = ScriptableObject.CreateInstance <VolumeData> ();
                UnityEditor.AssetDatabase.CreateAsset(vd, bytesPath);
                UnityEditor.AssetDatabase.Refresh();
                _vData = Resources.Load(workFile.Replace(".asset", ""), typeof(VolumeData)) as VolumeData;
            }
                        #endif
            return(_vData);
        }
Пример #3
0
        public void BuildVolume(Save _save, VolumeData _VData = null)
        {
            if (_VData == null && _useBytes == false)
            {
                return;
            }
            Reset();

            if (_useBytes)               //load .bytes
            {
                vd = null;
                Init(_save.chunkX, _save.chunkY, _save.chunkZ);
                foreach (var blockPair in _save.blocks)
                {
                    Block block = blockPair.Value;
                    if (block != null)
                    {
                        if (block is BlockAir)
                        {
                            BlockAir bAir = blockPair.Value as BlockAir;
                            if (!RemoveNodeIfIsEmpty(bAir.BlockPos))
                            {
                                SetBlock(blockPair.Key.x, blockPair.Key.y, blockPair.Key.z, bAir);
                            }
                            else
                            {
                                Debug.Log(bAir.BlockPos);
                            }
                        }
                        else
                        {
                            SetBlock(blockPair.Key.x, blockPair.Key.y, blockPair.Key.z, new Block());
                        }
                    }
                }
            }
            else                 //load ScriptableObject
            {
                Init(_VData.chunkX, _VData.chunkY, _VData.chunkZ);
                foreach (Chunk c in chunks.Values)
                {
                    c.cData = _VData.GetChunk(c.cData.ChunkPos);
                }
            }
            PlacePieces();
            UpdateChunks();
        }
Пример #4
0
        void OnEnable()
        {
            vd       = (VolumeData)target;
            defColor = GUI.color;
            volColor = new Color(0.5f, 0.8f, 0.75f);

            cb = new BlockBool[vd.chunkDatas.Count];
            for (int i = 0; i < cb.Length; i++)
            {
                cb [i].blocks     = new bool[vd.chunkDatas [i].blocks.Count];
                cb [i].blockAirs  = new bool[vd.chunkDatas [i].blockAirs.Count];
                cb [i].blockHolds = new bool[vd.chunkDatas [i].blockHolds.Count];
                cb[i].layerMin    = 0;
                cb[i].layerMax    = Chunk.chunkSize;
            }
            UpdateList();
        }
Пример #5
0
        private static void AddVolume()
        {
            GameObject newVol = new GameObject();

            newVol.name = "New Volume";
            newVol.AddComponent <Volume> ();
            Volume volume = newVol.GetComponent <Volume> ();

            volume.Reset();
            volume.Init(1, 1, 1);
            volume.workFile = "";
            volume.tempPath = "";
            string sPath = Application.dataPath + PathCollect.resourcesPath.Substring(6) + PathCollect.save;

            sPath            = EditorUtility.SaveFilePanel("save vData", sPath, volume.name + "_vData", "asset");
            sPath            = sPath.Substring(sPath.LastIndexOf(PathCollect.resourceSubPath));
            volume.vd        = VolumeData.GetVData(sPath);
            volume._useBytes = false;
            volume.BuildVolume(new Save(), volume.vd);
        }