public EditorIntSliderField(string label, int value, int min, int max, EventCallback <ChangeEvent <int> > callback) { sliderInt = new SliderInt(label, min, max, SliderDirection.Horizontal); sliderInt.name = nameof(sliderInt); sliderInt.value = value; labelElement.StylePadding(0, 8, 0, 0); Add(sliderInt); integerField = new IntegerField(); integerField.name = nameof(integerField); integerField.StyleWidth(64); integerField.style.paddingLeft = 4; integerField.style.marginRight = 0; integerField.value = value; integerField.RegisterValueChangedCallback(callback); integerField.RegisterValueChangedCallback((callbackChangedSlider) => { sliderInt.value = callbackChangedSlider.newValue; }); sliderInt.Add(integerField); sliderInt.RegisterValueChangedCallback((callbackSlide) => { integerField.value = callbackSlide.newValue; }); }
VisualElement CreateTextureSettingsView() { var textureSettings = new VisualElement(); var t = target as Texture; textureSettings.Add(new Label("Texture Settings:")); var wrapMode = new EnumField("Wrap Mode", t.wrapMode); wrapMode.RegisterValueChangedCallback(e => { Undo.RegisterCompleteObjectUndo(t, "Changed wrap mode"); t.wrapMode = (TextureWrapMode)e.newValue; }); textureSettings.Add(wrapMode); var filterMode = new EnumField("Filter Mode", t.filterMode); filterMode.RegisterValueChangedCallback(e => { Undo.RegisterCompleteObjectUndo(t, "Changed filter mode"); t.filterMode = (FilterMode)e.newValue; }); textureSettings.Add(filterMode); var aniso = new SliderInt("Aniso Level", 1, 9); aniso.RegisterValueChangedCallback(e => { Undo.RegisterCompleteObjectUndo(t, "Changed aniso level"); t.anisoLevel = e.newValue; }); textureSettings.Add(aniso); return(textureSettings); }
public IntegerSlider() : base() { slider.RegisterValueChangedCallback(evt => { field.value = value = evt.newValue; }); slider.style.minWidth = 50; field.RegisterValueChangedCallback(evt => { slider.value = value = evt.newValue; }); field.style.minWidth = 80; }
void OnGeometryChange(GeometryChangedEvent evt) { musicToggle = this.Q <Toggle>("music-toggle"); bool muteMusic = PlayerPrefs.GetInt(PlayerPrefsMuteMusicKey, 0) == 0; musicToggle?.SetValueWithoutNotify(!muteMusic); SetMuteMusic(muteMusic); musicToggle?.RegisterValueChangedCallback(e => OnMusicToggle(e)); speedSlider = this.Q <SliderInt>("speed-slider"); speedValue = this.Q <Label>("speed-value-label"); int timeScale = (int)Mathf.Round(Time.timeScale); // Capping (only matters in the Editor where the time scale can be changed on the project properties // but we're being safe). if (timeScale > 3) { timeScale = 3; } else if (timeScale < 1) { timeScale = 1; } if (speedValue != null) { speedValue.text = timeScale.ToString(); speedSlider.value = timeScale; speedSlider.RegisterValueChangedCallback(e => OnSpeedSliderChanged(e.newValue)); } this.UnregisterCallback <GeometryChangedEvent>(OnGeometryChange); }
public PercentSlider(string label) : base(label) { AddToClassList(s_UssClassName); styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(s_UssPath)); var template = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(s_UxmlPath); template.CloneTree(this); visualInput = this.Q(s_VisualInputName); mSlider = this.Q <SliderInt>(s_SliderName); mField = this.Q <IntegerField>(s_FieldName); mSlider.RegisterValueChangedCallback(OnSubFieldValueChange); mField.RegisterValueChangedCallback(OnSubFieldValueChange); }
public void OnEnable() { VisualElement root = rootVisualElement; // Import UXML var visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Editor/Sample4.uxml"); var styleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/Editor/Sample4.uss"); VisualElement labelFromUXML = visualTree.CloneTree(); labelFromUXML.styleSheets.Add(styleSheet); root.Add(labelFromUXML); this.label = root.Q <Label>("label"); this.image = root.Q <Image>("image"); this.slider = root.Q <SliderInt>("slider"); slider.RegisterValueChangedCallback <int>(Slider_ValueChanged); }
public Slider(int val, int min, int max, EventCallback <int> cb) { Callback = cb; Value = val; contentContainer.AddToClassList("bounded-int"); contentContainer.AddToClassList("range"); Range = new SliderInt { highValue = max, lowValue = min, value = val }; Min = new IntegerField { value = min }; Current = new IntegerField { value = val }; Max = new IntegerField { value = max }; Min.AddToClassList("min-value"); Current.AddToClassList("current-value"); Max.AddToClassList("max-value"); var Fields = new VisualElement(); Fields.AddToClassList("input-fields"); Fields.Add(Min); Fields.Add(Current); Fields.Add(Max); contentContainer.Add(Range); contentContainer.Add(Fields); Range.RegisterValueChangedCallback(CurrentChanged); Min.RegisterValueChangedCallback(MinChanged); Current.RegisterValueChangedCallback(CurrentChanged); Max.RegisterValueChangedCallback(MaxChanged); }
VisualElement CreateTextureSettingsView() { var textureSettings = new VisualElement(); var t = target as Texture; var settingsLabel = new Label("Texture Settings"); settingsLabel.AddToClassList("Header"); textureSettings.Add(settingsLabel); var settings = new VisualElement(); settings.AddToClassList("Indent"); textureSettings.Add(settings); var wrapMode = new EnumField("Wrap Mode", t.wrapMode); wrapMode.RegisterValueChangedCallback(e => { Undo.RegisterCompleteObjectUndo(t, "Changed wrap mode"); t.wrapMode = (TextureWrapMode)e.newValue; graph.settings.wrapMode = (OutputWrapMode)t.wrapMode; }); settings.Add(wrapMode); var filterMode = new EnumField("Filter Mode", t.filterMode); filterMode.RegisterValueChangedCallback(e => { Undo.RegisterCompleteObjectUndo(t, "Changed filter mode"); t.filterMode = (FilterMode)e.newValue; graph.settings.filterMode = (OutputFilterMode)t.filterMode; }); settings.Add(filterMode); var aniso = new SliderInt("Aniso Level", 1, 9); aniso.RegisterValueChangedCallback(e => { Undo.RegisterCompleteObjectUndo(t, "Changed aniso level"); t.anisoLevel = e.newValue; }); settings.Add(aniso); return(textureSettings); }
public override void OnOpen() { editorWindow.rootVisualElement.AddStyleSheetPath("PAAnimationOptions"); editorWindow.rootVisualElement.name = "Window"; editorWindow.rootVisualElement.Add(new Label("Name")); var animationName = new TextField(); animationName.value = _animation.name; animationName.RegisterValueChangedCallback((e) => { _animation.name = e.newValue; _workspace.RefreshAnimationList(); }); editorWindow.rootVisualElement.Add(animationName); editorWindow.rootVisualElement.Add(new Label("Frame Rate")); var animationFPS = new SliderInt(1, 30); animationFPS.value = _animation.fps; animationFPS.RegisterValueChangedCallback((e) => _animation.fps = e.newValue); editorWindow.rootVisualElement.Add(animationFPS); }
void CreateTexturePreviewImGUI(VisualElement previewContainer, MixtureNode node, int currentSlice) { // Add slider for texture 3D if (node.previewTexture.dimension == TextureDimension.Tex3D) { var previewSliceIndex = new SliderInt(0, TextureUtils.GetSliceCount(node.previewTexture) - 1) { label = "Slice", value = currentSlice, }; previewSliceIndex.RegisterValueChangedCallback((ChangeEvent <int> a) => { currentSlice = a.newValue; }); previewContainer.Add(previewSliceIndex); } var previewImageSlice = new IMGUIContainer(() => { if (node.previewTexture == null) { return; } DrawPreviewCommonSettings(node.previewTexture); Rect previewRect = GetPreviewRect(node.previewTexture); DrawImGUIPreview(node, previewRect, currentSlice); DrawTextureInfoHover(previewRect, node.previewTexture); }); // Force the ImGUI preview to refresh EditorApplication.update -= previewImageSlice.MarkDirtyRepaint; EditorApplication.update += previewImageSlice.MarkDirtyRepaint; previewContainer.Add(previewImageSlice); }
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); }
private void Init(SimulatorJsonSerialization states) { InitPlayerSettings(states); bool overrideDefaultPlayerSettings = (states != null) ? states.overrideDefaultPlayerSettings : false; m_OverrideDefaultPlayerSettings = m_RootElement.Q <Toggle>("override-default-player-settings"); m_OverrideDefaultPlayerSettings.RegisterValueChangedCallback(SetOverridePlayerSettings); m_OverrideDefaultPlayerSettings.SetValueWithoutNotify(overrideDefaultPlayerSettings); UpdateOverridePlayerSettingsStatus(); m_CustomizedPlayerSettingsElement = m_RootElement.Q <VisualElement>("customized-player-settings"); m_StartInFullscreen = m_RootElement.Q <Toggle>("android-start-in-fullscreen"); m_StartInFullscreen.SetValueWithoutNotify(m_CustomizedPlayerSettings.androidStartInFullscreen); m_StartInFullscreen.RegisterValueChangedCallback((evt) => { m_CustomizedPlayerSettings.androidStartInFullscreen = evt.newValue; }); m_ResolutionScalingMode = m_RootElement.Q <EnumField>("resolution-scaling-mode"); m_ResolutionScalingMode.Init(ResolutionScalingMode.Disabled); m_ResolutionScalingMode.RegisterValueChangedCallback(SetResolutionScalingMode); m_ResolutionScalingMode.SetValueWithoutNotify(m_CustomizedPlayerSettings.resolutionScalingMode); #region DPI m_DpiContainer = m_RootElement.Q <VisualElement>("dpi-container"); m_DpiSlider = m_DpiContainer.Q <SliderInt>("dpi-slider"); m_DpiSlider.RegisterValueChangedCallback(SyncDpiField); m_DpiSlider.SetValueWithoutNotify(m_CustomizedPlayerSettings.targetDpi); m_DpiField = m_DpiContainer.Q <IntegerField>("dpi-field"); m_DpiField.RegisterValueChangedCallback(SyncDpiSlider); m_DpiField.RegisterCallback <KeyDownEvent>(OnDpiFieldKeyDown); m_DpiField.SetValueWithoutNotify(m_CustomizedPlayerSettings.targetDpi); #endregion #region Orientation m_DefaultOrientation = m_RootElement.Q <EnumField>("default-screen-orientation"); m_DefaultOrientation.Init(UIOrientation.AutoRotation); m_DefaultOrientation.RegisterValueChangedCallback(SetDefaultOrientation); m_DefaultOrientation.SetValueWithoutNotify(m_CustomizedPlayerSettings.defaultOrientation); m_AllowedOrienations = m_RootElement.Q <Foldout>("allowed-orientations"); m_AllowedPortrait = m_AllowedOrienations.Q <Toggle>("orientation-allow-portrait"); m_AllowedPortrait.SetValueWithoutNotify(m_CustomizedPlayerSettings.allowedPortrait); m_AllowedPortrait.RegisterValueChangedCallback((evt) => { m_CustomizedPlayerSettings.allowedPortrait = evt.newValue; }); m_AllowedPortraitUpsideDown = m_AllowedOrienations.Q <Toggle>("orientation-allow-portrait-upside-down"); m_AllowedPortraitUpsideDown.SetValueWithoutNotify(m_CustomizedPlayerSettings.allowedPortraitUpsideDown); m_AllowedPortraitUpsideDown.RegisterValueChangedCallback((evt) => { m_CustomizedPlayerSettings.allowedPortraitUpsideDown = evt.newValue; }); m_AllowedLandscapeLeft = m_AllowedOrienations.Q <Toggle>("orientation-allow-landscape-left"); m_AllowedLandscapeLeft.SetValueWithoutNotify(m_CustomizedPlayerSettings.allowedLandscapeLeft); m_AllowedLandscapeLeft.RegisterValueChangedCallback((evt) => { m_CustomizedPlayerSettings.allowedLandscapeLeft = evt.newValue; }); m_AllowedLandscapeRight = m_AllowedOrienations.Q <Toggle>("orientation-allow-landscape-right"); m_AllowedLandscapeRight.SetValueWithoutNotify(m_CustomizedPlayerSettings.allowedLandscapeRight); m_AllowedLandscapeRight.RegisterValueChangedCallback((evt) => { m_CustomizedPlayerSettings.allowedLandscapeRight = evt.newValue; }); #endregion #region Graphics API m_AutoGraphicsAPI = m_RootElement.Q <Toggle>("auto-graphics-api"); m_AutoGraphicsAPI.SetValueWithoutNotify(m_CustomizedPlayerSettings.autoGraphicsAPI); m_AutoGraphicsAPI.RegisterValueChangedCallback(SetAutoGraphicsAPI); m_GraphicsAPIPlaceholder = m_RootElement.Q <VisualElement>("graphics-api-placeholder"); m_GraphicsAPIPlaceholder.SetEnabled(!m_CustomizedPlayerSettings.autoGraphicsAPI); #endregion UpdateCustomizedPlayerSettings(m_OverrideDefaultPlayerSettings.value); UpdateStartInFullScreen(); UpdateResolutionScalingMode(m_CustomizedPlayerSettings.resolutionScalingMode); UpdateAllowedOrientations(m_CustomizedPlayerSettings.defaultOrientation); UpdateGraphicsAPI(); }
void ReloadSettingsView() { // Remove all old fields Clear(); if (title != null) { var titleLabel = new Label(title); titleLabel.AddToClassList("PropertyEditorTitle"); this.Add(titleLabel); } var dimension = settings.GetResolvedTextureDimension(graph); // Wrap and Filter Modes smpHeader = new Label("Sampler States"); smpHeader.AddToClassList(headerStyleClass); this.Add(smpHeader); wrapMode = showSettingsForNode ? new EnumField(settings.wrapMode) : new EnumField((GraphOutputWrapMode)settings.wrapMode); wrapMode.label = "Wrap Mode"; wrapMode.RegisterValueChangedCallback(e => { owner.RegisterCompleteObjectUndo("Updated Wrap Mode " + e.newValue); settings.wrapMode = (OutputWrapMode)e.newValue; onChanged?.Invoke(); }); filterMode = showSettingsForNode ? new EnumField(settings.filterMode) : new EnumField((GraphOutputFilterMode)settings.filterMode); filterMode.label = "Filter Mode"; filterMode.RegisterValueChangedCallback(e => { owner.RegisterCompleteObjectUndo("Updated Filter Mode " + e.newValue); settings.filterMode = (OutputFilterMode)e.newValue; onChanged?.Invoke(); }); this.Add(wrapMode); this.Add(filterMode); // Size Modes sizeHeader = new Label("Size Properties"); sizeHeader.AddToClassList(headerStyleClass); this.Add(sizeHeader); outputSizeMode = showSettingsForNode ? new EnumField(settings.sizeMode) : new EnumField((GraphOutputSizeMode)settings.sizeMode); outputSizeMode.label = "Size Mode"; outputSizeMode.RegisterValueChangedCallback((EventCallback <ChangeEvent <Enum> >)(e => { owner.RegisterCompleteObjectUndo("Updated Size mode " + e.newValue); settings.sizeMode = (OutputSizeMode)e.newValue; onChanged?.Invoke(); ReloadSettingsView(); UpdateFieldVisibility(settings); })); this.Add(outputSizeMode); potSize = new EnumField(settings.potSize) { value = settings.potSize, label = "Resolution", }; potSize.RegisterValueChangedCallback(e => { owner.RegisterCompleteObjectUndo("Updated Size " + e.newValue); var size = (POTSize)e.newValue; settings.potSize = size; if (size != POTSize.Custom) { settings.width = (int)size; settings.height = (int)size; settings.depth = (int)size; } else { settings.width = outputWidth.value; settings.height = outputHeight.value; if (outputDepth != null) { settings.depth = outputDepth.value; } } onChanged?.Invoke(); ReloadSettingsView(); UpdateFieldVisibility(settings); }); this.Add(potSize); outputWidth = new IntegerField() { value = settings.width, label = "Width", isDelayed = true, }; outputWidth.RegisterValueChangedCallback(e => { owner.RegisterCompleteObjectUndo("Updated Width " + e.newValue); settings.width = e.newValue; onChanged?.Invoke(); }); this.Add(outputWidth); outputWidthScale = CreateSizeScaleSlider(settings.widthScale, (v) => settings.widthScale = v, "Width Scale"); this.Add(outputWidthScale); if (dimension != TextureDimension.Cube) { outputHeight = new IntegerField() { value = settings.height, label = "Height", isDelayed = true, }; outputHeight.RegisterValueChangedCallback(e => { owner.RegisterCompleteObjectUndo("Updated Height " + e.newValue); settings.height = e.newValue; onChanged?.Invoke(); }); this.Add(outputHeight); outputHeightScale = CreateSizeScaleSlider(settings.heightScale, v => settings.heightScale = v, "Height Scale"); this.Add(outputHeightScale); if (dimension == TextureDimension.Tex3D) { outputDepth = new IntegerField() { value = settings.depth, label = "Depth", isDelayed = true, }; outputDepth.RegisterValueChangedCallback(e => { owner.RegisterCompleteObjectUndo("Updated Depth " + e.newValue); settings.depth = e.newValue; onChanged?.Invoke(); }); this.Add(outputDepth); outputDepthScale = CreateSizeScaleSlider(settings.depthScale, v => settings.depthScale = v, "Depth Scale"); this.Add(outputDepthScale); } } SliderInt CreateSizeScaleSlider(float defaultValue, Action <float> setter, string propertyName) { var slider = new SliderInt(0, (int)(Mathf.Log(k_MaxSizeScale, 2) * 2)) { value = SizeScaleToInt(settings.heightScale), label = propertyName, }; slider.RegisterValueChangedCallback(e => { owner.RegisterCompleteObjectUndo(propertyName + " " + e.newValue); setter(IntToSizeScale(e.newValue)); onChanged?.Invoke(); }); return(slider); } // Dimension and Pixel Format formatHeader = new Label("Format"); formatHeader.AddToClassList(headerStyleClass); this.Add(formatHeader); outputDimension = showSettingsForNode ? new EnumField(settings.dimension) : new EnumField((GraphOutputDimension)settings.dimension); outputDimension.label = "Dimension"; outputDimension.RegisterValueChangedCallback(e => { owner.RegisterCompleteObjectUndo("Updated Texture Dimension " + e.newValue); // Check if the new texture is not too high res: settings.dimension = (OutputDimension)e.newValue; if (settings.dimension == OutputDimension.Texture3D) { long pixelCount = settings.GetResolvedWidth(graph) * settings.GetResolvedHeight(graph) * settings.GetResolvedDepth(graph); // Above 16M pixels in a texture3D, processing can take too long and crash the GPU when a conversion happen if (pixelCount > 16777216) { settings.sizeMode = OutputSizeMode.Absolute; settings.SetPOTSize(64); } } onChanged?.Invoke(); ReloadSettingsView(); }); outputChannels = showSettingsForNode ? new EnumField(settings.outputChannels) : new EnumField((GraphOutputChannel)settings.outputChannels); outputChannels.label = "Output Channels"; outputChannels.RegisterValueChangedCallback(e => { owner.RegisterCompleteObjectUndo("Updated Output Channels " + e.newValue); settings.outputChannels = (OutputChannel)e.newValue; onChanged?.Invoke(); }); outputPrecision = showSettingsForNode ? new EnumField(settings.outputPrecision) : new EnumField((GraphOutputPrecision)settings.outputPrecision); outputPrecision.label = "Output Precision"; outputPrecision.RegisterValueChangedCallback(e => { owner.RegisterCompleteObjectUndo("Updated Output Precision " + e.newValue); settings.outputPrecision = (OutputPrecision)e.newValue; // outputPrecision.Init(); onChanged?.Invoke(); }); this.Add(outputDimension); this.Add(outputChannels); this.Add(outputPrecision); UpdateFieldVisibility(settings); if (showSettingsForNode) { // Realtime fields and refresh mode otherHeader = new Label("Other"); otherHeader.AddToClassList(headerStyleClass); this.Add(otherHeader); doubleBuffered = new Toggle("Double Buffered") { value = settings.doubleBuffered, }; doubleBuffered.RegisterValueChangedCallback(e => { owner.RegisterCompleteObjectUndo("Set Double Buffered " + e.newValue); settings.doubleBuffered = e.newValue; onChanged?.Invoke(); }); Add(doubleBuffered); } else if (graph.type == MixtureGraphType.Realtime) { otherHeader = new Label("Realtime"); otherHeader.AddToClassList(headerStyleClass); this.Add(otherHeader); AddRealtimeFields(owner); } }