1.把下面脚本放到Editor文件夹下,这样脚本继承Button之后,新声明的public变量才能在Inspector面板显示出来。
using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEditor.UI; using UnityEngine; [CustomEditor(typeof(MyButton), true)] [CanEditMultipleObjects] public class MyButtonEditor : ButtonEditor { private SerializedProperty delayTime; protected override void OnEnable() { base.OnEnable(); delayTime = serializedObject.FindProperty("delayTime"); } public override void OnInspectorGUI() { base.OnInspectorGUI(); EditorGUILayout.Space(); serializedObject.Update(); EditorGUILayout.PropertyField(delayTime); serializedObject.ApplyModifiedProperties(); } }
2.把下面脚本当成Button组件用,在Inspector面板的delayTime输入想延迟的时间就行了。
using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEditor.UI; using UnityEngine; [CustomEditor(typeof(MyButton), true)] [CanEditMultipleObjects] public class MyButtonEditor : ButtonEditor { private SerializedProperty delayTime; protected override void OnEnable() { base.OnEnable(); delayTime = serializedObject.FindProperty("delayTime"); } public override void OnInspectorGUI() { base.OnInspectorGUI(); EditorGUILayout.Space(); serializedObject.Update(); EditorGUILayout.PropertyField(delayTime); serializedObject.ApplyModifiedProperties(); } }