读取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;
           

    }

你可能感兴趣的:(读取Atlas图集中精灵做为材质贴图)