public static void RenderBoundsProperty(VisualElement container, string name, object value, Action <object> setter) { var field = new BoundsField(name); field.SetValueWithoutNotify((Bounds)value); field.MarkDirtyRepaint(); field.RegisterValueChangedCallback(evt => setter(evt.newValue)); container.Add(field); }
void Init() { BoundsField field = new BoundsField() { value = config.value != null ? (Bounds)config.value : new Bounds(), }; field.RegisterValueChangedCallback((e) => { config.OnValueChanged(e.newValue); MarkDirtyRepaint(); }); Add(field); }
public async Task BoundsFieldTest() { var theme = MatterHackers.MatterControl.AppContext.Theme; var testField = new BoundsField(theme); await ValidateAgainstValueMap( testField, theme, (field) => { return(string.Join(",", field.Content.Children.OfType <MHNumberEdit>().Select(w => w.ActuallNumberEdit.Text).ToArray())); }, new List <ValueMap>() { { "0.1,0.2,0.3,0.4", "0.1,0.2,0.3,0.4" }, { "1,2,3,4", "1,2,3,4" }, { ",2,,4", "0,2,0,4" }, // Empty components should revert to 0s { "x,2,y,4", "0,2,0,4" }, // Non-numeric components should revert to 0s { ",2,", "0,0,0,0" }, // Non-vector4 csv should revert to Vector4.Zero }); }
internal override void Apply(VisualElement container) { /// <sample> // Get a reference to the field from UXML and assign it its value. var uxmlField = container.Q <BoundsField>("the-uxml-field"); uxmlField.value = new Bounds(new Vector3(1.1f, 2.2f, 3.3f), new Vector3(2.2f, 4.4f, 6.6f)); // Create a new field, disable it, and give it a style class. var csharpField = new BoundsField("C# Field"); csharpField.SetEnabled(false); csharpField.AddToClassList("some-styled-field"); csharpField.value = uxmlField.value; container.Add(csharpField); // Mirror value of uxml field into the C# field. uxmlField.RegisterCallback <ChangeEvent <Bounds> >((evt) => { csharpField.value = evt.newValue; }); /// </sample> }
void CreateUIElements() { var titleRow = new VisualElement() { style = { flexDirection = FlexDirection.Row, flexShrink = 0f, justifyContent = Justify.SpaceBetween } }; m_VisualElementContainer.Add(new Label("VisualElements Container")); var curveX = AnimationCurve.Linear(0, 0, 1, 0); var popupFieldValues = new List <SomeClass> { new SomeClass("First Class Value"), new SomeClass("Second Value"), new SomeClass("Another Value"), new SomeClass("Another Value with a very lonnnnnnnnnnnnnnnnnnnnnnnnng text to make sure this is really overflowing the popup field.") }; var maskFieldOptions = new List <string>(m_MaskFieldOptions); m_VisualElementContainer.Add(m_IntegerField = new IntegerField()); m_VisualElementContainer.Add(m_LongField = new LongField()); m_VisualElementContainer.Add(m_FloatField = new FloatField()); m_VisualElementContainer.Add(m_DoubleField = new DoubleField()); m_VisualElementContainer.Add(m_EnumField = new EnumField(EnumValues.Two)); m_VisualElementContainer.Add(m_TextField = new TextField()); m_VisualElementContainer.Add(m_PasswordField = new TextField() { isPasswordField = true, maskChar = '*' }); m_VisualElementContainer.Add(m_Vector3Field = new Vector3Field()); m_VisualElementContainer.Add(m_Vector3IntField = new Vector3IntField()); m_VisualElementContainer.Add(m_Vector2Field = new Vector2Field()); m_VisualElementContainer.Add(m_ColorField = new ColorField()); m_VisualElementContainer.Add(m_ObjectFieldCamera = new ObjectField() { objectType = typeof(Camera) }); m_VisualElementContainer.Add(m_ObjectFieldGameObject = new ObjectField() { objectType = typeof(GameObject) }); m_VisualElementContainer.Add(m_CurveField = new CurveField() { value = curveX }); m_VisualElementContainer.Add(m_CurveFieldMesh = new CurveField() { value = curveX, renderMode = CurveField.RenderMode.Mesh }); m_VisualElementContainer.Add(m_PopupField = new PopupField <SomeClass>(popupFieldValues, popupFieldValues[1])); m_VisualElementContainer.Add(m_RectField = new RectField()); m_VisualElementContainer.Add(m_BoundsField = new BoundsField()); m_VisualElementContainer.Add(m_ToggleField = new Toggle()); m_VisualElementContainer.Add(m_MaskField = new MaskField(maskFieldOptions, 6)); m_VisualElementContainer.Add(m_LayerField = new LayerField()); m_VisualElementContainer.Add(m_TagField = new TagField()); m_VisualElementContainer.Add(m_MinMaxSliderField = new MinMaxSlider(5, 10, 0, 125)); m_VisualElementContainer.Add(m_Slider = new Slider(2, 8)); m_VisualElementContainer.Add(m_SliderInt = new SliderInt(11, 23)); var buttonRow = new VisualElement() { style = { flexDirection = FlexDirection.Row, flexShrink = 0f, } }; buttonRow.Add(new Button() { text = k_ButtonLeftTitle, style = { flexGrow = 1 } }); buttonRow.Add(new Button() { text = k_ButtonRightTitle, style = { flexGrow = 1 } }); m_VisualElementContainer.Add(buttonRow); m_VisualElementContainer.Add(new Button() { text = k_ButtonTopTitle }); m_VisualElementContainer.Add(new Button() { text = k_ButtonBottomTitle }); m_VisualElementContainer.Add(m_ColorField1 = new ColorField()); m_VisualElementContainer.Add(m_LayerMaskField = new LayerMaskField(0)); m_VisualElementContainer.Add(m_MultiLineTextField = new TextField() { multiline = true }); m_VisualElementContainer.Add(m_SliderProgressBar = new SliderInt()); m_VisualElementContainer.Add(m_ProgressBar = new ProgressBar()); m_ProgressBar.title = nameof(ProgressBar); m_SliderProgressBar.lowValue = 0; m_SliderProgressBar.highValue = 100; m_SliderProgressBar.bindingPath = nameof(SliderProgressTestObject.exampleValue); m_ProgressBar.bindingPath = nameof(SliderProgressTestObject.exampleValue); m_SliderProgressBar.Bind(SliderProgressTestSO); m_ProgressBar.Bind(SliderProgressTestSO); // The progress bar by itself does not contain any margin in IMGUI... // In this example, we are artifically adding the textfield margin to it. (see below, in the IMGUI section, ProgressBar()) m_ProgressBar.style.marginBottom = 2f; m_VisualElementContainer.Add(m_GradientField = new GradientField()); RefreshUIElements(); }
public DelegateEntryEditor(ExposedDelegateEditor exposedDelegateEditor, DelegateEntry delegateEntry) { this.exposedDelegateEditor = exposedDelegateEditor; this.delegateEntry = delegateEntry; VisualTreeAsset visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/UtilityAI/Scripts/Editor/Delegate Entry Editor/DelegateEntryEditor.uxml"); visualTree.CloneTree(this); StyleSheet stylesheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/UtilityAI/Scripts/Editor/Delegate Entry Editor/DelegateEntryEditor.uss"); this.styleSheets.Add(stylesheet); this.AddToClassList("delegateEntryEditor"); if (exposedDelegateEditor.utilityAIActionEditor.utilityAIAgentEditor.GetType() == typeof(UtilityAIAgentEditor)) { UtilityAIAgentEditor editorWindow = (UtilityAIAgentEditor)exposedDelegateEditor.utilityAIActionEditor.utilityAIAgentEditor; if (delegateEntry.TargetGO != editorWindow.utilityAIAgent.gameObject) { delegateEntry.TargetGO = editorWindow.utilityAIAgent.gameObject; } } delegateEntryFoldout = this.Query <Foldout>("delegateEntry"); delegateEntryFoldout.Query <Toggle>().First().AddToClassList("delegateEntryFoldout"); Button moveUpButton = this.Query <Button>("moveUpButton").First(); moveUpButton.BringToFront(); moveUpButton.clickable.clicked += MoveEntryUp; Button moveDownButton = this.Query <Button>("moveDownButton").First(); moveDownButton.BringToFront(); moveDownButton.clickable.clicked += MoveEntryDown; Button deleteButton = this.Query <Button>("deleteButton").First(); deleteButton.BringToFront(); deleteButton.clickable.clicked += DeleteEntry; List <Component> components = new List <Component>(); if (exposedDelegateEditor.utilityAIActionEditor.utilityAIAgentEditor is UtilityAIAgentEditor) { components = delegateEntry.TargetGO.GetComponents <Component>().ToList(); } else if (exposedDelegateEditor.utilityAIActionEditor.utilityAIAgentEditor is UtilityAIActionSetEditor) { if (((UtilityAIActionSetEditor)exposedDelegateEditor.utilityAIActionEditor.utilityAIAgentEditor).utilityAIAgent.inheritingGameObject != null) { components = ((UtilityAIActionSetEditor)exposedDelegateEditor.utilityAIActionEditor.utilityAIAgentEditor).utilityAIAgent.inheritingGameObject.GetComponents <Component>().ToList(); } } if (components.Count > 0) { int index = 0; if (delegateEntry.Target != null) { List <Component> sharedComponents = components.Where(o => o.GetType() == delegateEntry.Target.GetType()).ToList(); if (sharedComponents.Count > 0) { index = components.IndexOf(sharedComponents[0]); } else { if (exposedDelegateEditor.utilityAIActionEditor.utilityAIAgentEditor is UtilityAIAgentEditor && ((UtilityAIAgentEditor)exposedDelegateEditor.utilityAIActionEditor.utilityAIAgentEditor).utilityAIAgent.actionSet != null) { ((UtilityAIAgentEditor)exposedDelegateEditor.utilityAIActionEditor.utilityAIAgentEditor).utilityAIAgent.MakeActionsSetUnique(); ((UtilityAIAgentEditor)exposedDelegateEditor.utilityAIActionEditor.utilityAIAgentEditor).CreateInspectorGUI(); return; } } } PopupField <Component> targetComponentField = new PopupField <Component>("Component: ", components, index); delegateEntry.Target = targetComponentField.value; targetComponentField.RegisterCallback <ChangeEvent <Component> >( e => { delegateEntry.Target = (Component)e.newValue; exposedDelegateEditor.UpdateDelegateEntries(); } ); delegateEntryFoldout.Add(targetComponentField); if (delegateEntry.Target != null) { Type selectedComponentType = delegateEntry.Target.GetType(); BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly; //Get a list of methods attached to the component, and create a dropdown menu: List <MethodInfo> methods = selectedComponentType.GetMethods(flags).ToList(); PopupField <MethodInfo> targetMethodField = new PopupField <MethodInfo>("Method: ", methods, methods.Contains(delegateEntry.Method) ? methods.IndexOf(delegateEntry.Method) : 0); if (delegateEntry.Method == null || delegateEntry.Method.Name != targetMethodField.value.Name) { delegateEntry.SetMethod(selectedComponentType, targetMethodField.value.Name); } targetMethodField.RegisterCallback <ChangeEvent <MethodInfo> >( e => { delegateEntry.SetMethod(selectedComponentType, e.newValue.Name); exposedDelegateEditor.UpdateDelegateEntries(); } ); delegateEntryFoldout.Add(targetMethodField); if (delegateEntry.Method != null && delegateEntry.Parameters.Length > 0) { Foldout parametersFoldout = new Foldout(); parametersFoldout.text = "Parameters: "; foreach (SerializableObject parameter in delegateEntry.Parameters) { if (parameter.obj is int) { IntegerField parameterField = new IntegerField(); parameterField.value = (int)parameter.obj; parameterField.RegisterCallback <ChangeEvent <int> >( e => { parameter.obj = (int)e.newValue; } ); parametersFoldout.Add(parameterField); } else if (parameter.obj is float) { FloatField parameterField = new FloatField(); parameterField.value = (float)parameter.obj; parameterField.RegisterCallback <ChangeEvent <float> >( e => { parameter.obj = (float)e.newValue; } ); parametersFoldout.Add(parameterField); } else if (parameter.obj is bool) { Toggle parameterField = new Toggle(); parameterField.value = (bool)parameter.obj; parameterField.RegisterCallback <ChangeEvent <bool> >( e => { parameter.obj = (bool)e.newValue; } ); parametersFoldout.Add(parameterField); } else if (parameter.obj is string) { TextField parameterField = new TextField(); parameterField.value = (string)parameter.obj; parameterField.RegisterCallback <ChangeEvent <string> >( e => { parameter.obj = (string)e.newValue; } ); parametersFoldout.Add(parameterField); } else if (parameter.obj is Vector3) { Vector3Field parameterField = new Vector3Field(); parameterField.value = (Vector3)parameter.obj; parameterField.RegisterCallback <ChangeEvent <Vector3> >( e => { parameter.obj = (Vector3)e.newValue; } ); parametersFoldout.Add(parameterField); } else if (parameter.obj is Vector2) { Vector2Field parameterField = new Vector2Field(); parameterField.value = (Vector2)parameter.obj; parameterField.RegisterCallback <ChangeEvent <Vector2> >( e => { parameter.obj = (Vector2)e.newValue; } ); parametersFoldout.Add(parameterField); } else if (parameter.obj is Bounds) { BoundsField parameterField = new BoundsField(); parameterField.value = (Bounds)parameter.obj; parameterField.RegisterCallback <ChangeEvent <Bounds> >( e => { parameter.obj = (Bounds)e.newValue; } ); parametersFoldout.Add(parameterField); } else if (parameter.obj is Rect) { RectField parameterField = new RectField(); parameterField.value = (Rect)parameter.obj; parameterField.RegisterCallback <ChangeEvent <Rect> >( e => { parameter.obj = (Rect)e.newValue; } ); parametersFoldout.Add(parameterField); } else if (parameter.obj is Color) { ColorField parameterField = new ColorField(); parameterField.value = (Color)parameter.obj; parameterField.RegisterCallback <ChangeEvent <Color> >( e => { parameter.obj = (Color)e.newValue; } ); parametersFoldout.Add(parameterField); } else if (parameter.obj is UnityEngine.Object) { ObjectField parameterField = new ObjectField(); parameterField.value = (UnityEngine.Object)parameter.obj; parameterField.RegisterCallback <ChangeEvent <UnityEngine.Object> >( e => { parameter.obj = (UnityEngine.Object)e.newValue; } ); parametersFoldout.Add(parameterField); } } delegateEntryFoldout.Add(parametersFoldout); } } } if (delegateEntry.TargetGO != null) { delegateEntryFoldout.text += delegateEntry.TargetGO.name; if (delegateEntry.Target != null) { delegateEntryFoldout.text += "(" + delegateEntry.Target.GetType() + ") "; if (delegateEntry.Method != null) { delegateEntryFoldout.text += delegateEntry.Method.Name; } } delegateEntryFoldout.text += ": "; } else { delegateEntryFoldout.text = "New Delegate Entry:"; } if (exposedDelegateEditor.utilityAIActionEditor.utilityAIAgentEditor is UtilityAIActionSetEditor && components.Count <= 0) { delegateEntryFoldout.text = "No inheriting object selected!"; } }