您的位置:首页 > 产品设计 > UI/UE

代码控制 UGUI相关

2019-06-13 16:30 1331 查看

设置RGB值

Color nameColor = Color.gray;								//直接指定顏色
Color topicColor= new color32(80, 80, 80, 255);				//RGB (0-255)
Color bodyColor = new color(0.313f, 0.313f, 0.313f, 1); 	//RGB (0-1.0)

代码控制toggle

(怀疑是Bug导致要这么麻烦,目前Unity版本2018.3.11f1)

toggle.isOn = false;		//从代码改了isOn,但显示没有改变
toggle.TrySetEnable(false);
toggle.TrySetEnable(true);

Tab键切换InputField光标位置

这个网上有好多文章,但是都是在update里面识别下一个,我觉得没必要,毕竟很少见InputField会动态改变。

using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class IBUIInputNavigator : MonoBehaviour, ISelectHandler, IDeselectHandler
{
public Selectable nextInputField;
private EventSystem system;
private bool isSelect = false;

void Start()
{
system = EventSystem.current;
}

void Update()
{
if (Input.GetKeyDown(KeyCode.Tab) && isSelect)
{
StartCoroutine(Wait(nextInputField));
}
}

IEnumerator Wait(Selectable next)
{
yield return new WaitForEndOfFrame();
system.SetSelectedGameObject(next.gameObject, new BaseEventData(system));
}

public void OnSelect(BaseEventData eventData)
{
isSelect = true;
}

public void OnDeselect(BaseEventData eventData)
{
isSelect = false;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: