IndieGame/client/Assets/Scripts/Config/Global/Editor/GlobalWindow.cs

58 lines
1.7 KiB
C#
Raw Normal View History

2024-10-11 10:12:15 +08:00

using DG.Tweening.Plugins.Core.PathCore;
using PlasticGui.WorkspaceWindow.Items;
using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using Unity.VisualScripting;
using UnityEditor;
using UnityEditor.ShortcutManagement;
using UnityEngine;
namespace Ether
{
public class GlobalWindow : OdinMenuEditorWindow
{
[MenuItem("配置/全局配置")]
[Shortcut("打开全局配置", KeyCode.F1)]
private static void OpenWindow()
{
var window = GetWindow<GlobalWindow>();
window.titleContent = new GUIContent("全局配置");
}
protected override OdinMenuTree BuildMenuTree()
{
var tree = new OdinMenuTree();
tree.Selection.SupportsMultiSelect = false;
GlobalSettings settings = AssetDatabase.LoadAssetAtPath<GlobalSettings>(PathConst.globalSettingsPath);
2024-10-11 10:12:15 +08:00
if (settings == null)
{
settings = ScriptableObject.CreateInstance<GlobalSettings>();
string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(PathConst.globalSettingsPath);
AssetDatabase.CreateAsset(settings, assetPathAndName);
// 最后刷新 AssetDatabase 来确保文件已经被正确保存
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
Selection.activeObject = settings;
}
EditorUtility.SetDirty(settings);
tree.Add("全局设置", settings);
return tree;
}
}
}