Unity FairyGUI(七)
一.复选按钮,单选按钮
public class Lesson28 : MonoBehaviour
{
private void Start()
{
GRoot.inst.SetContentScaleFactor(1365, 768,
UIContentScaler.ScreenMatchMode.MatchHeight);
var pack = UIPackage.AddPackage("Package1");
foreach (var item in pack.dependencies)
UIPackage.AddPackage(item["name"]);
var com = UIPackage.CreateObject("Package1", "LearnFGUI2").asCom;
GRoot.inst.AddChild(com);
var btn1 = com.GetChild("n10").asButton;
var btn2 = com.GetChild("n16").asButton;
btn1.selected = true;
btn2.selected = true;
var c = com.GetController("select");
c.selectedIndex = 0;
btn1.onChanged.Add(() =>
{
Debug.Log(btn1.selected);
});
}
}
二.进度条
public class Lesson29 : MonoBehaviour
{
private void Start()
{
GRoot.inst.SetContentScaleFactor(1365, 768,
UIContentScaler.ScreenMatchMode.MatchHeight);
var pack = UIPackage.AddPackage("Package1");
foreach (var item in pack.dependencies)
UIPackage.AddPackage(item["name"]);
var com = UIPackage.CreateObject("Package1", "LearnFGUI2").asCom;
GRoot.inst.AddChild(com);
var progressBar = com.GetChild("n18").asProgress;
progressBar.value = 55.2f;
progressBar.TweenValue(0,5f);
}
}
三.滑动条
public class Lesson30 : MonoBehaviour
{
private void Start()
{
GRoot.inst.SetContentScaleFactor(1365, 768,
UIContentScaler.ScreenMatchMode.MatchHeight);
var pack = UIPackage.AddPackage("Package1");
foreach (var item in pack.dependencies)
UIPackage.AddPackage(item["name"]);
var com = UIPackage.CreateObject("Package1", "LearnFGUI2").asCom;
GRoot.inst.AddChild(com);
var slider = com.GetChild("n20").asSlider;
slider.value = 50;
slider.onChanged.Add(() =>
{
Debug.Log(slider.value);
});
}
}
|