4 namespace HKI.Core.Scenes.Editor
13 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
16 if (property.propertyType == SerializedPropertyType.String)
18 var sceneObject = GetSceneObject(property.stringValue);
19 var scene = EditorGUI.ObjectField(position, label, sceneObject, typeof(SceneAsset),
true);
22 property.stringValue =
"";
24 else if (scene.name != property.stringValue)
26 var sceneObj = GetSceneObject(scene.name);
29 Debug.LogWarning(
"The scene " + scene.name +
" cannot be used. To use this scene add it to the build settings for the project");
33 property.stringValue = scene.name;
38 EditorGUI.LabelField(position, label.text,
"Use [Scene] with strings.");
44 if (
string.IsNullOrEmpty(sceneObjectName))
49 foreach (var editorScene
in EditorBuildSettings.scenes)
51 if (editorScene.path.IndexOf(sceneObjectName) != -1)
53 return AssetDatabase.LoadAssetAtPath(editorScene.path, typeof(SceneAsset)) as SceneAsset;
56 Debug.LogWarning(
"Scene [" + sceneObjectName +
"] cannot be used. Add this scene to the 'Scenes in the Build' in build settings.");
SceneAsset GetSceneObject(string sceneObjectName)
override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
Custom property drawer for the SceneAttribute class.
This PropertyAttribute is for using the scene object like other objects in Unity and draged to a Prop...