public static void RenderVector3IntProperty(VisualElement container, string name, object value, Action <object> setter) { var field = new Vector3IntField(name); field.SetValueWithoutNotify((Vector3Int)value); field.MarkDirtyRepaint(); field.RegisterValueChangedCallback(evt => setter(evt.newValue)); container.Add(field); }
void Init() { Vector3IntField field = new Vector3IntField() { value = config.value != null ? (Vector3Int)config.value : new Vector3Int(), }; field.EnableInClassList("compositeField", false); field.RegisterValueChangedCallback((e) => { config.OnValueChanged(e.newValue); MarkDirtyRepaint(); }); Add(field); }
internal override void Apply(VisualElement container) { /// <sample> // Get a reference to the field from UXML and assign it its value. var uxmlField = container.Q <Vector3IntField>("the-uxml-field"); uxmlField.value = new Vector3Int(23, 12, 88); // Create a new field, disable it, and give it a style class. var csharpField = new Vector3IntField("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 <Vector3Int> >((evt) => { csharpField.value = evt.newValue; }); /// </sample> }
private VisualElement CreateExportSettingsView() { var settingsContainer = new VisualElement() { name = Styles.exportSettings }; settingsContainer.AddToClassList(Styles.exportSettings); var exportTypes = new List <ExportTextureType>() { ExportTextureType.Texture2D, ExportTextureType.Texture3D }; var exportType = new PopupField <ExportTextureType>(exportTypes, exportTypes[0]) { name = Styles.exportType, label = "Texture Type" }; exportType.RegisterCallback <ChangeEvent <ExportTextureType> >( (evt) => { if (evt.newValue == ExportTextureType.Texture2D) { m_exportSettings.Remove(m_exportDims3D); m_exportSettings.Insert(1, m_exportDims2D); } else if (evt.newValue == ExportTextureType.Texture3D) { m_exportSettings.Remove(m_exportDims2D); m_exportSettings.Insert(1, m_exportDims3D); } } ); var dimensionsField2D = new Vector2IntField() { name = Styles.exportDims2D, label = "Dimensions", value = new Vector2Int(512, 512) }; var dimensionsField3D = new Vector3IntField() { name = Styles.exportDims3D, label = "Dimensions", value = new Vector3Int(64, 64, 64) }; var m_listOfFormats = new List <GraphicsFormat>() { // GraphicsFormat.R8_UNorm, // GraphicsFormat.R8_SNorm, GraphicsFormat.R16_UNorm, // GraphicsFormat.R16_SNorm, GraphicsFormat.R16_SFloat, // GraphicsFormat.R32_SFloat, }; var exportFormat = new PopupField <GraphicsFormat>(m_listOfFormats, GraphicsFormat.R16_UNorm) { name = Styles.exportFormat, label = "Texture Format" }; settingsContainer.Add(exportType); settingsContainer.Add(dimensionsField2D); settingsContainer.Add(exportFormat); m_exportSettings = settingsContainer; m_exportType = exportType; m_exportDims2D = dimensionsField2D; m_exportDims3D = dimensionsField3D; m_exportFormat = exportFormat; exportType.value = ExportTextureType.Texture2D; return(settingsContainer); }
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 override VisualElement CreatePropertyGUI(SerializedProperty property) { BindableElement newField = null; if (property.propertyType == SerializedPropertyType.Float) { if (property.type == "float") { newField = new FloatField(property.displayName); ((BaseField <float>)newField).onValidateValue += OnValidateValue; } else if (property.type == "double") { newField = new DoubleField(property.displayName); ((BaseField <double>)newField).onValidateValue += OnValidateValue; } } else if (property.propertyType == SerializedPropertyType.Integer) { if (property.type == "int") { newField = new IntegerField(property.displayName); ((BaseField <int>)newField).onValidateValue += OnValidateValue; } else if (property.type == "long") { newField = new LongField(property.displayName); ((BaseField <long>)newField).onValidateValue += OnValidateValue; } } else if (property.propertyType == SerializedPropertyType.Vector2) { newField = new Vector2Field(property.displayName); ((BaseField <Vector2>)newField).onValidateValue += OnValidateValue; } else if (property.propertyType == SerializedPropertyType.Vector2Int) { newField = new Vector2IntField(property.displayName); ((BaseField <Vector2Int>)newField).onValidateValue += OnValidateValue; } else if (property.propertyType == SerializedPropertyType.Vector3) { newField = new Vector3Field(property.displayName); ((BaseField <Vector3>)newField).onValidateValue += OnValidateValue; } else if (property.propertyType == SerializedPropertyType.Vector3Int) { newField = new Vector3IntField(property.displayName); ((BaseField <Vector3Int>)newField).onValidateValue += OnValidateValue; } else if (property.propertyType == SerializedPropertyType.Vector4) { newField = new Vector4Field(property.displayName); ((BaseField <Vector4>)newField).onValidateValue += OnValidateValue; } if (newField != null) { newField.bindingPath = property.propertyPath; return(newField); } return(new Label(s_InvalidTypeMessage)); }
protected VisualElement CreateParameterControl(SingularSerializableParameter parameter, string controlName, Action <SingularSerializableParameter> clampAction = null) { VisualElement control; switch (parameter.Type) { case ParameterType.behaviorAction: control = new VisualElement(); var buttons = new VisualElement { style = { flexDirection = FlexDirection.Row, paddingRight = 2f, paddingLeft = 2f } }; var actionLabel = new Label { style = { paddingLeft = 8f, paddingRight = 8f } }; var configureButton = new Button { text = "Configure" }; configureButton.clickable.clickedWithEventInfo += clickEvent => { var worldPosition = clickEvent.originalMousePosition + GraphView.editorWindow.position.position; GraphView.actionSearcher.TargetParameter = parameter; SearchWindow.Open(new SearchWindowContext(worldPosition), GraphView.actionSearcher); }; var removeButton = new Button(() => parameter.BehaviorActionValue = null) { text = "Remove" }; buttons.Add(configureButton); buttons.Add(removeButton); control.Add(actionLabel); control.Add(buttons); parameter.OnValueChangedMethods += OnBehaviorActionChanged; OnBehaviorActionChanged(); //Trigger a refresh void OnBehaviorActionChanged() { parameter.LoadBehaviorAction(GraphView.editorWindow.ImportData); //Refresh action name actionLabel.text = parameter.BehaviorActionValue == null ? "Missing Action" : parameter.BehaviorActionValue.ToString(); //Behavior action parameter controls const string ParameterGroupName = "Behavior Action Parameters Group"; VisualElement group = control.Q <VisualElement>(ParameterGroupName); if (group != null) { control.Remove(group); //If had old group remove/destroy it } var parameters = parameter.BehaviorActionValue?.method.Parameters; if (parameters == null || parameters.Count == 0) { return; //If no parameter for this action } group = new VisualElement { name = ParameterGroupName }; //Create group var accessor = ((SerializableParameter)parameter).BehaviorActionParameters; for (int i = 0; i < parameters.Count; i++) { BehaviorActionParameterInfo parameterInfo = parameters[i]; group.Add(CreateParameterControl(accessor[i], parameterInfo.name)); } control.Add(group); } break; case ParameterType.boolean: var toggle = new Toggle(controlName) { value = parameter.BooleanValue }; toggle.RegisterValueChangedCallback( changeEvent => { parameter.BooleanValue = changeEvent.newValue; clampAction?.Invoke(parameter); toggle.SetValueWithoutNotify(parameter.BooleanValue); } ); control = toggle; break; case ParameterType.enumeration: control = new EnumField(); //TODO break; case ParameterType.integer1: var integerField = new IntegerField(controlName) { value = parameter.Integer1Value }; integerField.RegisterValueChangedCallback( changeEvent => { parameter.Integer1Value = changeEvent.newValue; clampAction?.Invoke(parameter); integerField.SetValueWithoutNotify(parameter.Integer1Value); } ); control = integerField; break; case ParameterType.integer2: var vector2IntField = new Vector2IntField(controlName) { value = parameter.Integer2Value }; vector2IntField.RegisterValueChangedCallback( changeEvent => { parameter.Integer2Value = changeEvent.newValue; clampAction?.Invoke(parameter); vector2IntField.SetValueWithoutNotify(parameter.Integer2Value); } ); control = vector2IntField; break; case ParameterType.integer3: var vector3IntField = new Vector3IntField(controlName) { value = parameter.Integer3Value }; vector3IntField.RegisterValueChangedCallback( changeEvent => { parameter.Integer3Value = changeEvent.newValue; clampAction?.Invoke(parameter); vector3IntField.SetValueWithoutNotify(parameter.Integer3Value); } ); control = vector3IntField; break; case ParameterType.float1: var floatField = new FloatField(controlName) { value = parameter.Float1Value }; floatField.RegisterValueChangedCallback( changeEvent => { parameter.Float1Value = changeEvent.newValue; clampAction?.Invoke(parameter); floatField.SetValueWithoutNotify(parameter.Float1Value); } ); control = floatField; break; case ParameterType.float2: var vector2Field = new Vector2Field(controlName) { value = parameter.Float2Value }; vector2Field.RegisterValueChangedCallback( changeEvent => { parameter.Float2Value = changeEvent.newValue; clampAction?.Invoke(parameter); vector2Field.SetValueWithoutNotify(parameter.Float2Value); } ); control = vector2Field; break; case ParameterType.float3: var vector3Field = new Vector3Field(controlName) { value = parameter.Float3Value }; vector3Field.RegisterValueChangedCallback( changeEvent => { parameter.Float3Value = changeEvent.newValue; clampAction?.Invoke(parameter); vector3Field.SetValueWithoutNotify(parameter.Float3Value); } ); control = vector3Field; break; default: throw ExceptionHelper.Invalid(nameof(parameter.Type), parameter.Type, InvalidType.unexpected); } control.Query <FloatField>().ForEach(field => field.style.minWidth = 60f); Label label = control.Q <Label>(); if (label != null) { label.style.minWidth = 0f; label.style.paddingRight = 20f; } return(control); }
public static VisualElement CreateFieldBasedOnType(ConfiguratorValueType _valueType, object _initialValue, string _label, System.Action _changeEventCallback) { switch (_valueType) { case ConfiguratorValueType.BOOL: Toggle newToggle = new Toggle(_label) { value = _initialValue.StructConvertTo <bool>() }; newToggle.RegisterCallback <ChangeEvent <bool> >(_event => _changeEventCallback?.Invoke()); return(newToggle); case ConfiguratorValueType.INT: IntegerField newIntegerField = new IntegerField(_label) { value = _initialValue.StructConvertTo <int>() }; newIntegerField.RegisterCallback <ChangeEvent <int> >(_event => _changeEventCallback?.Invoke()); return(newIntegerField); case ConfiguratorValueType.FLOAT: FloatField newFloatField = new FloatField(_label) { value = _initialValue.StructConvertTo <float>() }; newFloatField.RegisterCallback <ChangeEvent <float> >(_event => _changeEventCallback?.Invoke()); return(newFloatField); case ConfiguratorValueType.STRING: string castValue = _initialValue.TryConvertTo <string>(); TextField newTextField = new TextField(_label) { value = castValue ?? string.Empty }; newTextField.RegisterCallback <ChangeEvent <string> >(_event => _changeEventCallback?.Invoke()); return(newTextField); case ConfiguratorValueType.VECTOR2: Vector2Field newVector2Field = new Vector2Field(_label) { value = _initialValue.StructConvertTo <Vector2>() }; newVector2Field.RegisterCallback <ChangeEvent <Vector2> >(_event => _changeEventCallback?.Invoke()); return(newVector2Field); case ConfiguratorValueType.VECTOR3: Vector3Field newVector3Field = new Vector3Field(_label) { value = _initialValue.StructConvertTo <Vector3>() }; newVector3Field.RegisterCallback <ChangeEvent <Vector3> >(_event => _changeEventCallback?.Invoke()); return(newVector3Field); case ConfiguratorValueType.VECTOR2INT: Vector2IntField newVector2IntField = new Vector2IntField(_label) { value = _initialValue.StructConvertTo <Vector2Int>() }; newVector2IntField.RegisterCallback <ChangeEvent <Vector2Int> >(_event => _changeEventCallback?.Invoke()); return(newVector2IntField); case ConfiguratorValueType.VECTOR3INT: Vector3IntField newVector3IntField = new Vector3IntField(_label) { value = _initialValue.StructConvertTo <Vector3Int>() }; newVector3IntField.RegisterCallback <ChangeEvent <Vector3Int> >(_event => _changeEventCallback?.Invoke()); return(newVector3IntField); default: return(null); } }