IndieGame/client/Assets/Scripts/Config/Global/Editor/GlobalWindow.cs
DOBEST\zhaoyingjie f242607587 初始化工程
2024-10-11 10:12:15 +08:00

58 lines
1.7 KiB
C#

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);
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;
}
}
}