Created
May 19, 2015 02:10
-
-
Save rutcreate/b02738c5d81dc9811e79 to your computer and use it in GitHub Desktop.
Unity3D Editor: Scene popup
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
using UnityEngine; | |
using System.Collections; | |
public class ScenePopup : PropertyAttribute { | |
public bool required = false; | |
public ScenePopup() {} | |
public ScenePopup(bool required) { | |
this.required = required; | |
} | |
} |
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
using UnityEngine; | |
using UnityEditor; | |
using System.IO; | |
using System.Collections; | |
using System.Collections.Generic; | |
[CustomPropertyDrawer(typeof(ScenePopup))] | |
public class ScenePopupDrawer : PropertyDrawer { | |
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { | |
if (property.propertyType != SerializedPropertyType.Integer) { | |
EditorGUI.PropertyField(position, property); | |
return; | |
} | |
List<GUIContent> sceneNames = new List<GUIContent>(); | |
List<int> sceneValues = new List<int>(); | |
ScenePopup scenePopup = attribute as ScenePopup; | |
if (!scenePopup.required) { | |
sceneNames.Add(new GUIContent("- None -")); | |
sceneValues.Add(-1); | |
} | |
for (int i = 0; i < EditorBuildSettings.scenes.Length; i++) { | |
EditorBuildSettingsScene scene = EditorBuildSettings.scenes[i]; | |
if (scene.enabled) { | |
string name = Path.GetFileName(scene.path); | |
sceneNames.Add(new GUIContent(name)); | |
sceneValues.Add(i); | |
} | |
} | |
EditorGUI.IntPopup(position, property, sceneNames.ToArray(), sceneValues.ToArray()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment