public static void RenderVector2IntProperty(VisualElement container, string name, object value, Action <object> setter) { var field = new Vector2IntField(name); field.SetValueWithoutNotify((Vector2Int)value); field.MarkDirtyRepaint(); field.RegisterValueChangedCallback(evt => setter(evt.newValue)); container.Add(field); }
public ConstantPadNode(string titleLabel = "Constant Padding") { SetSize(new Vector2(224, 100 + style.marginTop)); inputContainer.style.width = 84; // hardcode 1x1 padding for now. TODO - make this have a UI pad = new Padding(1); title = titleLabel; var pixelType = typeof(T); m_ImageDataType = typeof(Image <T>); m_PortLabel = string.Format("Image<{0}>", pixelType.Name); input = VisionPort.Create <Edge, Image <T> >(Orientation.Horizontal, Direction.Input, Port.Capacity.Single); input.onUpdate += OnInputUpdate; input.portName = m_PortLabel; inputContainer.Add(input); output = VisionPort.Create <Edge, Image <T> >(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi); output.portName = m_PortLabel; outputContainer.style.width = 84; outputContainer.style.flexDirection = FlexDirection.Row; outputContainer.style.alignItems = Align.Center; outputContainer.Add(output); var sizeField = new Vector2IntField(); var sizeLabel = new Label("Pad Size"); sizeLabel.style.minWidth = 92; var sizeContainer = new VisualContainer(); sizeContainer.style.flexDirection = FlexDirection.Row; sizeContainer.style.flexWrap = Wrap.NoWrap; sizeField.style.flexDirection = FlexDirection.Row; sizeField.style.flexWrap = Wrap.NoWrap; sizeField.style.maxWidth = 128; sizeContainer.Add(sizeLabel); sizeContainer.Add(sizeField); extensionContainer.Add(sizeContainer); titleButtonContainer.style.visibility = Visibility.Hidden; RefreshExpandedState(); }
void Init() { Vector2IntField field = new Vector2IntField() { value = config.value != null ? (Vector2Int)config.value : new Vector2Int(), }; field.EnableInClassList("compositeField", false); field.style.flexDirection = FlexDirection.Row; field.style.flexWrap = Wrap.NoWrap; field.RegisterValueChangedCallback((e) => { config.OnValueChanged(e.newValue); MarkDirtyRepaint(); }); Add(field); }
void InitBuildMenu(VisualElement root) { gridSizeField = root.Query <Vector2IntField>("size-field").First(); gridTilePanel = root.Query <VisualElement>("tile-panel").First(); buildButton = root.Query <Button>("build-tiles-button").First(); loadButton = root.Query <Button>("load-tiles-button").First(); resizeButton = root.Query <Button>("resize-tile-button").First(); setDoorButton = root.Query <Button>("set-door-button").First(); buildButton.clickable.clicked += () => { currentRoom = CreateRoom(gridSizeField.value.x, gridSizeField.value.y); CreateGridButton(); }; loadButton.clickable.clicked += () => { var loadPath = EditorUtility.OpenFilePanel("Room 불러오기", Application.dataPath, ROOM_FILE_EXTENTION); currentRoom = LoadRoom(loadPath); CreateGridButton(); }; resizeButton.clickable.clicked += () => { var width = gridSizeField.value.x; var height = gridSizeField.value.y; if (width < MIN_WIDTH || height < MIN_HEGIHT) { return; } currentRoom?.SetSize(width, height); }; setDoorButton.clickable.clicked += () => { selectedPaletteEelment.Clear(); drawer.DrawAction = SwitchDoorInTile; }; }
internal override void Apply(VisualElement container) { /// <sample> // Get a reference to the field from UXML and assign it its value. var uxmlField = container.Q <Vector2IntField>("the-uxml-field"); uxmlField.value = new Vector2Int(23, 12); // Create a new field, disable it, and give it a style class. var csharpField = new Vector2IntField("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 <Vector2Int> >((evt) => { csharpField.value = evt.newValue; }); /// </sample> }
public PreConvolutionPadNode(string titleLabel = "Pre-Convolution Padding") { SetSize(new Vector2(224, 100 + style.marginTop)); inputContainer.style.width = 84; title = titleLabel; var pixelType = typeof(T); m_ImageDataType = typeof(Image <T>); m_PortLabel = string.Format("Image<{0}>", pixelType.Name); var input1 = VisionPort.Create <Edge>(Orientation.Horizontal, Direction.Input, Port.Capacity.Single, m_ImageDataType); input1.portName = m_PortLabel; inputContainer.Add(input1); output = VisionPort.Create <Edge>(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, m_ImageDataType); output.portName = m_PortLabel; outputContainer.style.width = 84; outputContainer.style.flexDirection = FlexDirection.Row; outputContainer.style.alignItems = Align.Center; outputContainer.Add(output); var modeField = new EnumField(ConvolutionPadMode.Same); var sizeField = new Vector2IntField(); var sizeLabel = new Label("Convolution Size"); sizeLabel.style.minWidth = 92; var modeContainer = new VisualContainer(); modeContainer.style.flexDirection = FlexDirection.Row; modeContainer.style.flexWrap = Wrap.NoWrap; /* * var sizeContainer = new VisualContainer(); * sizeContainer.style.flexDirection = FlexDirection.Row; * sizeContainer.style.flexWrap = Wrap.NoWrap; * sizeField.style.flexDirection = FlexDirection.Row; * sizeField.style.flexWrap = Wrap.NoWrap; * sizeField.style.maxWidth = 128; * sizeContainer.Add(sizeLabel); * sizeContainer.Add(sizeField); */ modeField.style.minWidth = 64; var padLabel = new Label("Pad Mode"); padLabel.style.minWidth = 96; modeContainer.Add(padLabel); modeContainer.Add(modeField); //extensionContainer.Add(sizeContainer); extensionContainer.Add(modeContainer); titleButtonContainer.style.visibility = Visibility.Hidden; RefreshExpandedState(); }
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); }
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 void OpenProjectSettings(MProject project) { var ModalContent = this.ShowModalWindow("PROJECT SETTINGS"); var NameField = new TextField("Project Name: "); NameField.value = project.ProjectName; ModalContent.Add(NameField); NameField.RegisterCallback <ChangeEvent <string> >((evt) => { project.ProjectName = evt.newValue; }); // Resolution Field. var resolutionField = new PopupField <string>("Resolution: ", ResNames, project.ResolutionIndex); //normalField.value = ResNames[0]; ModalContent.Add(resolutionField); // Create a new field and assign it its value. var framerateField = new PopupField <string>("FrameRate: ", FPSNames, project.FrameRateIndex); ModalContent.Add(framerateField); var customResField = new Vector2IntField("Custom:"); customResField.value = new Vector2Int(project.OutputWidth, project.OutputHeight); customResField.style.display = (project.ResolutionIndex == CustomResIndex) ? DisplayStyle.Flex : DisplayStyle.None; ModalContent.Add(customResField); // Mirror value of uxml field into the C# field. resolutionField.RegisterCallback <ChangeEvent <string> >((evt) => { project.ResolutionIndex = ResNames.IndexOf(evt.newValue); var size = this.ResSizes[project.ResolutionIndex]; project.OutputWidth = (int)size.x; project.OutputHeight = (int)size.y; customResField.style.display = (project.ResolutionIndex == CustomResIndex) ? DisplayStyle.Flex : DisplayStyle.None; project.is360 = _360Indices.Contains(project.ResolutionIndex); project.is360Stereo = (project.ResolutionIndex == _360StereoIndex); }); framerateField.RegisterCallback <ChangeEvent <string> >((evt) => { project.FrameRateIndex = FPSNames.IndexOf(evt.newValue); project.FrameRate = this.FPSValues[project.FrameRateIndex]; }); customResField.RegisterCallback <ChangeEvent <Vector2Int> >((evt) => { project.OutputWidth = evt.newValue.x; project.OutputHeight = evt.newValue.y; }); var toggleScreenShots = new Toggle("Capture ScreenShots:"); toggleScreenShots.value = project.TakeScreenShots; ModalContent.Add(toggleScreenShots); var ScreenShotsInterval = new FloatField("ScreenShots Interval (sec): "); ScreenShotsInterval.value = project.ScreenShotsInterval; ScreenShotsInterval.style.display = (project.TakeScreenShots) ? DisplayStyle.Flex : DisplayStyle.None; ModalContent.Add(ScreenShotsInterval); toggleScreenShots.RegisterCallback <ChangeEvent <bool> >((evt) => { project.TakeScreenShots = evt.newValue; ScreenShotsInterval.style.display = (project.TakeScreenShots) ? DisplayStyle.Flex : DisplayStyle.None; }); ScreenShotsInterval.RegisterCallback <ChangeEvent <float> >((evt) => { project.ScreenShotsInterval = evt.newValue; }); var DeleteButton = new Button(); DeleteButton.text = "DELETE PROJECT"; DeleteButton.clicked += () => { this.ShowConfirmDialog("Delete Project", "Are you sure?", (bool confirm) => { if (confirm) { this.m_MainWindow.DeleteProject(project); } else { this.OpenProjectSettings(project); } }); }; ModalContent.Add(DeleteButton); }
public override VisualElement CreateInspectorGUI() { m_Root = new VisualElement(); // root.Bind(serializedObject); // SerializedProperty property = serializedObject.GetIterator(); // if (property.NextVisible(true)) // Expand first child. // { // do // { // var field = new PropertyField(property); // field.name = "PropertyField:" + property.propertyPath; // if (property.propertyPath == "m_Script" && serializedObject.targetObject != null) // field.SetEnabled(false); // if (property.propertyPath != "CanvasOps") // m_Root.Add(field); // } // while (property.NextVisible(false)); // } var paletteProp = serializedObject.FindProperty("Palette"); var palette = new ObjectField("Palette"); palette.objectType = typeof(Palette); palette.BindProperty(paletteProp); if (paletteProp.objectReferenceValue == null) { paletteProp.objectReferenceValue = AssetDatabase.LoadAssetAtPath <Palette>(AssetDatabase.GUIDToAssetPath(AssetDatabase.FindAssets("t:Palette").First())); } m_Root.Add(palette); var size = new Vector2IntField("Size"); size.value = serializedObject.FindProperty("Size").vector2IntValue; m_Root.Add(size); var button = new Button(() => ResizeCanvas(size.value)); button.text = "Resize Canvas"; m_Root.Add(button); int frameCount = serializedObject.FindProperty("Frames").arraySize; var frameSlider = new SliderInt("Frame", 0, frameCount - 1); frameSlider.BindProperty(serializedObject.FindProperty("FrameIndex")); frameSlider.RegisterValueChangedCallback(ChangeFrame); m_Root.Add(frameSlider); var frameIndex = new IntegerField("Frame"); frameIndex.BindProperty(serializedObject.FindProperty("FrameIndex")); frameIndex.RegisterValueChangedCallback(ChangeFrame); frameIndex.SetEnabled(false); m_Root.Add(frameIndex); var importFrameButton = new Button(() => ImportFrame()); importFrameButton.text = "Import Image"; m_Root.Add(importFrameButton); m_Image = new Image(); m_Image.image = m_Texture; var desiredSize = 128f; if (m_Texture.width >= m_Texture.height) { m_Image.style.width = desiredSize; m_Image.style.height = desiredSize * (m_Texture.height / (float)m_Texture.width); } else { m_Image.style.height = desiredSize; m_Image.style.width = desiredSize * (m_Texture.width / (float)m_Texture.height); } // m_Image.RegisterCallback<MouseDownEvent>(RandomisePixels); var spacer = new VisualElement(); spacer.style.height = 10; m_Root.Add(spacer); m_Root.Add(m_Image); return(m_Root); }
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); } }