﻿#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;

namespace JLGames.RocketDriver.Actions.DateTimex
{
    [CanEditMultipleObjects]
    [CustomEditor(typeof(MonoTimer))]
    public class TimerComponentEditor : Editor
    {
        public override void OnInspectorGUI()
        {
            var script = (MonoTimer) target;

            // 重绘GUI
            EditorGUI.BeginChangeCheck();

            // 公开属性
            DrawProperty("Delay", "延迟时间(秒)");
            DrawProperty("Interval", "间隔时间(秒)");
            DrawProperty("RepeatCount", "重复次数");
            if (script.RepeatCount <= 0)
            {
                EditorGUILayout.LabelField(" ", "<=0 时无限重复", GUILayout.ExpandWidth(true));
            }

            EditorGUILayout.BeginHorizontal();
            DrawProperty("AutoStart", "自动计时");
            DrawProperty("AutoDestroy", "自动销毁");
            EditorGUILayout.EndHorizontal();


            // 只读属性
            GUI.enabled = false;
            DrawProperty("CurrentTime", "当前时间(秒)");
            DrawProperty("CurrentCount", "当前次数");
            GUI.enabled = true;


            // 回调事件
            DrawProperty("OnIntervalEvent", "计时间隔事件");
            DrawProperty("OnCompleteEvent", "计时完成事件");

            if (EditorGUI.EndChangeCheck()) serializedObject.ApplyModifiedProperties();
        }


        private void DrawProperty(string property, string label)
        {
            EditorGUILayout.PropertyField(serializedObject.FindProperty(property));
        }
    }
}
#endif