public override VisualElement CreateInspectorGUI() { var root = new BindableElement(); var monoScript = new ObjectField("Script") { value = MonoScript.FromMonoBehaviour(Target) }; monoScript.Q <Label>().style.paddingLeft = 0; monoScript.Q(className: "unity-object-field__selector").SetEnabled(false); monoScript.RegisterCallback <ChangeEvent <UnityEngine.Object>, ObjectField>( (evt, element) => element.value = evt.previousValue, monoScript); root.contentContainer.Add(monoScript); m_RootElement = new InspectorElement(); m_RootElement.RegisterCallback <AttachToPanelEvent, (InspectorElement inspector, PropertyBehaviour target)>((evt, ctx) => { ctx.inspector.SetTarget(ctx.target); }, (m_RootElement, Target)); m_RootElement.OnChanged += (element, path) => { Target.Save(); }; root.contentContainer.Add(m_RootElement); root.AddToClassList("unity-inspector-element"); StylingUtility.AlignInspectorLabelWidth(root); root.RegisterCallback <GeometryChangedEvent, BindableElement>(OnGeometryChanged, root); return(root); }
/// <summary> /// Creates a new instance of <see cref="InspectorElement"/> with the provided target value. /// </summary> /// <param name="value">The target.</param> /// <typeparam name="TValue">The target type.</typeparam> /// <returns>The new instance.</returns> public static InspectorElement MakeWithValue <TValue>(TValue value) { var element = new InspectorElement(); element.SetTarget(value); return(element); }