我有一个UI 图像,它的源图像是在运行时分配的。这些图像将具有各种大小,我需要对它们进行缩放以适应布局元素的边界,以便整个图像可见。
我为此尝试了多种方法,但是我似乎无法使其正常工作;谁能给我一些关于如何实现这一目标的指示?
提前谢谢了
注意:布局是通过Layout Group组件控制的,它与其他可能有用的布局组件(例如Aspect Ratio Fitter和Content Sizer)控制 rect 冲突(如针对此问题的文档解决方案中所述)
public
function ContextImgImp() {
Debug.Log("Context Img Located at: " + texLocation);
var wwwDirectory = "file://" + texLocation; //this will probably need to change for other OS (PC = file:/ [I think?]) - **REVISE**
Debug.Log("Tex located at: " + wwwDirectory);
newImgTex = new Texture2D(512, 512, TextureFormat.DXT1, false);
while (true) {
var www: WWW = new WWW(wwwDirectory);
yield www;
Debug.Log("Done Downloading Texture");
www.LoadImageIntoTexture(newImgTex);
if (www.isDone) {
break; //if done downloading image break loop
}
}
var imgSprite = contImg.sprite;
var imgRect = imgSprite.rect;
var imgPivot = imgRectTrans.pivot;
var pixelScale = 100;
Debug.Log("Pixel Scale:" + pixelScale);
newImgSprite = Sprite.Create(newImgTex, imgRect, imgPivot, pixelScale);
contImg.sprite = newImgSprite;
//imgRectTrans.rect.size = Vector2(130,130);
//contImg.sprite.rect.size = Vector2(130,130);
//contImg.type = Image.Type.Simple;
//***HERE***
if (assetFromFile) {
ImgNameSplit(); //only execute namesplit if from file
}
}