Created
November 20, 2020 15:21
-
-
Save shana/2eaaf2f21796c258b05ba794d28207d0 to your computer and use it in GitHub Desktop.
Implementation of AssetReferenceT for referencing addressables scene with a nice selector UI in the Unity Inspector.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UnityEditor; | |
using UnityEngine.AddressableAssets; | |
[Serializable] | |
public class AssetReferenceScene : AssetReferenceT<SceneReference> | |
{ | |
/// <summary> | |
/// Constructs a new reference to a GameObject. | |
/// </summary> | |
/// <param name="guid">The object guid.</param> | |
public AssetReferenceScene(string guid) : base(guid) | |
{ | |
} | |
public override bool ValidateAsset(string path) | |
{ | |
#if UNITY_EDITOR | |
var type = AssetDatabase.GetMainAssetTypeAtPath(path); | |
return typeof(SceneAsset).IsAssignableFrom(type); | |
#else | |
return false; | |
#endif | |
} | |
#if UNITY_EDITOR | |
public new SceneAsset editorAsset | |
{ | |
get | |
{ | |
if (CachedAsset != null || string.IsNullOrEmpty(AssetGUID)) | |
return CachedAsset as SceneAsset; | |
var assetPath = AssetDatabase.GUIDToAssetPath(AssetGUID); | |
var main = AssetDatabase.LoadMainAssetAtPath(assetPath) as SceneAsset; | |
if (main != null) | |
CachedAsset = main; | |
return main; | |
} | |
} | |
#endif | |
} | |
[Serializable] | |
public class SceneReference : UnityEngine.Object | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment