UGUI 学习笔记 4 Image

来源:互联网 发布:免费下载音乐的软件 编辑:程序博客网 时间:2024/05/19 03:22
  1. 属性详解

Source Image: The texture that represents the image to display(which must be imported as a Sprite). 图片,纹理格式必须是Sprite.
Color: The Color to apply to the image. 颜色
Material :The Material to use for rendering the image. 材质球
Raycast Target : Should this be considered a target for raycasting? 射线目标
Preserve Aspect : Ensure image remains existing dimension. 保持比例
Set Native Size : Button to set the dimensions of the image bos to the original pixel size of the texture. 设置原图大小
2. Image Type详解
Simple,根据Image的长宽,拉伸图片。如果勾选了Preserve Aspect,会保持图片的长宽比拉伸。
Sliced,选中图片在Sprite Editor编辑拉伸区域,绿色线划分出来的四个角不做拉伸,蓝色圈区域会横向拉伸,红色圈区域会纵向拉伸。中间区域既有横向拉伸,也有纵向拉伸。如果不勾选 Fill Center ,中间区域将不会显示。
这里写图片描述
Tiled 如果图片没有编辑拉伸区域,则图片会保持原有的大小,平铺整个Image。如果图片有编辑拉区域,则四个角不变,横向用蓝色圈区域平铺,纵向用红色圈区域平铺,中间部分用绿色线划分的中间区域平铺。如果不勾选 Fill Center ,中间区域将不会显示。
Filled 中有4个参数Fill Method, Fill Origin, Fill Amount, Clock wise
Fill Method是填充方法,Horizontal 是水平方向,Vertical 是垂直方向,Radial 90 是90° Radial 180是 180° Radial 360是 360°
Fill Origin 是填充开始位置 Bottom 底,Top 顶,Left 左,Right 右。
Fill Amount 是填充值,范围0~1;
Clock wise 是顺时针方向填充。
3. 代码控制
脚本添加引用 using UnityEngine.UI; 才能使用UGUI的控件。
将图片绑定到预制体上,通过预制体来引用图片。
编写工具代码
这里写图片描述
引用代码示例

这里写图片描述

原创粉丝点击