Exemplo n.º 1
0
    void Start()
    {
        gameObject.transform.localScale = new Vector3(1, 1, 0);      //new Vector3(Utility.TileWidth,Utility.TileHeight,0);

        curSheetObject = TiledSheetFactory.getSpriteSheet("Grid", "EditorSheets");


        shader = Shader.Find("Transparent/Diffuse");

        gameObject.AddComponent <MeshFilter>();
        gameObject.AddComponent <MeshRenderer>();
        gameObject.AddComponent <MeshCollider>();

        m_meshFilter = this.GetComponent <MeshFilter>();

        Mesh newMesh = new Mesh();

        m_meshFilter.mesh = newMesh;

        regenerateMesh();

        renderer.material.shader = shader;

        renderer.material.mainTexture = curSheetObject.spriteTexture;



        this.enabled = true;
    }
Exemplo n.º 2
0
 private void loadTextures()
 {
     if (curSheet == null || curSheet.Trim().Length == 0)
     {
         return;
     }
     curSheetObject = TiledSheetFactory.getSpriteSheet(curSheet);
     textures       = null;
     scrollpos      = Vector2.zero;
     if (curSheetObject != null)
     {
         textures = new Texture2D[curSheetObject.frame_count];
         int       ix = 0;
         FrameData fd = null;
         while (ix < curSheetObject.frame_count)
         {
             fd = curSheetObject.frames[ix];
             int ox = Mathf.FloorToInt(fd.position.x);
             int oy = Mathf.FloorToInt(fd.position.y);
             int wx = Mathf.FloorToInt(fd.imageSize.x);
             int wy = Mathf.FloorToInt(fd.imageSize.y);
             //Debug.Log(fd.name + " ("+ox+","+oy+") ("+wx+","+wy+")");
             Texture2D newText = new Texture2D(wx, wy);
             oy = curSheetObject.textureHeight - oy - wy;
             Color[] colors = curSheetObject.spriteTexture.GetPixels(ox, oy, wx, wy);
             newText.SetPixels(colors);
             newText.Apply();
             textures[ix] = newText;
             ix++;
         }
     }
 }
Exemplo n.º 3
0
    //public void setSpriteSheetName(string sheetname, string sheetpath){
    //	if(spriteSheetName == null || !spriteSheetName.Equals(sheetname)){
    //		spriteSheetName = sheetname;
    //		spriteSheetPath = sheetpath;
    //		isDirty = true;
    //	}
    //}/

    public void destroySpriteSheet()
    {
        if (tileSheetDefinition == null)
        {
            if (spriteSheetName == null || spriteSheetName.Trim().Length == 0)
            {
                return;
            }
        }
        // Destroy current.
        if (spriteSheet != null)
        {
            spriteSheet.destroy();
            this.spriteSheet = null;
        }

        if (tileSheetDefinition != null)
        {
            spriteSheet = TiledSheetFactory.getSpriteSheet(tileSheetDefinition);
        }
        else
        {
            spriteSheet = TiledSheetFactory.getSpriteSheet(spriteSheetName, spriteSheetPath);
        }
    }
Exemplo n.º 4
0
    void Start()
    {
        gridWidth  = Mathf.Ceil(width / Utility.TileWidth);
        gridHeight = Mathf.Ceil(height / Utility.TileHeight);

        gameObject.transform.position = new Vector3(posx, posy, posz);

        gameObject.transform.localScale = new Vector3(1, 1, 1);      //new Vector3(Utility.TileWidth,Utility.TileHeight,0);

        curSheetObject = TiledSheetFactory.getSpriteSheet(spriteSheetName, spriteSheetPath);

        //meshUV = curSheetObject.frames[0].uv.Clone() as Vector2[];

        //shader = Shader.Find("Transparent/Diffuse");
        shader = Shader.Find("Unlit/Transparent");

        gameObject.AddComponent <MeshFilter>();
        gameObject.AddComponent <MeshRenderer>();
        gameObject.AddComponent <MeshCollider>();

        m_meshFilter = this.GetComponent <MeshFilter>();

        Mesh newMesh = new Mesh();

        m_meshFilter.mesh = newMesh;

        regenerateMesh();

        renderer.material.shader = shader;

        renderer.material.mainTexture = curSheetObject.spriteTexture;

        //renderer.material.color = new Color(1,1,1,1);

        //this.enabled = true;
    }