diff --git a/Editor/Assets/UnifiedScenePropertyDrawer.cs b/Editor/Assets/UnifiedScenePropertyDrawer.cs index dce50a8..c5df4b8 100644 --- a/Editor/Assets/UnifiedScenePropertyDrawer.cs +++ b/Editor/Assets/UnifiedScenePropertyDrawer.cs @@ -8,34 +8,54 @@ 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) { +#if USE_MEW_CORE_ASSETS var sceneAssetReferenceProperty = property.FindPropertyRelative(SceneAssetReferenceKBackingField); + var addressableSceneKeyProperty = property.FindPropertyRelative(AddressableSceneKeyKBackingField); +#endif var sceneReferenceProperty = property.FindPropertyRelative(SceneReferenceKBackingField); + +#if USE_MEW_CORE_ASSETS var sceneAssetReference = sceneAssetReferenceProperty.boxedValue as SceneAssetReference; + var addressableSceneKey = addressableSceneKeyProperty.boxedValue as AddressablesSceneKey; +#endif var sceneReference = sceneReferenceProperty.boxedValue as SceneReference; - var drawer = new LayoutDrawer(); +#if USE_MEW_CORE_ASSETS var isAssetReference = !string.IsNullOrEmpty(sceneAssetReference.AssetGUID); + var isAddressableSceneKey = addressableSceneKey is not null; +#else + const bool isAssetReference = false; + const bool isAddressableSceneKey = false; +#endif var isSceneReference = sceneReference.IsValid; - var labelText = isAssetReference + var drawer = new LayoutDrawer(); + var labelText = (isAssetReference || isAddressableSceneKey) ? $"{label.text} (Addressables)" : isSceneReference ? $"{label.text} : (Build Settings)" : $"{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); EditorGUI.indentLevel++; + +#if USE_MEW_CORE_ASSETS if (isAssetReference) { drawer.DrawProperty(position, sceneAssetReferenceProperty); } + else if (isAddressableSceneKey) + { + drawer.DrawProperty(position, addressableSceneKeyProperty); + } else if (isSceneReference) { drawer.DrawProperty(position, sceneReferenceProperty); @@ -44,7 +64,12 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten { drawer.DrawProperty(position, sceneAssetReferenceProperty); drawer.DrawProperty(position, sceneReferenceProperty); + drawer.DrawProperty(position, addressableSceneKeyProperty); } +#else + drawer.DrawProperty(position, sceneReferenceProperty); +#endif + EditorGUI.indentLevel--; if (!isAssetReference && !isSceneReference) GUI.color = originalColor; @@ -83,26 +108,43 @@ public override float GetPropertyHeight(SerializedProperty property, GUIContent { var sceneAssetReferenceProperty = property.FindPropertyRelative(SceneAssetReferenceKBackingField); var sceneReferenceProperty = property.FindPropertyRelative(SceneReferenceKBackingField); + var addressableSceneKeyProperty = property.FindPropertyRelative(AddressableSceneKeyKBackingField); +#if USE_MEW_CORE_ASSETS var sceneAssetReference = sceneAssetReferenceProperty.boxedValue as SceneAssetReference; + var addressableSceneKey = addressableSceneKeyProperty.boxedValue as AddressablesSceneKey; +#endif var sceneReference = sceneReferenceProperty.boxedValue as SceneReference; var fixedHeight = EditorGUI.GetPropertyHeight(SerializedPropertyType.String, label); - if (!string.IsNullOrEmpty(sceneAssetReference.AssetGUID)) + if (sceneReference.IsValid) + { + return fixedHeight + + EditorGUI.GetPropertyHeight(sceneReferenceProperty); + } +#if USE_MEW_CORE_ASSETS + else if (!string.IsNullOrEmpty(sceneAssetReference.AssetGUID)) { return fixedHeight + EditorGUI.GetPropertyHeight(sceneAssetReferenceProperty); } - else if (sceneReference.IsValid) + else if (addressableSceneKey is not null) { return fixedHeight + - EditorGUI.GetPropertyHeight(sceneReferenceProperty); + EditorGUI.GetPropertyHeight(addressableSceneKeyProperty); } +#endif else { +#if USE_MEW_CORE_ASSETS return fixedHeight + EditorGUI.GetPropertyHeight(sceneAssetReferenceProperty) + + EditorGUI.GetPropertyHeight(sceneReferenceProperty) + + EditorGUI.GetPropertyHeight(addressableSceneKeyProperty); +#else + return fixedHeight + EditorGUI.GetPropertyHeight(sceneReferenceProperty); +#endif } } } 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)