111 lines
3.2 KiB
C#
111 lines
3.2 KiB
C#
using System;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.Serialization;
|
|
|
|
namespace Stary.Evo
|
|
{
|
|
[Serializable]
|
|
[CreateAssetMenu(fileName = "DomainConfig", menuName = "Evo/Create DomainConfig")]
|
|
public class DomainConfig : SerializedScriptableObject
|
|
{
|
|
/// <summary>
|
|
/// 域id
|
|
/// </summary>
|
|
[Sirenix.OdinInspector.ReadOnly] public string domain;
|
|
|
|
/// <summary>
|
|
/// 入口命名空间
|
|
/// </summary>
|
|
[Sirenix.OdinInspector.ReadOnly] public string @namespace;
|
|
|
|
/// <summary>
|
|
/// 入口类
|
|
/// </summary>
|
|
[Sirenix.OdinInspector.ReadOnly] public string className;
|
|
|
|
[InfoBox( "Prefab(仅加载预制体) Scene(加载场景)")]
|
|
[OnValueChanged("SetLoadResType")]
|
|
public LoadResType loadResType;
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
[ShowIf("loadResType", LoadResType.Scene)] [OnValueChanged("LoadScenePath")]
|
|
[ValidateInput("ValidateScenePath", "只能使用 本Domain 目录下的场景!", InfoMessageType.Error)]
|
|
public SceneAsset sceneAsset;
|
|
#endif
|
|
[InfoBox( "Static(持久化存在,不可手动卸载) Additive(叠加,可手动卸载) Single(下一个加载自动卸载) ")]
|
|
[ShowIf("loadResType", LoadResType.Prefab)]
|
|
public DomainLoadType domainLoadType;
|
|
|
|
[ShowIf("loadResType", LoadResType.Scene)]
|
|
public LoadSceneMode loadSceneMode;
|
|
/// <summary>
|
|
/// 入口预制体
|
|
/// </summary>
|
|
[Sirenix.OdinInspector.ReadOnly] [ShowIf("loadResType", LoadResType.Prefab)]
|
|
public string mainPrefab;
|
|
|
|
[ShowIf("loadResType", LoadResType.Scene)] [ReadOnly]
|
|
public string scenePath;
|
|
|
|
[ShowIf("loadResType", LoadResType.Scene)] [ReadOnly]
|
|
public string sceneIdentifier;
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
public void LoadScenePath()
|
|
{
|
|
if (sceneAsset == null)
|
|
{
|
|
Debug.LogError($"Scene {scenePath} 资源不存在,请检查!");
|
|
return;
|
|
}
|
|
|
|
scenePath = AssetDatabase.GetAssetPath(sceneAsset);
|
|
sceneIdentifier = $"Scenes_{sceneAsset.name}";
|
|
}
|
|
private bool ValidateScenePath(SceneAsset scene)
|
|
{
|
|
if (scene == null) return true;
|
|
|
|
string path = AssetDatabase.GetAssetPath(scene);
|
|
return path.StartsWith($"Assets/Domain/{domain}/AddressableRes/Scenes/");
|
|
}
|
|
#endif
|
|
private void SetLoadResType()
|
|
{
|
|
if (loadResType == LoadResType.Prefab)
|
|
{
|
|
sceneAsset = null;
|
|
scenePath = null;
|
|
sceneIdentifier = null;
|
|
}
|
|
}
|
|
public enum LoadResType
|
|
{
|
|
Prefab,
|
|
Scene
|
|
}
|
|
|
|
public enum DomainLoadType
|
|
{
|
|
/// <summary>
|
|
/// 下一个加载自动卸载
|
|
/// </summary>
|
|
Single,
|
|
/// <summary>
|
|
/// 叠加,可手动卸载
|
|
/// </summary>
|
|
Additive,
|
|
/// <summary>
|
|
/// 持久化存在,不可手动卸载
|
|
/// </summary>
|
|
Static
|
|
}
|
|
}
|
|
} |