今天介绍一下 UI 组件之 Image 组件 , Image 用来显示图片的 .
我们从unity 里选取一张图片 , 修改为 sprite格式
然后把图片拖到 Image 组件中的 Source Image 中 , 就可以在 Scene 视图下看到图片了
下面介绍一下 Image 常用属性和功能 :
Source Image : 显示图片的 Sprite 图像纹理 ;Color : 图片颜色 ;Image Type : 图像类型
Simple : 普通模式Sliced : 九宫格模式Tiled : 平铺Filled : 填充模式 (一般用来做技能 CD)
4. Preserve Aspect : 图像原始比例的宽和高是否保持相同比例 ;
5. Set Native Size : 保持图片原有大小 ;
好了 , 然后我们来做一个 进度条吧
新建一个 Image , 拖入一张图片 , 把 ImageType 改为 Filled 填充模式 , Fill Method 改为 Horizontal , fillAmount 设置为 0
写一个脚本吧 :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TestImage : MonoBehaviour
{
// 定义一个 Image 对象
private Image m_Im