//绘制小组件
        private KingdomsUnityEditor.KingdomsLevelItemConfig DrawLevelItem(KingdomsUnityEditor.KingdomsLevelItemConfig itemConfig)
        {
            if (_prefabNames == null)
            {
                return(itemConfig);
            }
            GUILayout.BeginHorizontal("box");
            GUILayout.BeginVertical();

            itemConfig.Name = EditorGUILayout.TextField("名称", itemConfig.Name);
            int selectSprite = -1;

            if (_prefabNames != null)
            {
                for (int i = 0; i < _prefabNames.Length; i++)
                {
                    if (_prefabNames[i].Equals(itemConfig.Sprite))
                    {
                        selectSprite = i;
                        break;
                    }
                }
            }

            int newSelectSprite = EditorGUILayout.Popup("图片", selectSprite, _prefabNames);

            if (newSelectSprite != selectSprite)
            {
                itemConfig.Sprite = _prefabNames[newSelectSprite];
            }


            //itemConfig.Sprite = EditorGUILayout.TextField("图片",itemConfig.Sprite);
            itemConfig.Size  = EditorGUILayout.Vector2Field("大小", itemConfig.Size);
            itemConfig.Point = EditorGUILayout.Vector2Field("位置", itemConfig.Point);
            GUILayout.EndVertical();


            int        iconSize   = 100;
            string     prefabPath = _target.GetPrafabPath(itemConfig.Sprite);
            GameObject prefab     = AssetDatabase.LoadAssetAtPath <GameObject>(prefabPath);

            if (prefab != null)
            {
                GUILayout.Label("", GUILayout.Width(iconSize), GUILayout.Height(iconSize));
                Rect lastRect = GUILayoutUtility.GetLastRect();
                GUI.DrawTexture(new Rect(lastRect.position, Vector2.one * iconSize), prefab.transform.Find("Image").GetComponent <Image>().sprite.texture, ScaleMode.ScaleToFit);
            }
            GUILayout.EndHorizontal();
            return(itemConfig);
        }
        public override void OnInspectorGUI()
        {
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Apply", GUILayout.Width(60)))
            {
                //bool save = true;
                //foreach (var item in _target.Config.Levels)
                //{
                //	if (string.IsNullOrEmpty(item.LevelName))
                //	{
                //		save = false;
                //		EditorUtility.DisplayDialog("保证关卡")
                //	}
                //}
                SaveData();
                EditorUtility.DisplayDialog("保存数据", "保存数据", "ok");
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginVertical("helpbox");
            GUILayout.Label("全局配置", EditorStyles.boldLabel);
            _target.Config.Size   = EditorGUILayout.IntField("单位大小", _target.Config.Size);
            _target.Config.Row    = EditorGUILayout.IntField("行数", _target.Config.Row);
            _target.Config.Column = EditorGUILayout.IntField("列数", _target.Config.Column);
            bool showBg = EditorGUILayout.Toggle("运行时显示背景", _target.ShowBgRuntime);

            if (showBg != _target.ShowBgRuntime)
            {
                _target.ShowBgRuntime = showBg;
                EditorUtility.SetDirty(_target);
            }
            GUILayout.EndVertical();

            GUILayout.BeginVertical("helpbox");
            GUILayout.Label($"关卡配置 ({_target.SelectLevel + 1}/{_target.Config.Levels.Count})", EditorStyles.boldLabel);
            if (_target.Config.Levels.Count > 0)
            {
                if (_target.SelectLevel < 0 || _target.SelectLevel >= _target.Config.Levels.Count)
                {
                    _target.SelectLevel = 0;
                    EditorUtility.SetDirty(_target);
                    //return;
                }

                string[] levelNames = new string[_target.Config.Levels.Count];
                for (int i = 0; i < _target.Config.Levels.Count; i++)
                {
                    levelNames[i] = _target.Config.Levels[i].LevelName;
                }
                int selectLevel = EditorGUILayout.Popup("选择关卡", _target.SelectLevel, levelNames);
                if (selectLevel != _target.SelectLevel)
                {
                    _target.SelectLevel = selectLevel;
                    EditorUtility.SetDirty(_target);
                }


                var levelConfig = _target.Config.Levels[_target.SelectLevel];

                GUILayout.BeginVertical("Box");
                levelConfig.LevelName = EditorGUILayout.TextField("关卡名称", levelConfig.LevelName);
                //删除当前关卡
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("删除当前关卡", GUILayout.Width(100)))
                {
                    if (EditorUtility.DisplayDialog("警告", $"是否删除当前关卡:{levelConfig.LevelName}", "ok", "cancel"))
                    {
                        _target.Config.Levels.RemoveAt(_target.SelectLevel);
                        //_target.SelectLevel--;
                        GUIUtility.ExitGUI();
                        return;
                    }
                }
                GUILayout.EndHorizontal();
                //渲染组件
                if (levelConfig.Items != null && levelConfig.Items.Count > 0)
                {
                    int      playerItem  = -1;
                    int      victoryItem = -1;
                    string[] itemNames   = new string[levelConfig.Items.Count];
                    for (int i = 0; i < levelConfig.Items.Count; i++)
                    {
                        itemNames[i] = levelConfig.Items[i].Name;
                        if (itemNames[i].Equals(levelConfig.Player))
                        {
                            playerItem = i;
                        }
                        if (itemNames[i].Equals(levelConfig.Victory))
                        {
                            victoryItem = i;
                        }
                    }
                    int newItem = EditorGUILayout.Popup("角色组件", playerItem, itemNames);
                    if (newItem != playerItem && newItem >= 0)
                    {
                        if (newItem < itemNames.Length)
                        {
                            levelConfig.Player = itemNames[newItem];
                        }
                    }
                    newItem = EditorGUILayout.Popup("胜利组件", victoryItem, itemNames);
                    if (newItem != playerItem && newItem >= 0)
                    {
                        if (newItem < itemNames.Length)
                        {
                            levelConfig.Victory = itemNames[newItem];
                        }
                    }

                    GUILayout.Label($"组件 ({levelConfig.Items.Count})");
                    for (int i = 0; i < levelConfig.Items.Count; i++)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button("x", GUILayout.Width(30)))
                        {
                            if (EditorUtility.DisplayDialog("警告", $"是否删除当前组件:{levelConfig.Items[i].Name}", "ok", "cancel"))
                            {
                                _target.Config.Levels[_target.SelectLevel].Items.RemoveAt(i);
                                //levelConfig.Items.RemoveAt(i);

                                GUIUtility.ExitGUI();
                                return;
                            }
                        }
                        GUILayout.EndHorizontal();
                        levelConfig.Items[i] = DrawLevelItem(levelConfig.Items[i]);
                    }
                }
                if (GUILayout.Button("添加组件"))
                {
                    if (levelConfig.Items == null)
                    {
                        levelConfig.Items = new List <KingdomsUnityEditor.KingdomsLevelItemConfig>();
                    }
                    KingdomsUnityEditor.KingdomsLevelItemConfig itemConfig;
                    if (levelConfig.Items.Count > 0)
                    {
                        itemConfig = levelConfig.Items[levelConfig.Items.Count - 1];
                    }
                    else
                    {
                        itemConfig = new KingdomsUnityEditor.KingdomsLevelItemConfig();
                    }
                    itemConfig.Name = System.Guid.NewGuid().ToString().Substring(0, 6);
                    levelConfig.Items.Add(itemConfig);
                }
                GUILayout.EndVertical();

                _target.Config.Levels[_target.SelectLevel] = levelConfig;
            }
            if (GUILayout.Button("添加关卡"))
            {
                KingdomsUnityEditor.KingdomsLevelConfig levelConfig;
                if (_target.Config.Levels.Count > 0)
                {
                    levelConfig = _target.Config.Levels[_target.Config.Levels.Count - 1];
                }
                else
                {
                    levelConfig = new KingdomsUnityEditor.KingdomsLevelConfig();
                }
                levelConfig.LevelName = System.Guid.NewGuid().ToString().Substring(0, 10);
                _target.Config.Levels.Add(levelConfig);
                _target.SelectLevel = _target.Config.Levels.Count - 1;
            }
            GUILayout.EndVertical();
            //base.OnInspectorGUI();


            if (GUILayout.Button("Apply", GUILayout.Width(60)))
            {
                //bool save = true;
                //foreach (var item in _target.Config.Levels)
                //{
                //	if (string.IsNullOrEmpty(item.LevelName))
                //	{
                //		save = false;
                //		EditorUtility.DisplayDialog("保证关卡")
                //	}
                //}
                SaveData();
                EditorUtility.DisplayDialog("保存数据", "保存数据", "ok");
            }
        }