1. 程式人生 > >讀取Atlas圖集中精靈做為材質貼圖

讀取Atlas圖集中精靈做為材質貼圖

void ClickBt(GameObject _go)
    {
        UISprite _sprite = _go.GetComponent<UISprite>();
        _tex = (_sprite.atlas.texture) as Texture2D;

        isProductClick = true;
      
            int _pixelX = _sprite.atlas.GetSprite(_sprite.spriteName).x;
            int _pixelY = _sprite.atlas.GetSprite(_sprite.spriteName).y;
            int _pixelW = _sprite.atlas.GetSprite(_sprite.spriteName).width;
            int _pixelH = _sprite.atlas.GetSprite(_sprite.spriteName).height;
            Texture2D tex = new Texture2D(_pixelW, _pixelH);
            Color[] cor = _tex.GetPixels(_pixelX, _tex.height - _pixelY - _pixelH, _pixelW, _pixelH);  //從左下角開始計算
            tex.SetPixels(cor);
            tex.Apply();
            deskMList[0].mainTexture = tex;
           

    }