VR4Medical/ICI/Library/PackageCache/com.unity.learn.iet-framework@4bd5247958fc/Editor/Property Drawers/SceneObjectReferencePropertyDrawer.cs
2025-07-29 13:45:50 +03:00

41 lines
1.2 KiB
C#

using UnityEditor;
using UnityEngine;
namespace Unity.Tutorials.Core.Editor
{
[CustomPropertyDrawer(typeof(SceneObjectReference))]
class SceneObjectReferencePropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var sor = new SceneObjectReference(property);
var origColor = GUI.color;
if (!sor.ReferenceResolved)
{
label.text = "(Not resolved) " + label.text;
GUI.color = Color.red;
}
label = EditorGUI.BeginProperty(position, label, property);
position = EditorGUI.PrefixLabel(position, label);
GUI.color = origColor;
Object obj = sor.ReferencedObject;
if (!sor.ReferenceResolved)
{
obj = sor.ReferenceScene;
}
EditorGUI.BeginChangeCheck();
var newObj = EditorGUI.ObjectField(position, obj, typeof(Object), true);
if (EditorGUI.EndChangeCheck())
{
sor.Update(newObj);
}
EditorGUI.EndProperty();
}
}
}