- Home /
type of scene asset
I'm making editor window that will perform some operations on scenes(*.unity). And i want to objectfield with just scene support.
I have code something like this:
private void OnGUI() {
scene = EditorGUILayout.ObjectField(scenes[i], typeof (Object), false, null);
//other stuff
}
EditorGUILayout.ObjectField(scenes[i], typeof (<what type?>), false, null);
with that code scene can take any object. What type I need to put just to allow only scenes there? I tried EditorBuildSettingsScene, but it doesn't allow any scene to put in my editor window.
I've no idea off hand - but you can tell by just doing
if(scene != null) Debug.Log(scene.GetType().FullName);
In the code you have and drop a scene into the ObjectField.
it's type - UnityEngine.SceneAsset, unity's internal type
when i use UnityEngine.SceneAsset in my code, the compiler complains that this class name does not exist... ?
Answer by FriesB_DAEStudios · Jun 25, 2014 at 12:40 PM
UnityEngine.SceneAsset is not recognized by the compiler, but you can check if the Object.ToString() ends with "(UnityEngine.SceneAsset)". I used a workaround to create a level manager which creates the order in which levels will be played.
This is how I managed it:
public string LevelName;
private Object _levelScene;
public Object LevelScene
{
get {return _levelScene;}
set
{
//Only set when the value is changed
if(_levelScene != value && value != null)
{
string name = value.ToString();
if(name.Contains(" (UnityEngine.SceneAsset)"))
{
_levelScene = value;
LevelName = name.Substring(0,name.IndexOf(" (UnityEngine.SceneAsset)"));
}
}
}
}
And in editor window:
LevelScene = EditorGUILayout.ObjectField("Scene",LevelScene,typeof(Object),false);
Later, I can load the correct level using the LevelName.
Your answer