unity UGUI Toggle事件管理

 
   void Start() {
        List<string> togglesName = new List<string>();
        togglesName.Add("Toggle_forward");
        togglesName.Add("Toggle_right");
        togglesName.Add("Toggle_left");

        foreach (string  toggleName in togglesName)
        {
            GameObject btnObj = GameObject.Find(toggleName);
            Toggle tg = btnObj.GetComponent<Toggle>();
            tg.onValueChanged.AddListener(delegate(bool isOn){
                 this.OnValueChanged(isOn, btnObj);  
            });
        }
    }

    public void OnValueChanged(bool ison,GameObject sender)
    {
        switch (sender.name)
        {
            case "Toggle_forward":
                
                break;
            case "Toggle_right":
               
                break;
            case "Toggle_left":
                
                break;
            default:
                break;
        }
    }

你可能感兴趣的:(unity,toggle,UGUI)