untiy3d NGUI为UIButton和UIToggle脚本绑定方法


using System;
using UnityEngine;


public class TestPanel : MonoBehaviour
{

    private UIToggle tog;
    private UIButton but;
    void Awake()
    {
        tog = transform.FindChild("Toggle").GetComponent();
        but = transform.FindChild("Button").GetComponent();
        EventDelegate.Add(tog.onChange, delegate ()
        {
            OnToggleClick(tog.value);
        });
        EventDelegate.Add(but.onClick, delegate ()
        {
            OnButtonClick(but.gameObject);
        });
    }


    public void OnToggleClick(bool isON)
    {
        if (isON)
            Debug.LogError("开");
        else
            Debug.LogError("关");
    }

    public void OnButtonClick(GameObject but)
    {
        Debug.LogError(but.name);
    }



}

untiy3d NGUI为UIButton和UIToggle脚本绑定方法_第1张图片
图片.png

你可能感兴趣的:(untiy3d NGUI为UIButton和UIToggle脚本绑定方法)