RectTransform、Texture2d 绽放问题
来源:互联网 发布:手机反黄软件 编辑:程序博客网 时间:2024/04/25 10:12
1、缩小一个Texture2d
代码:
/// <summary>/// 缩小一个texture/// </summary>/// <param name="originTexture"></param>/// <param name="rate"></param>/// <returns></returns>Texture2D CeateTexture_With_Scale(Texture2D originTexture, float rate){ if (rate >= 1f) { return originTexture; } int with = (int)(originTexture.width * rate); int height = (int)(originTexture.height * rate); int count = with * height; Texture2D textrue = new Texture2D(with, height, TextureFormat.ARGB32, false); Color32[] originColors = originTexture.GetPixels32(); Color32[] colors = new Color32[count]; float _1_rate = 1 / rate; for (int y = 0; y < height; y++) { for (int x = 0; x < with; x++) { int i = x + y * with; int j = (int)(_1_rate * x) + (int)(_1_rate * y) * originTexture.width; colors[i] = originColors[j]; } } textrue.SetPixels32(colors); textrue.Apply(); return textrue;}
2、缩放一个RawImage的UV,使用的它的Texture不变形
//[lzh]using UnityEngine;using UnityEngine.UI;using System.Collections;public class Test : MonoBehaviour{ public RawImage rawImg; public RectTransform rtRawImg; private Texture texture; // Use this for initialization void Start () { texture = rawImg.texture; ScaleUV(); } void ScaleUV() { Vector2 rtSize = rtRawImg.rect.size; Vector2 texSize = new Vector2(texture.width, texture.height); //Debug.Log(rtSize); float rateRt = rtSize.y / rtSize.x; float rateTex = texSize.y / texSize.x; float temp = rateTex / rateRt; Debug.Log(temp); if(temp<1) { //rawImg.uvRect.x = 0.5f * (temp - 1); rawImg.uvRect = new Rect(0.5f * (1-temp), 1f, temp, 1f); } else if(temp > 1) { temp = 1 / temp; rawImg.uvRect = new Rect(1f, 0.5f * (1 - temp),1f, temp); } }}
0 0
- RectTransform、Texture2d 绽放问题
- 绽放
- 关于UGUI中RectTransform组件的获取问题
- [UnityUI]RectTransform
- UGUI - RectTransform
- Unity RectTransform
- UGUI RectTransform
- RectTransform.anchorMin
- RectTransform详解
- Texture2D.FromFile
- 详解Texture2D
- Xna4.0中使用Texture2D.FromStream加载png图像的问题
- 【UGUI进阶】RectTransform剖析
- u3d 设置RectTransform属性
- 【UGUI进阶】RectTransform剖析
- UGUI之rectTransform属性
- 【UGUI】uGUI RectTransform
- UI系统 UGUI-RectTransform
- windows-VC++6.0环境下C++链接MySQL数据库
- 大数据开发学习规划时间表记录及反思
- ServerSocket学习1
- slf4j
- codeforces 603A. Alternative Thinking(数学找规律 或者 dp)
- RectTransform、Texture2d 绽放问题
- thinkphp3.2之url模式和后台模块之间的关系
- week13---12月4日 JS内置对象——Array、String
- iOS-UI父视图下视图的操作
- hdu 2874 Connections between cities
- ZOJ - 2972 Hurdles of 110m
- [leetcode] 103. Binary Tree Zigzag Level Order Traversal
- Python利用结巴分词进行中文分词
- iOS开发之UIViewController属性