diff --git a/Editor/Assets/UnifiedScenePropertyDrawer.cs b/Editor/Assets/UnifiedScenePropertyDrawer.cs index dce50a8..336c3ae 100644 --- a/Editor/Assets/UnifiedScenePropertyDrawer.cs +++ b/Editor/Assets/UnifiedScenePropertyDrawer.cs @@ -8,17 +8,21 @@ public class UnifiedScenePropertyDrawer : PropertyDrawer { private const string SceneAssetReferenceKBackingField = "k__BackingField"; private const string SceneReferenceKBackingField = "k__BackingField"; + private const string AddressableSceneKeyKBackingField = "k__BackingField"; public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var sceneAssetReferenceProperty = property.FindPropertyRelative(SceneAssetReferenceKBackingField); var sceneReferenceProperty = property.FindPropertyRelative(SceneReferenceKBackingField); + var addressableSceneKeyProperty = property.FindPropertyRelative(AddressableSceneKeyKBackingField); var sceneAssetReference = sceneAssetReferenceProperty.boxedValue as SceneAssetReference; var sceneReference = sceneReferenceProperty.boxedValue as SceneReference; + var addressableSceneKey = addressableSceneKeyProperty.boxedValue as AddressablesSceneKey; var drawer = new LayoutDrawer(); var isAssetReference = !string.IsNullOrEmpty(sceneAssetReference.AssetGUID); var isSceneReference = sceneReference.IsValid; + var isAddressableSceneKey = addressableSceneKey is not null; var labelText = isAssetReference ? $"{label.text} (Addressables)" @@ -27,7 +31,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten : $"{label.text} : Select scene"; var customLabel = new GUIContent(labelText); var originalColor = GUI.color; - if (!isAssetReference && !isSceneReference) + if (!isAssetReference && !isSceneReference && !isAddressableSceneKey) GUI.color = Color.yellow; drawer.DrawLabel(position, customLabel); @@ -40,10 +44,15 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten { drawer.DrawProperty(position, sceneReferenceProperty); } + else if (isAddressableSceneKey) + { + drawer.DrawProperty(position, addressableSceneKeyProperty); + } else { drawer.DrawProperty(position, sceneAssetReferenceProperty); drawer.DrawProperty(position, sceneReferenceProperty); + drawer.DrawProperty(position, addressableSceneKeyProperty); } EditorGUI.indentLevel--; if (!isAssetReference && !isSceneReference) @@ -83,8 +92,10 @@ public override float GetPropertyHeight(SerializedProperty property, GUIContent { var sceneAssetReferenceProperty = property.FindPropertyRelative(SceneAssetReferenceKBackingField); var sceneReferenceProperty = property.FindPropertyRelative(SceneReferenceKBackingField); + var addressableSceneKeyProperty = property.FindPropertyRelative(AddressableSceneKeyKBackingField); var sceneAssetReference = sceneAssetReferenceProperty.boxedValue as SceneAssetReference; var sceneReference = sceneReferenceProperty.boxedValue as SceneReference; + var addressableSceneKey = addressableSceneKeyProperty.boxedValue as AddressablesSceneKey; var fixedHeight = EditorGUI.GetPropertyHeight(SerializedPropertyType.String, label); @@ -98,11 +109,17 @@ public override float GetPropertyHeight(SerializedProperty property, GUIContent return fixedHeight + EditorGUI.GetPropertyHeight(sceneReferenceProperty); } + else if (addressableSceneKey is not null) + { + return fixedHeight + + EditorGUI.GetPropertyHeight(addressableSceneKeyProperty); + } else { return fixedHeight + EditorGUI.GetPropertyHeight(sceneAssetReferenceProperty) + - EditorGUI.GetPropertyHeight(sceneReferenceProperty); + EditorGUI.GetPropertyHeight(sceneReferenceProperty) + + EditorGUI.GetPropertyHeight(addressableSceneKeyProperty); } } } diff --git a/Runtime/Assets/Scene/AddressablesSceneKey.cs b/Runtime/Assets/Scene/AddressablesSceneKey.cs new file mode 100644 index 0000000..f32aa80 --- /dev/null +++ b/Runtime/Assets/Scene/AddressablesSceneKey.cs @@ -0,0 +1,13 @@ +#if USE_MEW_CORE_ASSETS +using UnityEngine; + +namespace Mew.Core.Assets +{ + [CreateAssetMenu(menuName = "MewCore/AddressableSceneKey", fileName = "AddressableSceneKey", order = 0)] + public class AddressablesSceneKey : ScriptableObject + { + [field: SerializeField] public string RuntimeKey { get; set; } + public AddressablesSceneKey(string runtimeKey) { RuntimeKey = runtimeKey; } + } +} +#endif \ No newline at end of file diff --git a/Runtime/Assets/Scene/AddressablesSceneKey.cs.meta b/Runtime/Assets/Scene/AddressablesSceneKey.cs.meta new file mode 100644 index 0000000..f1880c8 --- /dev/null +++ b/Runtime/Assets/Scene/AddressablesSceneKey.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a7d9845084884dafaf4440978efd0994 +timeCreated: 1707192202 \ No newline at end of file diff --git a/Runtime/Assets/Scene/UnifiedScene.cs b/Runtime/Assets/Scene/UnifiedScene.cs index 16f437c..9435ccf 100644 --- a/Runtime/Assets/Scene/UnifiedScene.cs +++ b/Runtime/Assets/Scene/UnifiedScene.cs @@ -11,6 +11,7 @@ public class UnifiedScene { #if USE_MEW_CORE_ASSETS [field: SerializeField] public SceneAssetReference SceneAssetReference { get; set; } + [field: SerializeField] public AddressablesSceneKey AddressablesSceneKey { get; set; } public IResourceLocation SceneResourceLocation { get; set; } #endif [field: SerializeField] public SceneReference SceneReference { get; set; } @@ -32,6 +33,18 @@ public bool IsSceneAssetReference } } + public bool IsAddressablesSceneKey + { + get + { +#if USE_MEW_CORE_ASSETS + return AddressablesSceneKey is not null; +#else + return false; +#endif + } + } + public bool IsSceneResourceLocation { get @@ -44,9 +57,9 @@ public bool IsSceneResourceLocation } } - private bool IsValidInternal => IsSceneReference || IsSceneAssetReference || IsSceneResourceLocation; + private bool IsValidInternal => IsSceneReference || IsSceneAssetReference || IsSceneResourceLocation || IsAddressablesSceneKey; #if UNITY_EDITOR - public bool IsValid => IsValidInternal || !string.IsNullOrEmpty(EditorScenePath); + public bool IsValid => IsValidInternal || !string.IsNullOrEmpty(EditorScenePath); #else public bool IsValid => IsValidInternal; #endif diff --git a/Runtime/Assets/Scene/UnifiedSceneLoader.cs b/Runtime/Assets/Scene/UnifiedSceneLoader.cs index 6234fd1..3b7625a 100644 --- a/Runtime/Assets/Scene/UnifiedSceneLoader.cs +++ b/Runtime/Assets/Scene/UnifiedSceneLoader.cs @@ -32,6 +32,11 @@ public static async Task LoadAsync(UnifiedScene unifiedScene, Canc var h = Addressables.LoadSceneAsync(unifiedScene.SceneAssetReference, parameters); handle = new SceneInstanceHandle(h); } + else if (unifiedScene.IsAddressablesSceneKey) + { + var h = Addressables.LoadSceneAsync(unifiedScene.AddressablesSceneKey.RuntimeKey, parameters); + handle = new SceneInstanceHandle(h); + } else #endif if (unifiedScene.SceneReference is not null && unifiedScene.SceneReference.IsValid)