【问题标题】:Scale UI Image source image缩放 UI Image 源图像
【发布时间】:2015-09-14 01:56:24
【问题描述】:

我有一个 UI 图像,其源图像 是在运行时分配的。这些图像将具有各种大小,我需要对它们进行缩放以适应布局元素的边界,以便整个图像可见。

我为此尝试了多种方法,但我似乎无法让它发挥作用;谁能给我一些关于如何实现这一目标的指导?

在此先感谢

NB:布局是通过 Layout Group 组件控制的,这与其他可能有用的布局组件(例如 Aspect Ratio Fitter 和 Content Sizer(如解决此问题的文档中所述)

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
  }
}

【问题讨论】:

    标签: layout unity3d unityscript unity3d-gui


    【解决方案1】:

    有“SetNativeSize”功能,但是如果您使用布局组件,则此尺寸将在下一个更新循环中被覆盖。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-04
      • 2015-10-23
      • 1970-01-01
      • 2020-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多