您当前的位置: 首页 >  unity

幻世界

暂无认证

  • 0浏览

    0关注

    237博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【Unity开发小技巧】UGUI组件Toogle,ScrollView,DropDown的运用变形

幻世界 发布时间:2019-04-09 15:15:17 ,浏览量:0

欢迎加入Unity业内qq交流群:956187480

qq扫描二维码加群

demo地址:https://download.csdn.net/download/qq_37310110/11099998 一:Toogle

变形  group

public class RToogleGroup01 : MonoBehaviour {

    public Toggle tg1;
    public Toggle tg2;
    // Use this for initialization
    void Start () {
        tg1.onValueChanged.AddListener(isOn => {
            if (isOn)
            {
                Debug.Log("tg1打开");
            }
            else
            {
                Debug.Log("tg1关闭");
            }
        });
        tg2.onValueChanged.AddListener(isOn =>
        {
            if (isOn)
            {
                Debug.Log("tg2打开");
            }
            else
            {
                Debug.Log("tg2关闭");
            }
        });
    }
	
	// Update is called once per frame
	void Update () {
		
	}

public class RToogleGroup02 : MonoBehaviour {
    public Toggle tg1;
    public Toggle tg2;
    public Toggle tg3;
    public Transform []bgs;
    // Use this for initialization
    void Start()
    {
        tg1.onValueChanged.AddListener(isOn => { ShowBG(0); });
        tg2.onValueChanged.AddListener(isOn => { ShowBG(1); });
        tg3.onValueChanged.AddListener(isOn => { ShowBG(2); });
    }

    private void ShowBG(int index)
    {
        for (int i = 0; i < bgs.Length; i++)
        {
            if (i == index)
            {
                bgs[i].gameObject.SetActive(true);
            }
            else
            {
                bgs[i].gameObject.SetActive(false);
            }
        }
    }
二:DropDown
public class RDropdown : MonoBehaviour {

    Dropdown dropdown;
    List tempNames;

    void Awake()
    {
        dropdown = GetComponent();
        tempNames = new List();
        dropdown.onValueChanged.AddListener(ExecuteItem);
    }

    private void ExecuteItem(int arg0)
    {
        Debug.Log("执行逻辑:"+ arg0);
    }

    void Start()
    {
        AddNames();
        UpdateDropdownView(tempNames);
    }

    /// 
    /// 刷数据
    /// 
    /// 
    private void UpdateDropdownView(List showNames)
    {
        dropdown.options.Clear();
        Dropdown.OptionData tempData;
        for (int i = 0; i < showNames.Count; i++)
        {
            tempData = new Dropdown.OptionData();
            tempData.text = showNames[i];
            dropdown.options.Add(tempData);
        }
        dropdown.captionText.text = showNames[0];
    }
   
    private void AddNames()
    {
        string s1 = "0";
        string s2 = "1";
        string s3 = "2";
        string s4 = "3";
        string s5 = "4";

        tempNames.Add(s1);
        tempNames.Add(s2);
        tempNames.Add(s3);
        tempNames.Add(s4);
        tempNames.Add(s5);
    }
}

demo地址:https://download.csdn.net/download/qq_37310110/11099998

欢迎加入Unity业内qq交流群:956187480

qq扫描二维码加群

关注
打赏
1660704426
查看更多评论
立即登录/注册

微信扫码登录

0.0375s