Files
plugin-library/Assets/00.StaryEvo/Runtime/PlayerSettings/DomainConfig.cs

117 lines
3.4 KiB
C#
Raw Normal View History

2025-04-11 09:56:06 +08:00
using System;
using Sirenix.OdinInspector;
2025-10-24 19:08:10 +08:00
using UnityEditor;
2025-03-31 11:16:52 +08:00
using UnityEngine;
2025-06-17 11:05:53 +08:00
using UnityEngine.SceneManagement;
2025-10-24 19:08:10 +08:00
using UnityEngine.Serialization;
2025-03-31 11:16:52 +08:00
namespace Stary.Evo
{
2025-04-11 09:56:06 +08:00
[Serializable]
2025-03-31 11:16:52 +08:00
[CreateAssetMenu(fileName = "DomainConfig", menuName = "Evo/Create DomainConfig")]
2025-04-11 09:56:06 +08:00
public class DomainConfig : SerializedScriptableObject
2025-03-31 11:16:52 +08:00
{
/// <summary>
/// 域id
/// </summary>
2025-04-11 09:56:06 +08:00
[Sirenix.OdinInspector.ReadOnly] public string domain;
2026-04-18 12:00:41 +08:00
/// <summary>
/// 程序集
/// </summary>
[Sirenix.OdinInspector.ReadOnly] public string assemblyName;
2025-03-31 11:16:52 +08:00
/// <summary>
/// 入口命名空间
/// </summary>
2025-04-11 09:56:06 +08:00
[Sirenix.OdinInspector.ReadOnly] public string @namespace;
2025-03-31 11:16:52 +08:00
/// <summary>
/// 入口类
/// </summary>
2025-04-11 09:56:06 +08:00
[Sirenix.OdinInspector.ReadOnly] public string className;
2025-03-31 11:16:52 +08:00
2026-04-12 16:48:41 +08:00
[InfoBox( "Prefab(仅加载预制体) Scene(加载场景)")]
[OnValueChanged("SetLoadResType")]
2025-04-11 09:56:06 +08:00
public LoadResType loadResType;
2025-10-31 11:18:23 +08:00
2025-03-31 11:16:52 +08:00
2025-04-11 09:56:06 +08:00
2025-10-24 19:08:10 +08:00
#if UNITY_EDITOR
2026-04-12 16:48:41 +08:00
2025-10-31 11:18:23 +08:00
[ShowIf("loadResType", LoadResType.Scene)] [OnValueChanged("LoadScenePath")]
2026-04-12 16:48:41 +08:00
[ValidateInput("ValidateScenePath", "只能使用 本Domain 目录下的场景!", InfoMessageType.Error)]
2025-10-24 19:08:10 +08:00
public SceneAsset sceneAsset;
#endif
2026-04-12 16:48:41 +08:00
[InfoBox( "Static(持久化存在,不可手动卸载) Additive(叠加,可手动卸载) Single(下一个加载自动卸载) ")]
[ShowIf("loadResType", LoadResType.Prefab)]
public DomainLoadType domainLoadType;
2025-10-31 11:18:23 +08:00
[ShowIf("loadResType", LoadResType.Scene)]
public LoadSceneMode loadSceneMode;
2026-04-12 16:48:41 +08:00
/// <summary>
/// 入口预制体
/// </summary>
[Sirenix.OdinInspector.ReadOnly] [ShowIf("loadResType", LoadResType.Prefab)]
public string mainPrefab;
2025-10-31 11:18:23 +08:00
[ShowIf("loadResType", LoadResType.Scene)] [ReadOnly]
2025-10-24 19:08:10 +08:00
public string scenePath;
2025-10-31 11:18:23 +08:00
[ShowIf("loadResType", LoadResType.Scene)] [ReadOnly]
2025-10-24 19:08:10 +08:00
public string sceneIdentifier;
2025-10-31 11:18:23 +08:00
#if UNITY_EDITOR
2025-10-24 19:08:10 +08:00
public void LoadScenePath()
{
if (sceneAsset == null)
{
Debug.LogError($"Scene {scenePath} 资源不存在,请检查!");
return;
}
2025-10-31 11:18:23 +08:00
2025-10-24 19:08:10 +08:00
scenePath = AssetDatabase.GetAssetPath(sceneAsset);
2025-10-31 11:18:23 +08:00
sceneIdentifier = $"Scenes_{sceneAsset.name}";
2025-10-24 19:08:10 +08:00
}
2026-04-12 16:48:41 +08:00
private bool ValidateScenePath(SceneAsset scene)
{
if (scene == null) return true;
string path = AssetDatabase.GetAssetPath(scene);
return path.StartsWith($"Assets/Domain/{domain}/AddressableRes/Scenes/");
}
2025-10-31 11:18:23 +08:00
#endif
2026-04-12 16:48:41 +08:00
private void SetLoadResType()
{
if (loadResType == LoadResType.Prefab)
{
2026-04-13 13:53:03 +08:00
#if UNITY_EDITOR
2026-04-12 16:48:41 +08:00
sceneAsset = null;
2026-04-13 13:53:03 +08:00
#endif
2026-04-12 16:48:41 +08:00
scenePath = null;
sceneIdentifier = null;
}
}
2025-04-11 09:56:06 +08:00
public enum LoadResType
{
Prefab,
Scene
}
2026-04-12 16:48:41 +08:00
public enum DomainLoadType
{
/// <summary>
/// 下一个加载自动卸载
/// </summary>
Single,
/// <summary>
/// 叠加,可手动卸载
/// </summary>
Additive,
/// <summary>
/// 持久化存在,不可手动卸载
/// </summary>
Static
}
2025-04-11 09:56:06 +08:00
}
2025-03-31 11:16:52 +08:00
}