Created
August 28, 2024 18:42
-
-
Save phosphoer/c9c8cd3e19576c001d589cdf514a2ef1 to your computer and use it in GitHub Desktop.
SceneField
This file contains 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
// Taken from http://wiki.unity3d.com/index.php/SceneField | |
using UnityEngine; | |
[System.Serializable] | |
public class SceneField : ISerializationCallbackReceiver | |
{ | |
#if UNITY_EDITOR | |
public UnityEditor.SceneAsset sceneAsset; | |
#endif | |
#pragma warning disable 414 | |
[SerializeField, HideInInspector] | |
private string sceneName = ""; | |
#pragma warning restore 414 | |
// Makes it work with the existing Unity methods (LoadLevel/LoadScene) | |
public static implicit operator string(SceneField sceneField) | |
{ | |
#if UNITY_EDITOR | |
return System.IO.Path.GetFileNameWithoutExtension(UnityEditor.AssetDatabase.GetAssetPath(sceneField.sceneAsset)); | |
#else | |
return sceneField.sceneName; | |
#endif | |
} | |
public void OnBeforeSerialize() | |
{ | |
#if UNITY_EDITOR | |
sceneName = this; | |
#endif | |
} | |
public void OnAfterDeserialize() { } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment