Skip to content

Instantly share code, notes, and snippets.

@phosphoer
Created August 28, 2024 18:42
Show Gist options
  • Save phosphoer/c9c8cd3e19576c001d589cdf514a2ef1 to your computer and use it in GitHub Desktop.
Save phosphoer/c9c8cd3e19576c001d589cdf514a2ef1 to your computer and use it in GitHub Desktop.
SceneField
// 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