예제 #1
0
    public override int GetRightIndexByData(NBTChunk chunk, int data)
    {
        switch (data)
        {
        case 0:
        case 8:
            return(TextureArrayManager.GetIndexByName("log_oak"));

        case 1:
        case 9:
            return(TextureArrayManager.GetIndexByName("log_spruce"));

        case 2:
        case 10:
            return(TextureArrayManager.GetIndexByName("log_birch"));

        case 3:
        case 11:
            return(TextureArrayManager.GetIndexByName("log_jungle"));

        case 4:
            return(TextureArrayManager.GetIndexByName("log_oak_top"));

        case 5:
            return(TextureArrayManager.GetIndexByName("log_spruce_top"));

        case 6:
            return(TextureArrayManager.GetIndexByName("log_birch_top"));

        case 7:
            return(TextureArrayManager.GetIndexByName("log_jungle_top"));
        }
        return(TextureArrayManager.GetIndexByName("log_oak"));
    }
예제 #2
0
    public void Refresh()
    {
        mesh.Clear();

        var vertexCount = vertexList.Count;

        mesh.SetVertexBufferParams(vertexCount, new[] {
            new VertexAttributeDescriptor(VertexAttribute.Position, VertexAttributeFormat.Float32, 4),
            new VertexAttributeDescriptor(VertexAttribute.Color, VertexAttributeFormat.Float32, 4),
            new VertexAttributeDescriptor(VertexAttribute.TexCoord0, VertexAttributeFormat.Float32, 2),
        });

        var verts = new NativeArray <Vertex>(vertexCount, Allocator.Temp);

        verts.CopyFrom(vertexList.ToArray());

        mesh.SetVertexBufferData(verts, 0, 0, vertexCount);
        mesh.SetTriangles(triangles.ToArray(), 0);
        mesh.RecalculateBounds();

        GetComponent <MeshRenderer>().sharedMaterial.SetTexture("_Array", TextureArrayManager.GetArray());
        GetComponent <MeshFilter>().sharedMesh = mesh;
        if (isCollidable)
        {
            GetComponent <MeshCollider>().sharedMesh = mesh;
        }
    }
예제 #3
0
    void FillMesh(NBTChunk chunk, CubeAttributes ca, NBTMesh nbtMesh)
    {
        chunk.GetLights(ca.pos.x, ca.pos.y, ca.pos.z, out float skyLight, out float blockLight);

        FaceAttributes fa = new FaceAttributes();

        fa.faceIndex  = TextureArrayManager.GetIndexByName("ladder");
        fa.color      = Color.white;
        fa.skyLight   = new float[] { skyLight, skyLight, skyLight, skyLight };
        fa.blockLight = new float[] { blockLight, blockLight, blockLight, blockLight };
        fa.normal     = Vector3.zero;
        fa.uv         = uv_zero;

        if (ca.blockData == 2)
        {
            fa.pos = frontFace;
            AddFace(nbtMesh, fa, ca);
        }
        else if (ca.blockData == 3)
        {
            fa.pos = backFace;
            AddFace(nbtMesh, fa, ca);
        }
        else if (ca.blockData == 4)
        {
            fa.pos = leftFace;
            AddFace(nbtMesh, fa, ca);
        }
        else if (ca.blockData == 5)
        {
            fa.pos = rightFace;
            AddFace(nbtMesh, fa, ca);
        }
    }
예제 #4
0
 public override int GetPlantIndexByData(int data)
 {
     if (data == 0)
     {
         return(TextureArrayManager.GetIndexByName("flower_rose"));
     }
     else if (data == 3)
     {
         return(TextureArrayManager.GetIndexByName("flower_houstonia"));
     }
     else if (data == 4)
     {
         return(TextureArrayManager.GetIndexByName("flower_tulip_red"));
     }
     else if (data == 5)
     {
         return(TextureArrayManager.GetIndexByName("flower_tulip_orange"));
     }
     else if (data == 6)
     {
         return(TextureArrayManager.GetIndexByName("flower_houstonia"));
     }
     else if (data == 8)
     {
         return(TextureArrayManager.GetIndexByName("flower_oxeye_daisy"));
     }
     throw new System.Exception("no index");
 }
예제 #5
0
    public override void AddCube(NBTChunk chunk, byte blockData, Vector3Int pos, NBTGameObject nbtGO)
    {
        ca.pos       = pos;
        ca.blockData = blockData;

        InitBlockAttributes(chunk, ref ca);

        bool topIsSnow = chunk.GetBlockByte(pos.x, pos.y + 1, pos.z) == 78;

        if (!chunk.HasOpaqueBlock(pos.x, pos.y, pos.z - 1))
        {
            FaceAttributes fa = GetFrontFaceAttributes(chunk, nbtGO.nbtMesh, ca);
            if (topIsSnow)
            {
                fa.faceIndex = TextureArrayManager.GetIndexByName("grass_side_snowed");
            }
            AddFace(nbtGO.nbtMesh, fa, ca);
        }
        if (!chunk.HasOpaqueBlock(pos.x + 1, pos.y, pos.z))
        {
            FaceAttributes fa = GetRightFaceAttributes(chunk, nbtGO.nbtMesh, ca);
            if (topIsSnow)
            {
                fa.faceIndex = TextureArrayManager.GetIndexByName("grass_side_snowed");
            }
            AddFace(nbtGO.nbtMesh, fa, ca);
        }
        if (!chunk.HasOpaqueBlock(pos.x - 1, pos.y, pos.z))
        {
            FaceAttributes fa = GetLeftFaceAttributes(chunk, nbtGO.nbtMesh, ca);
            if (topIsSnow)
            {
                fa.faceIndex = TextureArrayManager.GetIndexByName("grass_side_snowed");
            }
            AddFace(nbtGO.nbtMesh, fa, ca);
        }
        if (!chunk.HasOpaqueBlock(pos.x, pos.y, pos.z + 1))
        {
            FaceAttributes fa = GetBackFaceAttributes(chunk, nbtGO.nbtMesh, ca);
            if (topIsSnow)
            {
                fa.faceIndex = TextureArrayManager.GetIndexByName("grass_side_snowed");
            }
            AddFace(nbtGO.nbtMesh, fa, ca);
        }
        if (!chunk.HasOpaqueBlock(pos.x, pos.y + 1, pos.z))
        {
            FaceAttributes fa = GetTopFaceAttributes(chunk, nbtGO.nbtMesh, ca);
            if (topIsSnow)
            {
                fa.faceIndex = TextureArrayManager.GetIndexByName("snow");
            }
            AddFace(nbtGO.nbtMesh, fa, ca);
        }
        if (!chunk.HasOpaqueBlock(pos.x, pos.y - 1, pos.z))
        {
            FaceAttributes fa = GetBottomFaceAttributes(chunk, nbtGO.nbtMesh, ca);
            AddFace(nbtGO.nbtMesh, fa, ca);
        }
    }
예제 #6
0
    public override Mesh GetItemMesh(NBTChunk chunk, Vector3Int pos, byte blockData)
    {
        CubeAttributes ca = new CubeAttributes();

        ca.blockData = blockData;

        NBTMesh nbtMesh = new NBTMesh(256);

        chunk.GetLights(pos.x - chunk.x * 16, pos.y, pos.z - chunk.z * 16, out float skyLight, out float blockLight);

        FaceAttributes fa = new FaceAttributes();

        fa.faceIndex  = TextureArrayManager.GetIndexByName(GetNameByData(blockData));
        fa.skyLight   = new float[] { skyLight, skyLight, skyLight, skyLight };
        fa.blockLight = new float[] { blockLight, blockLight, blockLight, blockLight };
        fa.color      = Color.white;

        FillMesh(fa, ca, nbtMesh);

        nbtMesh.Refresh();

        nbtMesh.Dispose();

        return(nbtMesh.mesh);
    }
예제 #7
0
 // Start is called before the first frame update
 void Start()
 {
     GetComponent <Renderer>().material.SetTexture("_Array", TextureArrayManager.GetArray());
     GetComponent <Renderer>().material.SetInt("_Slice", TextureArrayManager.GetIndexByName(texturePath));
     GetComponent <Renderer>().material.SetColor("_Color", tintColor);
     GetComponent <Renderer>().material.SetFloat("_SkyLight", skyLight);
     GetComponent <Renderer>().material.SetFloat("_BlockLight", blockLight);
 }
예제 #8
0
    public override Mesh GetItemMesh(byte data = 0)
    {
        CubeAttributes ca = new CubeAttributes();

        NBTMesh nbtMesh = new NBTMesh(256);

        FaceAttributes fa = new FaceAttributes();

        //fa.skyLight = skylight_default;
        //fa.blockLight = blocklight_default;
        fa.color = Color.white;
        fa.uv    = uv_zero;

        try
        {
            fa.pos       = frontVertices;
            fa.normal    = Vector3.forward;
            fa.faceIndex = TextureArrayManager.GetIndexByName(frontName);
            AddFace(nbtMesh, fa, ca);

            fa.pos       = backVertices;
            fa.normal    = Vector3.back;
            fa.faceIndex = TextureArrayManager.GetIndexByName(backName);
            AddFace(nbtMesh, fa, ca);

            fa.pos       = topVertices;
            fa.normal    = Vector3.up;
            fa.faceIndex = TextureArrayManager.GetIndexByName(topName);
            fa.color     = TintManager.tintColor;
            AddFace(nbtMesh, fa, ca);
            fa.color = Color.white;

            fa.pos       = bottomVertices;
            fa.normal    = Vector3.down;
            fa.faceIndex = TextureArrayManager.GetIndexByName(bottomName);
            AddFace(nbtMesh, fa, ca);

            fa.pos       = leftVertices;
            fa.normal    = Vector3.left;
            fa.faceIndex = TextureArrayManager.GetIndexByName(leftName);
            AddFace(nbtMesh, fa, ca);

            fa.pos       = rightVertices;
            fa.normal    = Vector3.right;
            fa.faceIndex = TextureArrayManager.GetIndexByName(rightName);
            AddFace(nbtMesh, fa, ca);
        }
        catch (System.Exception e)
        {
            Debug.LogError("GetItemMesh error,generator=" + GetType() + ",message=\n" + e.Message);
        }

        nbtMesh.Refresh();

        nbtMesh.Dispose();

        return(nbtMesh.mesh);
    }
예제 #9
0
 public virtual Material GetItemMaterial(byte data)
 {
     if (commonItemMat == null)
     {
         commonItemMat = new Material(Shader.Find("Custom/TextureArrayShader"));
         commonItemMat.SetTexture("_Array", TextureArrayManager.GetArray());
     }
     return(commonItemMat);
 }
예제 #10
0
    // Use this for initialization
    void Start()
    {
        SoundManager.Init();
        LocalizationManager.Init();
        NBTGeneratorManager.Init();
        TextureArrayManager.Init();
        CraftingSystem.Init();

        SceneManager.LoadScene("LoginScene");
    }
예제 #11
0
    public void Refresh()
    {
        nbtMesh.Refresh();

        GetComponent <MeshRenderer>().sharedMaterial.SetTexture("_Array", TextureArrayManager.GetArray());
        GetComponent <MeshFilter>().sharedMesh = nbtMesh.mesh;
        if (isCollidable)
        {
            GetComponent <MeshCollider>().sharedMesh = nbtMesh.mesh;
        }
    }
예제 #12
0
 public override int GetTopIndexByData(NBTChunk chunk, int data)
 {
     if (data == 10)
     {
         return(TextureArrayManager.GetIndexByName("mushroom_block_inside"));
     }
     else
     {
         return(TextureArrayManager.GetIndexByName("mushroom_block_skin_brown"));
     }
 }
예제 #13
0
 public override int GetRightIndexByData(NBTChunk chunk, int data)
 {
     if (data == 3)
     {
         return(TextureArrayManager.GetIndexByName("pumpkin_face_off"));
     }
     else
     {
         return(TextureArrayManager.GetIndexByName("pumpkin_side"));
     }
 }
예제 #14
0
 public override int GetTopIndexByData(NBTChunk chunk, int data)
 {
     if (data == 7)
     {
         return(TextureArrayManager.GetIndexByName("farmland_wet"));
     }
     else
     {
         return(TextureArrayManager.GetIndexByName("farmland_dry"));
     }
 }
예제 #15
0
    public static void Test()
    {
        GameObject   go  = GameObject.CreatePrimitive(PrimitiveType.Cube);
        MeshRenderer mr  = go.GetComponent <MeshRenderer>();
        Material     mat = new Material(Shader.Find("Custom/TextureArrayShader"));

        mat.SetTexture("_Array", TextureArrayManager.GetArray());
        mr.material = mat;
        MeshFilter mf = go.GetComponent <MeshFilter>();

        mf.mesh = GetMesh();
    }
예제 #16
0
    int GetIndexByData(int data)
    {
        switch (data % 4)
        {
        case 0:
            return(TextureArrayManager.GetIndexByName("leaves_acacia"));

        case 1:
            return(TextureArrayManager.GetIndexByName("leaves_big_oak"));
        }
        return(TextureArrayManager.GetIndexByName("leaves_oak"));
    }
예제 #17
0
    int GetIndexByData(int data)
    {
        switch (data)
        {
        case 0:
            return(TextureArrayManager.GetIndexByName("stone"));

        case 1:
            return(TextureArrayManager.GetIndexByName("cobblestone"));
        }
        throw new System.Exception("no data,data=" + data);
    }
예제 #18
0
 public override int GetRightIndexByData(NBTChunk chunk, int data)
 {
     if (data == 3 || data == 6 || data == 9)
     {
         return(TextureArrayManager.GetIndexByName("mushroom_block_skin_red"));
     }
     else if (data == 10)
     {
         return(TextureArrayManager.GetIndexByName("mushroom_block_skin_stem"));
     }
     else
     {
         return(TextureArrayManager.GetIndexByName("mushroom_block_inside"));
     }
 }
예제 #19
0
    // Use this for initialization
    void Start()
    {
        SoundManager.Init();
        LocalizationManager.Init();
        NBTGeneratorManager.Init();
        TextureArrayManager.Init();

        SceneManager.LoadScene("LoginScene");

        //if (NetworkManager.Connect())
        //{
        //}
        //else
        //{
        //    DisconnectedUI.Show();
        //}
    }
예제 #20
0
    int GetIndexByData(int data)
    {
        switch (data % 4)
        {
        case 0:
            return(TextureArrayManager.GetIndexByName("planks_oak"));

        case 1:
            return(TextureArrayManager.GetIndexByName("planks_spruce"));

        case 2:
            return(TextureArrayManager.GetIndexByName("planks_birch"));

        case 3:
            return(TextureArrayManager.GetIndexByName("planks_jungle"));
        }
        return(TextureArrayManager.GetIndexByName("planks_oak"));
    }
예제 #21
0
    public override int GetPlantIndexByData(int data)
    {
        switch (data % 4)
        {
        case 0:
            return(TextureArrayManager.GetIndexByName("sapling_oak"));

        case 1:
            return(TextureArrayManager.GetIndexByName("sapling_spruce"));

        case 2:
            return(TextureArrayManager.GetIndexByName("sapling_birch"));

        case 3:
            return(TextureArrayManager.GetIndexByName("sapling_jungle"));
        }
        throw new System.Exception("no index");
    }
예제 #22
0
    public override int GetPlantIndexByData(NBTChunk chunk, int data)
    {
        switch (data)
        {
        case 1:
            return(TextureArrayManager.GetIndexByName("double_plant_syringa_bottom"));

        case 2:
            return(TextureArrayManager.GetIndexByName("double_plant_grass_bottom"));

        case 3:
            return(TextureArrayManager.GetIndexByName("double_plant_fern_bottom"));

        case 4:
            return(TextureArrayManager.GetIndexByName("double_plant_rose_bottom"));

        case 5:
            return(TextureArrayManager.GetIndexByName("double_plant_paeonia_bottom"));

        case 10:
            byte bottomType = 0;
            byte bottomData = 0;
            chunk.GetBlockData(pos.x, pos.y - 1, pos.z, ref bottomType, ref bottomData);
            switch (bottomData)
            {
            case 1:
                return(TextureArrayManager.GetIndexByName("double_plant_syringa_top"));

            case 2:
                return(TextureArrayManager.GetIndexByName("double_plant_grass_top"));

            case 3:
                return(TextureArrayManager.GetIndexByName("double_plant_fern_top"));

            case 4:
                return(TextureArrayManager.GetIndexByName("double_plant_rose_top"));

            case 5:
                return(TextureArrayManager.GetIndexByName("double_plant_paeonia_top"));
            }
            break;
        }
        throw new System.Exception("no index");
    }
예제 #23
0
    public override int GetRightIndexByData(NBTChunk chunk, int data)
    {
        switch (data)
        {
        case 0:
        case 8:
            return(TextureArrayManager.GetIndexByName("log_acacia"));

        case 1:
        case 9:
            return(TextureArrayManager.GetIndexByName("log_big_oak"));

        case 4:
            return(TextureArrayManager.GetIndexByName("log_acacia_top"));

        case 5:
            return(TextureArrayManager.GetIndexByName("log_big_oak_top"));
        }
        return(TextureArrayManager.GetIndexByName("log_acacia"));
    }
예제 #24
0
    public override void AddCube(NBTChunk chunk, byte blockData, Vector3Int localPosition, NBTGameObject nbtGO)
    {
        MeshData mesh = GetMesh(chunk, localPosition, blockData);

        int faceIndex = TextureArrayManager.GetIndexByName(stairsName);

        chunk.GetLights(localPosition.x, localPosition.y + 1, localPosition.z, out float skyLight, out float blockLight);

        NBTMesh nbtMesh    = nbtGO.nbtMesh;
        ushort  startIndex = nbtMesh.vertexCount;

        for (int i = 0; i < mesh.vertices.Length; i++)
        {
            SetVertex(nbtMesh, mesh.vertices[i] + localPosition, faceIndex, mesh.uv[i], skyLight, blockLight, Color.white, Vector3.zero);
        }
        foreach (int index in mesh.triangles)
        {
            nbtMesh.triangleArray[nbtMesh.triangleCount++] = (ushort)(startIndex + index);
        }
    }
예제 #25
0
    public override Mesh GetItemMesh(byte data = 0)
    {
        CubeAttributes ca = new CubeAttributes();

        ca.blockData = data;

        NBTMesh nbtMesh = new NBTMesh(256);

        FaceAttributes fa = new FaceAttributes();

        fa.faceIndex  = TextureArrayManager.GetIndexByName(GetNameByData(data));
        fa.skyLight   = skylight_default;
        fa.blockLight = blocklight_default;
        fa.color      = Color.white;

        FillMesh(fa, ca, nbtMesh);

        nbtMesh.Refresh();

        nbtMesh.Dispose();

        return(nbtMesh.mesh);
    }
예제 #26
0
    public override void AddCube(NBTChunk chunk, byte blockData, byte skyLight, Vector3Int pos, NBTGameObject nbtGO)
    {
        this.pos       = pos;
        this.blockData = blockData;
        vertices       = nbtGO.vertexList;
        triangles      = nbtGO.triangles;

        Mesh mesh = GetMesh();

        int faceIndex = TextureArrayManager.GetIndexByName(stairsName);

        int length = vertices.Count;

        for (int i = 0; i < mesh.vertices.Length; i++)
        {
            vertices.Add(new Vertex {
                pos = ToVector4(mesh.vertices[i] + pos, faceIndex), texcoord = mesh.uv[i], color = Color.white
            });
        }
        foreach (int index in mesh.triangles)
        {
            triangles.Add(index + length);
        }
    }
예제 #27
0
    public override void AddCube(NBTChunk chunk, byte blockData, Vector3Int pos, NBTGameObject nbtGO)
    {
        UnityEngine.Profiling.Profiler.BeginSample(GetType().Name + " AddCube");

        int faceIndex = TextureArrayManager.GetIndexByName(fenceName);

        MeshData mesh = GetMesh(chunk, pos);

        chunk.GetLights(pos.x, pos.y, pos.z, out float skyLight, out float blockLight);

        NBTMesh nbtMesh    = nbtGO.nbtMesh;
        ushort  startIndex = nbtMesh.vertexCount;

        for (int i = 0; i < mesh.vertices.Length; i++)
        {
            SetVertex(nbtMesh, mesh.vertices[i] + pos, faceIndex, mesh.uv[i], skyLight, blockLight, Color.white, mesh.normals[i]);
        }
        foreach (int index in mesh.triangles)
        {
            nbtMesh.triangleArray[nbtMesh.triangleCount++] = (ushort)(startIndex + index);
        }

        UnityEngine.Profiling.Profiler.EndSample();
    }
예제 #28
0
 public override int GetPlantIndexByData(int data)
 {
     return(TextureArrayManager.GetIndexByName("mushroom_red"));
 }
예제 #29
0
 public override int GetRightIndexByData(NBTChunk chunk, int data)
 {
     return(TextureArrayManager.GetIndexByName(GetTextureNameByData(data)));
 }
예제 #30
0
 public override int GetPlantIndexByData(int data)
 {
     return(TextureArrayManager.GetIndexByName("wheat_stage_7"));
 }