From 2c2c75902d86be46d3e86c34d05d839a80e5113a Mon Sep 17 00:00:00 2001 From: "guzhu@fairygui.com" Date: Mon, 21 Jan 2019 11:53:54 +0800 Subject: [PATCH] Add new NTexture(sprite) --- Source/Scripts/Core/NTexture.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Source/Scripts/Core/NTexture.cs b/Source/Scripts/Core/NTexture.cs index d57085e4..231c4686 100644 --- a/Source/Scripts/Core/NTexture.cs +++ b/Source/Scripts/Core/NTexture.cs @@ -109,7 +109,6 @@ public NTexture(Texture texture) : this(texture, null, 1, 1) /// public NTexture(Texture texture, Texture alphaTexture, float xScale, float yScale) { - _root = this; _nativeTexture = texture; _alphaTexture = alphaTexture; @@ -176,6 +175,23 @@ public NTexture(NTexture root, Rect region, bool rotated, Vector2 originalSize, _offset = offset; } + /// + /// + /// + /// + public NTexture(Sprite sprite) + { + Rect rect = sprite.rect; + rect.y = sprite.texture.height - rect.yMax; + + _root = this; + _nativeTexture = sprite.texture; + _region = rect; + _originalSize = new Vector2(_region.width, _region.height); + uvRect = new Rect(_region.x / _nativeTexture.width, 1 - _region.yMax / _nativeTexture.height, + _region.width / _nativeTexture.width, _region.height / _nativeTexture.height); + } + /// /// ///