コード例 #1
0
    //Load Menu Functions///////////////////////////////////////////////////////////////////////////////////////////////
    public GameObject LoadObject(string file, Vector3 position, Atlas[] atlas, Material material)
    {
        BinaryReader br;

        try {
            FileStream filestream = File.OpenRead("Assets/VoxelObjects/" + file + ".vox");
            br = new BinaryReader(filestream);
        }
        catch (IOException e) {
            Debug.Log(e.Message + " Cannot open file.");
            return(null);
        }
        try{
            //Load stuff
            VoxelFile.Name        = br.ReadString();
            VoxelFile.MaterialID  = br.ReadInt32();
            VoxelFile.VoxelSize.x = (float)br.ReadInt32();
            VoxelFile.VoxelSize.y = (float)br.ReadInt32();
            VoxelFile.VoxelSize.z = (float)br.ReadInt32();
            int p = (int)VoxelFile.VoxelSize.x * (int)VoxelFile.VoxelSize.y * (int)VoxelFile.VoxelSize.z;
            VoxelFile.VoxelData = new int[p];
            for (int x = 0; x < p; x++)
            {
                VoxelFile.VoxelData[x] = br.ReadInt32();
            }
            //Debug.Log(VoxelFile.Name + " loaded");
        }
        catch (IOException e) {
            Debug.Log(e.Message + " Cannot read from file.");
        }
        br.Close();


        return(NewVoxelMesh.BuildVoxelMesh(VoxelFile.VoxelData, VoxelFile.VoxelSize, position, atlas, material, 1));
    }
コード例 #2
0
    void AddVoxel()
    {
        Vector3 p = Highlighters[0].transform.position;

        p.x += (GridSize.x / 2) - 0.5f;
        p.z += (GridSize.z / 2) - 0.5f;

        //VoxelObject[(int)p.x + (int)GridSize.y * ((int)p.y + (int)GridSize.z * (int)p.z)] = CurrentColor;
        VoxelFile.VoxelData[((int)p.y * (int)GridSize.x + (int)p.x) + ((int)GridSize.x * (int)GridSize.y * (int)p.z)] = CurrentColor;
        if (GameObject.Find("Voxel Mesh") != null)
        {
            DestroyImmediate(GameObject.Find("Voxel Mesh"));
            NewVoxelMesh.BuildVoxelMesh(VoxelFile.VoxelData, GridSize, new Vector3(-(GridSize.x / 2), 0, -(GridSize.z / 2)), TextureAtlas, EditorMaterials[1], Mode);
        }
        else
        {
            NewVoxelMesh.BuildVoxelMesh(VoxelFile.VoxelData, GridSize, new Vector3(-(GridSize.x / 2), 0, -(GridSize.z / 2)), TextureAtlas, EditorMaterials[1], Mode);
        }
        Resources.UnloadUnusedAssets();
    }