1. 程式人生 > >【Unity3D】【NGUI】處理Button的按下狀態?

【Unity3D】【NGUI】處理Button的按下狀態?

NGUI討論群:333417608

提供一個指令碼,會不會用就看各位的造化了。

MonoBehaviourSZUIPressedButton

using UnityEngine;
using System.Collections.Generic;
 
public class SZUIPressedButton : UIWidgetContainer
{
        public List<EventDelegate> onPressed = new List<EventDelegate> ();
        private bool pressed = false;
         
        void Update ()
        {
                if (pressed)
                {
                        EventDelegate.Execute(onPressed);
                }
        }
         
        public void OnPress (bool isPressed)
        {
                pressed = isPressed;
        }
         
        void OnDisable()
        {
                pressed = false;
        }
}

編輯指令碼:SZUIPressedButtonEditor

using UnityEngine;
using UnityEditor;
 
[CustomEditor(typeof(SZUIPressedButton))]
public class SZUIPressedButtonEditor : Editor
{
        public override void OnInspectorGUI ()
        {
                SZUIPressedButton pb = target as SZUIPressedButton;
                NGUIEditorTools.DrawEvents("On Pressed", pb, pb.onPressed);
        }
}