Beispiel #1
0
    public Map()
    {
        layers = new IntArrayFromTexture[depth];
        for (int i = 0; i < layers.Length; i++)
        {
            layers[i] = new IntArrayFromTexture();
            //Load the texture from hard drive if it exist
            Texture2D layer = HDDResources.LoadImage("layer" + i);
            if (layer)
            {
                layers[i].SetTexture(layer);
            }
            else             //Create a black texture otherwise
            {
                layer = new Texture2D(width, height);
                Color[] colors = new Color[width * height];
                for (int j = 0; j < colors.Length; j++)
                {
                    colors[j] = Color.black;
                }

                layer.SetPixels(colors);
                layers[i].SetTexture(layer);
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// Makes a new quadrilateral using v0..3 as vertices in this order:
    ///  1 - - 2
    ///  |   / |
    ///  |  /  |
    ///  0 - - 3
    /// </summary>
    /// <param name="v0">Vertex 0</param>
    /// <param name="v1">Vertex 1</param>
    /// <param name="v2">Vertex 2</param>
    /// <param name="v3">Vertex 3</param>
    /// <param name="blockID">The ID of the block that will set the color of the quad</param>
    void NewQuadrilateral(Vector3 v0, Vector3 v1, Vector3 v2, Vector3 v3, int blockID)
    {
        int xOffset, yOffset;

        Palette.ColorToCoord(IntArrayFromTexture.IntToColor(blockID), out xOffset, out yOffset);

        //Offset is the center of the pixel color on the texture
        Vector2 offset = new Vector2((float)xOffset * _tileWidth + _tileWidth * .5f, (float)yOffset * _tileHeight + _tileHeight * .5f);


        _vertices.Add(v0);
        _vertices.Add(v1);
        _vertices.Add(v2);
        _vertices.Add(v3);

        _meshTris.Add(_quadCounter * 4 + 0);
        _meshTris.Add(_quadCounter * 4 + 1);
        _meshTris.Add(_quadCounter * 4 + 2);
        _meshTris.Add(_quadCounter * 4 + 0);
        _meshTris.Add(_quadCounter * 4 + 2);
        _meshTris.Add(_quadCounter * 4 + 3);


        //uvs coords are really close to "stretch" the texture a lot so only one pixel in the texture
        //is enough to fill any quad with the same color
        _uvs.Add(offset + new Vector2(0, 0));
        _uvs.Add(offset + new Vector2(0, .0000001f));
        _uvs.Add(offset + new Vector2(.0000001f, .0000001f));
        _uvs.Add(offset + new Vector2(.0000001f, 0));


        Vector3 side1  = v1 - v0;
        Vector3 side2  = v3 - v0;
        Vector3 normal = Vector3.Cross(side1, side2).normalized;

        _normals.Add(normal);
        _normals.Add(normal);
        _normals.Add(normal);
        _normals.Add(normal);


        QuadCounter = _quadCounter + 1;
    }
Beispiel #3
0
 void SelectColor(Color color)
 {
     _previewImage.color    = color;
     paintingBlockID        = IntArrayFromTexture.ColorToInt(color);
     _colorDetailsText.text = IntArrayFromTexture.IntToColor(paintingBlockID).ToString() + "\t\tint(" + paintingBlockID.ToString() + ")";
 }