强行扩展Unity原生组件

效果图:
强行扩展Unity原生组件_第1张图片
Scripts:

using UnityEngine.EventSystems;
using UnityEngine.UI;
using UnityEngine;


namespace H2Engine
{
    [XLua.LuaCallCSharp]
    public class H2Toggle : Toggle
    {
        private ILua_H2Button luaH2Button;

        public int SoundID = 9;

        public override void OnPointerClick(PointerEventData eventData)
        {
            if (luaH2Button == null)
            {
                luaH2Button = LuaManager.Global.Get<ILua_H2Button>("H2Button");
            }
            luaH2Button.OnClick(SoundID);
            base.OnPointerClick(eventData);
        }       
    }
}

Editor:

using UnityEditor;
using UnityEditor.UI;

namespace H2Engine {

    [CustomEditor(typeof(H2Toggle))]
    public class H2ToggleEditor : ToggleEditor
    {
        SerializedProperty sp;
        protected override void OnEnable()
        {
            base.OnEnable();
            sp = serializedObject.FindProperty("SoundID");
        }

        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            EditorGUILayout.PropertyField(sp);
            serializedObject.ApplyModifiedProperties();
            EditorUtility.SetDirty(target);
        }
    }



}


你可能感兴趣的:(UnityEditor)