Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using UnityEngine;
  2. #if UNITY_EDITOR
  3. using UnityEditor;
  4. #endif
  5. [System.Serializable]
  6. public class SceneField
  7. {
  8.     [SerializeField]
  9.     private Object m_SceneAsset;
  10.     [SerializeField]
  11.     private string m_SceneName = "";
  12.     public string SceneName
  13.     {
  14.         get { return m_SceneName; }
  15.     }
  16.     // makes it work with the existing Unity methods (LoadLevel/LoadScene)
  17.     public static implicit operator string(SceneField sceneField)
  18.     {
  19.         return sceneField.SceneName;
  20.     }
  21. }
  22. #if UNITY_EDITOR
  23. [CustomPropertyDrawer(typeof(SceneField))]
  24. public class SceneFieldPropertyDrawer : PropertyDrawer
  25. {
  26.     public override void OnGUI(Rect _position, SerializedProperty _property, GUIContent _label)
  27.     {
  28.         EditorGUI.BeginProperty(_position, GUIContent.none, _property);
  29.         SerializedProperty sceneAsset = _property.FindPropertyRelative("m_SceneAsset");
  30.         SerializedProperty sceneName = _property.FindPropertyRelative("m_SceneName");
  31.         _position = EditorGUI.PrefixLabel(_position, GUIUtility.GetControlID(FocusType.Passive), _label);
  32.         if (sceneAsset != null)
  33.         {
  34.             sceneAsset.objectReferenceValue = EditorGUI.ObjectField(_position, sceneAsset.objectReferenceValue, typeof(SceneAsset), false);
  35.             if (sceneAsset.objectReferenceValue != null)
  36.             {
  37.                 sceneName.stringValue = (sceneAsset.objectReferenceValue as SceneAsset).name;
  38.             }
  39.         }
  40.         EditorGUI.EndProperty();
  41.     }
  42. }
  43. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement