protected override void VisitContainer <TContainer>(ref TContainer target) { if (Inspector.TryGetTarget(out TContainer currentTarget) && RuntimeTypeInfoCache <TContainer> .CanBeNull && EqualityComparer <TContainer> .Default.Equals(currentTarget, target)) { return; } Inspector.SetTarget(target); // In the inspector, the size of the content will depend on the size of the children (there is // intentionally no "expand to take all available size"), while in an editor window, you can expand your // content to take the full size of the window. For this window, users can choose between the default // window behaviour and the inspector behaviour. To support this, we will force the root to fully expand. // When a custom inspector is provided, we need to adjust the CustomInspectorElement to also fully expand. if (Inspector.childCount == 1 && Inspector[0] is CustomInspectorElement customInspector && customInspector.IsRootInspector) { customInspector.style.flexGrow = 1; } if (Content.InspectionContext.ApplyInspectorStyling) { StylingUtility.AlignInspectorLabelWidth(Inspector); } Content.Save(); }
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); }
public override void OnActivate(string searchContext, VisualElement rootElement) { // TODO: Switch to use uxml/uss for this. var root = new VisualElement(); rootElement.Add(root); var title = new Label(Title); title.style.unityFontStyleAndWeight = FontStyle.Bold; title.style.marginTop = 1; title.style.fontSize = 19; title.style.unityTextAlign = TextAnchor.MiddleLeft; title.style.height = 26; root.Add(title); Resources.Templates.Settings.AddStyles(rootElement); foreach (var kvp in s_Settings) { if (kvp.Value.All(w => w.Internal) && !Unsupported.IsDeveloperMode()) { continue; } var label = new Label { text = kvp.Key }; label.style.unityFontStyleAndWeight = FontStyle.Bold; root.Add(label); foreach (var wrapper in kvp.Value) { if (wrapper.Internal && !Unsupported.IsDeveloperMode()) { continue; } var setting = wrapper.Setting; var element = new PropertyElement(); element.style.marginLeft = -3; element.SetAttributeFilter(AttributeFilter); element.SetTarget(setting); element.OnChanged += (propertyElement, path) => setting.OnSettingChanged(path); root.Add(element); element.RegisterCallback <GeometryChangedEvent>(evt => StylingUtility.AlignInspectorLabelWidth(element)); } } root.AddToClassList("unity-inspector-element"); root.style.paddingLeft = 10; base.OnActivate(searchContext, rootElement); }
public void Update() { if (!IsValid) { return; } if (null != m_ContentRoot && InspectionContext.ApplyInspectorStyling) { StylingUtility.AlignInspectorLabelWidth(m_ContentRoot); } var state = Provider.MoveNext(); if (m_PreviousState != state) { m_ContentRoot?.ClearTarget(); switch (state) { case ContentStatus.ContentUnavailable: return; case ContentStatus.ContentNotReady: SetNotReadyContent(); break; case ContentStatus.ContentReady: SetTarget(); break; case ContentStatus.ReloadContent: SetNotReadyContent(); Load(); break; default: throw new ArgumentOutOfRangeException(); } } m_PreviousState = state; }
static void OnGeometryChanged(GeometryChangedEvent evt, BindableElement root) { StylingUtility.AlignInspectorLabelWidth(root); }
void OnGeometryChanged(GeometryChangedEvent evt) { StylingUtility.AlignInspectorLabelWidth(m_ComponentsRoot); }
void IBinding.Update() { StylingUtility.AlignInspectorLabelWidth(m_ComponentsRoot); }
public void Initialize() { m_ContentRoot = new InspectorElement(); m_ContentRoot.OnChanged += (element, path) => { Provider.OnContentChanged(new ContentProvider.ChangeContext(element)); }; m_ContentRoot.AddContext(InspectionContext); if (InspectionContext.ApplyInspectorStyling) { m_ContentRoot.RegisterCallback <GeometryChangedEvent, VisualElement>((evt, element) => StylingUtility.AlignInspectorLabelWidth(element), m_ContentRoot); } m_ContentNotReadyRoot = new InspectorElement(); Root.contentContainer.Add(m_ContentRoot); Root.contentContainer.Add(m_ContentNotReadyRoot); m_ContentRoot.style.flexGrow = 1; }