【SIKI】_10_Unity5.1UI系统-UGUI笔记

来源:互联网 发布:手机如何淘宝购物 编辑:程序博客网 时间:2024/04/24 20:30
Canvas
——Text
EventSystem 事件系统


0.滚动文本列表(隐藏背景)/Scroll/mask
image【Scroll Rect】【Mask】
——text(拉伸到显示全部)
Scrollbar【Scrollbar】

【Scrollbar】
_Direction滚动方向
【Scroll Rect 】
_指定 Content 为 text.
_指定 Vertical Srcollbar 为Scrollbar
_Horizontal水平滑动
_Vertical垂直滑动
【mask】
_Show Mask Graphic不勾选

1.加载场景
using UnityEngine.SceneManagement;
public class GameManger : MonoBehaviour {

public void OnstartGame(int sceneIndex)
{
SceneManager.LoadScene(sceneIndex);
//Application.LoadLevel(sceneName);
}

2.滑动条/slider
slider
——Background(背景图像)
——Fill Area
————Fill(填空图像)
——Handle Silde Area
————Handle(按钮图像)

3.图像类型/Image Type
——Simple 简单
——Sliced 切片(九宫切图,中心扩大缩小,其他不变)
——Tiled 平铺(产生多个该文件平铺该空间)
——Filled 切割 (围绕一个点切割显示一部分)

4.技能冷却
图片1:技能原图
图片2:黑色,半透明,Filled,Fill Amount(控制显示部分)
public class SkillItem : MonoBehaviour
{
public float coldTime = 2;
public KeyCode keycode;//读取按键
private float timer = 0;
private Image filledImage;
private bool isStartTimer = false;
// Use this for initialization
void Start ()
{
filledImage =transform.Find("FilledImage").GetComponent<Image>();寻找物体
Toggle toggle;
ToggleGroup group;
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(keycode))
{
isStartTimer = true;
}
if (isStartTimer)
{
timer += Time.deltaTime;//增量时间
filledImage.fillAmount = (coldTime - timer)/coldTime;//(总时间-运行时间)/总时间
if (timer >= coldTime)
{
filledImage.fillAmount = 0;
timer = 0;
isStartTimer = false;
}
}
}

public void OnClick()//注册到该图像Button组件下On Click()
{
isStartTimer = true;
}

5.单选/Toggle
Is On(是否勾选)
——Background
————Checkmark(勾选图像)
——Label

6.选项卡控制面板切换/Toggle Group
Toggle Group
——Toggle 1
——Toggle 2
——Toggle 3
——Panel 1
——Panel 2
——Panel 3
1.选择多个toggle然后在父类创建Toggle Group
2.在每个Toggle下On Value Changed载入Panel,选择GameObject的SetActive

7.表格/Grid Layout Group
选择Component_Layout_Grid Layout Group
每一个image放在GameObject,可以保持间隔

8.拖拽/IBeginDragHandler,IEndDragHandle
public class LevelButtonScrollRect : MonoBehaviour ,IBeginDragHandler,IEndDragHandler
{
private ScrollRect scrollRect;//滑动组件
public float smoothing = 4;//滑动速度
private float[] pageArray=new float[]{ 0,0.33333f,0.66666f,1 };//每个页面定点位置
public Toggle[] toggleArray;//页面数
private float targetHorizontalPosition=0;//目标位置
private bool isDraging = false;//是否正在拖拽
// Use this for initialization
void Start ()
{
scrollRect = GetComponent<ScrollRect>();调用组件
}
// Update is called once per frame
void Update ()
{
if(isDraging==false)//拖拽结束才运行代码 scrollRect.horizontalNormalizedPosition=Mathf.Lerp(scrollRect.horizontalNormalizedPosition,
targetHorizontalPosition,Time.deltaTime*smoothing);//从目前位置缓动到目标位置,时间
}


public void OnBeginDrag(PointerEventData eventData)//拖拽开始
{
isDraging = true;
}

public void OnEndDrag(PointerEventData eventData)//拖拽结束
{
isDraging = false;
float posX = scrollRect.horizontalNormalizedPosition;当前位置
int index = 0;
float offset = Mathf.Abs(pageArray[index] - posX);//绝对值
for (int i = 1; i < pageArray.Length; i++)
{
float offsetTemp = Mathf.Abs(pageArray[i] - posX);
if (offsetTemp < offset)
{
index = i;
offset = offsetTemp;
}
}
targetHorizontalPosition = pageArray[index];//载入目标值
toggleArray[index].isOn = true;
//scrollRect.horizontalNormalizedPosition = pageArray[index];
}

public void MoveToPage1(bool isOn) {
if (isOn)
{
targetHorizontalPosition = pageArray[0];
}
}
public void MoveToPage2(bool isOn) {
if (isOn) {
targetHorizontalPosition = pageArray[1];
}

}
public void MoveToPage3(bool isOn) {
if (isOn)
{
targetHorizontalPosition = pageArray[2];
}

}
public void MoveToPage4(bool isOn) {

if (isOn)
{
targetHorizontalPosition = pageArray[3];
}
}
}

9.Toggle/显示隐藏
1.每次点击通知运行MyToggle
2.MyToggle初始化OnValueChange方法
3.OnValueChange根据Toggle显示或隐藏选项。
public class MyToggle : MonoBehaviour
{

public GameObject isOnGameObject;//直接载入物体
public GameObject isOffGameObject;

private Toggle toggle;

// Use this for initialization
void Start ()
{
toggle = GetComponent<Toggle>();
OnValueChange(toggle.isOn);
}
// Update is called once per frame
void Update () {
}

public void OnValueChange(bool isOn)
{
isOnGameObject.SetActive(isOn);
isOffGameObject.SetActive(!isOn);
}
}

10.InputField/输入
InputField
——Placeholder(文字提示)
——Text(输入的文字)
【InputField】
_Image(背景)
_Content Type(输入类型,是否是密码)

11.texture Type/纹理类型
——【Texture/基本原理】
————Generate Alpha From Grayscale(从灰度产生Alpha通道)

——【Normal Map/法线贴图】
————Bumpiness(控制凹凸的总量)
————Filtering(过滤)
——————Smooth(平滑)
—————— Sharp(锐化)

——【GUI/GUI设置】

——【Reflection/反射设置】
————Mapping ( 映射)
——————Sphere Mapped (纹理映射到一个"球状" 立方体贴图上)
——————Cylindrical (纹理映射到一个圆柱体)
——————Simple Sphere (纹理映射到一个简单的球形,当你旋转它时变形反射)
——————Nice Sphere (纹理映射到一个球形,当你旋转它时变形,但你仍可看到纹理的外观)

——【Cookies/反射设置】
为你的场景增添很多视觉细节的一种有趣方式是使用Cookies——灰阶纹理用来控制游戏中照明的精确外观。这是构建移动云层和给人茂密植物印象的一种奇妙方式
————Light Type (光源类型)
————Generate Alpha From Grayscale(从灰度产生Alpha通道)

12.Button_Transition/点击按钮_转化选项
Transition(转化选项)
——ColorTint(颜色变化)
——SpriteSwap(不同的图片)
——Animation(动画)