public NullElement(PropertyElement root, IProperty property, PropertyPath path) { m_PotentialTypes = new List <Type> { typeof(Null) }; binding = this; m_Root = root; m_Path = path; name = m_Path.ToString(); TypeConstruction.GetAllConstructableTypes <T>(m_PotentialTypes); if (typeof(T).IsArray) { Resources.Templates.NullStringField.Clone(this); this.Q <Label>().text = GuiFactory.GetDisplayName(property); var button = this.Q <Button>(); button.text = $"Null ({GetTypeName(typeof(T))})"; button.clickable.clicked += ReloadWithArrayType; if (property.IsReadOnly) { button.SetEnabledSmart(false); } return; } if (m_PotentialTypes.Count == 2) { Resources.Templates.NullStringField.Clone(this); this.Q <Label>().text = GuiFactory.GetDisplayName(property); var button = this.Q <Button>(); button.text = $"Null ({GetTypeName(typeof(T))})"; button.clickable.clicked += ReloadWithFirstType; if (property.IsReadOnly) { button.SetEnabledSmart(false); } return; } var typeSelector = new PopupField <Type>( GuiFactory.GetDisplayName(property), m_PotentialTypes, typeof(Null), GetTypeName, GetTypeName); typeSelector.RegisterValueChangedCallback(OnCreateItem); if (property.IsReadOnly) { typeSelector.pickingMode = PickingMode.Ignore; typeSelector.Q(className: UssClasses.Unity.BasePopupFieldInput).SetEnabledSmart(false); } Add(typeSelector); }
public override void Initialize(TreeGraphView graphView, NodeInfo info) { base.Initialize(graphView, info); contextSelector = new PopupField <SerializableMethod>( "Target Context", representativeMethods, 0, method => { if (representativeMethods.Count != 1) { GraphView.editorWindow.SetTargetContextType(contextSelector?.value); } return("Select"); }, method => { if (method == null) { return("Select"); } if (method.Method == null) { return("Missing"); } return(method.TargetContextType.ToString()); } ); typeLabel = new Label("None"); { // Because the choices property in PopupField is internal, which according to https://forum.unity.com/threads/maskfield-choices-internal.672670/ // is a bug. So we will use reflection to set it for now var property = contextSelector.GetType().GetProperty("choices", BindingFlags.Instance | BindingFlags.NonPublic); if (property == null) { throw new Exception("Reflection not working!!!"); } //Should be contextSelector.choices = representativeActions property.SetValue(contextSelector, representativeMethods); } VisualElement parameterContainer = TryGetParameterContainer(); var labelStyle = contextSelector.Q <Label>().style; labelStyle.paddingTop = 0f; labelStyle.paddingLeft = 4f; labelStyle.paddingRight = 7f; contextSelector[1].style.paddingBottom = 0f; //Set selector bottom padding to 0 typeLabel.style.minWidth = labelStyle.minWidth = 64f; typeLabel.style.paddingRight = typeLabel.style.paddingLeft = 8f; inputContainer.style.justifyContent = Justify.Center; inputContainer.Add(contextSelector); parameterContainer.Add(typeLabel); GraphView.editorWindow.OnTargetContextChangedMethods += RecalculateTargetContext; RecalculateTargetContext(); }