using UnityEditor;
using UnityEngine;

namespace XGame.Editor.Build.AssetBundles
{
    [CustomEditor(typeof(ABPackerInfoManifest), false)]
    public class ABPackerInfoManifestInspector : UnityEditor.Editor
    {
        private SerializedProperty m_Script;
        private ABPackerInfoManifestWindow manifestEditor;

        private void OnEnable()
        {
            m_Script = serializedObject.FindProperty("m_Script");
            var manifest = serializedObject.targetObject as ABPackerInfoManifest;
            manifestEditor = new ABPackerInfoManifestWindow(manifest, true);
        }

        private void OnDisable()
        {
            manifestEditor.Close();
            manifestEditor = null;
        }

        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            //展示区域，禁止操作
            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.PropertyField(m_Script);
            GUILayout.Space(10);
            EditorGUI.EndDisabledGroup();

            manifestEditor?.OnGUI();
            serializedObject.ApplyModifiedProperties();
            //if (GUI.changed)
            //{
            //    EditorUtility.SetDirty(target);
            //    AssetDatabase.SaveAssets();
            //}
        }
    }
}
