示例#1
0
    public ChunkData LoadChunk(ChunkTransform chunkTransform)
    {
        string path = Application.persistentDataPath
                      + "/" + worldName
                      + "/Chunks"
                      + "/" + terrainId
                      + "/" + chunkTransform.ToString()
                      + ".chk";

        // Make sure file exists
        FileStream file;

        if (File.Exists(path))
        {
            file = File.OpenRead(path);
        }
        else
        {
            Debug.LogError(chunkTransform.ToString() + " - File not found");
            return(null);
        }

        // Load and close
        BinaryFormatter formatter = new BinaryFormatter();
        ChunkData       chunkData = (ChunkData)formatter.Deserialize(file);

        file.Close();

        return(chunkData);
    }
示例#2
0
    public bool ChunkFileExists(ChunkTransform chunkTransform)
    {
        string path = Application.persistentDataPath
                      + "/" + worldName
                      + "/Chunks"
                      + "/" + terrainId
                      + "/" + chunkTransform.ToString()
                      + ".chk";

        return(File.Exists(path));
    }
示例#3
0
    // Returns chunk that is currently in the game hierarchy
    // Returns null if the chunk is not loaded
    public Chunk GetChunk(ChunkTransform chunkTransform)
    {
        Transform t = parentOfChunks.transform.Find(chunkTransform.ToString());

        if (t == null)
        {
            return(null);
        }

        return(t.GetComponent <Chunk>());
    }
    VoxelChunk GetChunk(Transform ChunkContainer, Vector3 vPos, bool bCreate, int iSize = 27)
    {
        Transform ChunkTransform;

        vPos = ChunkContainer.InverseTransformPoint(vPos) * ChunkContainer.localScale.x;

        /*Vector3 vINT;
         * vINT.x = Mathf.Clamp(Mathf.RoundToInt(pPos.x/Size),-1,1);
         * vINT.y = Mathf.Clamp(Mathf.RoundToInt(pPos.y/Size),-1,1);
         * vINT.z = Mathf.Clamp(Mathf.RoundToInt(pPos.z/Size),-1,1);
         */
        ChunkTransform = ChunkContainer.FindChild(vPos.ToString());

        if (ChunkTransform == null && bCreate)
        {
            //Debug.Log("Create NEW Chunk");

            /*GameObject ChunkObject = new GameObject(pPos.ToString(),typeof(MeshRenderer), typeof(MeshFilter),typeof(MeshCollider), typeof(VChunk));
             * ChunkObject.transform.parent = transform;
             * ChunkObject.GetComponent<MeshRenderer>().material =  _material;
             * ChunkObject.transform.localScale = Scale;
             * ChunkObject.transform.localPosition = pPos;
             */
            VoxelChunk c = NewChunk(ChunkContainer, vPos, iSize);
            if (c == null)
            {
                Debug.LogWarning("NULL creation!");
            }
            return(c);
        }
        else
        {
            //Debug.Log("Get Chunk "+ChunkTransform.GetComponent<VChunk>());
            if (ChunkTransform == null)
            {
                return(null);
            }
            return(ChunkTransform.GetComponent <VoxelChunk>());
        }
    }
示例#5
0
 public Random ChunkBuild(ChunkTransform chunkTransform)
 {
     return(new Random(IntegerAt(3) + IntegerAt(1) + chunkTransform.x + chunkTransform.z * 2));
 }
示例#6
0
 public void SetTransform(ChunkTransform chunkTransform)
 {
     this.chunkTransform = chunkTransform;
     chunkData           = new ChunkData();
 }