diff --git a/Packages/com.unity.render-pipelines.core/Editor/MaterialUpgrader.cs b/Packages/com.unity.render-pipelines.core/Editor/MaterialUpgrader.cs index ec52b772..518a9a46 100644 --- a/Packages/com.unity.render-pipelines.core/Editor/MaterialUpgrader.cs +++ b/Packages/com.unity.render-pipelines.core/Editor/MaterialUpgrader.cs @@ -74,6 +74,7 @@ namespace UnityEditor.Rendering public float setVal, unsetVal; } List m_KeywordFloatRename = new List(); + Dictionary)> m_ConditionalFloatRename; /// /// Type of property to rename. @@ -222,6 +223,20 @@ namespace UnityEditor.Rendering dstMaterial.SetFloat(t.property, srcMaterial.IsKeywordEnabled(t.keyword) ? t.setVal : t.unsetVal); } + + // Handle conditional float renaming + if (m_ConditionalFloatRename != null) + { + foreach (var (oldName, (newName, condition)) in m_ConditionalFloatRename) + { + if (srcMaterial.HasProperty(oldName) && + condition(srcMaterial.GetFloat(oldName)) && + dstMaterial.HasProperty(newName)) + { + dstMaterial.SetFloat(newName, 1.0f); + } + } + } } /// @@ -318,6 +333,17 @@ namespace UnityEditor.Rendering m_KeywordFloatRename.Add(new KeywordFloatRename { keyword = oldName, property = newName, setVal = setVal, unsetVal = unsetVal }); } + /// + /// Rename a float property conditionally based on its value + /// + /// Old property name + /// New property name + /// Condition function that takes the float value and returns true if renaming should occur + protected void RenameFloat(string oldName, string newName, System.Func condition) + { + (m_ConditionalFloatRename ??= new Dictionary)>())[oldName] = (newName, condition); + } + static MaterialUpgrader GetUpgrader(List upgraders, Material material) { if (material == null || material.shader == null) diff --git a/Packages/com.unity.render-pipelines.core/Runtime/Debugging/DebugUI.Fields.cs b/Packages/com.unity.render-pipelines.core/Runtime/Debugging/DebugUI.Fields.cs index 9d5e3346..2f732228 100644 --- a/Packages/com.unity.render-pipelines.core/Runtime/Debugging/DebugUI.Fields.cs +++ b/Packages/com.unity.render-pipelines.core/Runtime/Debugging/DebugUI.Fields.cs @@ -85,7 +85,9 @@ namespace UnityEngine.Rendering /// Input value. public virtual void SetValue(T value) { - Assert.IsNotNull(setter); + if (setter == null) + return; + var v = ValidateValue(value); if (v == null || !v.Equals(getter())) diff --git a/Packages/com.unity.render-pipelines.core/package.json b/Packages/com.unity.render-pipelines.core/package.json index d32e4d31..8385b992 100644 --- a/Packages/com.unity.render-pipelines.core/package.json +++ b/Packages/com.unity.render-pipelines.core/package.json @@ -14,5 +14,5 @@ "com.unity.modules.jsonserialize": "1.0.0", "com.unity.rendering.light-transport": "1.0.1" }, - "_fingerprint": "317e801bb3aaa64596e4ec903cb788a0dfb07788" + "_fingerprint": "67f868dbad82414b67a47161bdeffad5498e1cc0" } diff --git a/Packages/com.unity.shadergraph/Editor/Data/Nodes/UV/ParallaxOcclusionMappingNode.cs b/Packages/com.unity.shadergraph/Editor/Data/Nodes/UV/ParallaxOcclusionMappingNode.cs index 4c5385e6..d9a49c56 100644 --- a/Packages/com.unity.shadergraph/Editor/Data/Nodes/UV/ParallaxOcclusionMappingNode.cs +++ b/Packages/com.unity.shadergraph/Editor/Data/Nodes/UV/ParallaxOcclusionMappingNode.cs @@ -10,7 +10,7 @@ namespace UnityEditor.ShaderGraph [Title("UV", "Parallax Occlusion Mapping")] [FormerName("UnityEditor.Experimental.Rendering.HDPipeline.ParallaxOcclusionMappingNode")] [FormerName("UnityEditor.Rendering.HighDefinition.ParallaxOcclusionMappingNode")] - class ParallaxOcclusionMappingNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction, IMayRequireViewDirection, IMayRequireMeshUV + class ParallaxOcclusionMappingNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction, IMayRequireViewDirection, IMayRequireMeshUV, IMayRequireTransform { public ParallaxOcclusionMappingNode() { @@ -220,6 +220,8 @@ $precision {GetVariableNameForSlot(kPixelDepthOffsetOutputSlotId)} = ({tmpMaxHei "); } + public NeededTransform[] RequiresTransform(ShaderStageCapability stageCapability = ShaderStageCapability.All) => new[] { NeededTransform.WorldToObject }; + public NeededCoordinateSpace RequiresViewDirection(ShaderStageCapability stageCapability = ShaderStageCapability.All) { return NeededCoordinateSpace.Tangent; diff --git a/Packages/com.unity.shadergraph/package.json b/Packages/com.unity.shadergraph/package.json index 34db61b3..b06da7dc 100644 --- a/Packages/com.unity.shadergraph/package.json +++ b/Packages/com.unity.shadergraph/package.json @@ -48,5 +48,5 @@ "path": "Samples~/CustomMaterialPropertyDrawers" } ], - "_fingerprint": "5516e0d9751810ec70d19bca7a5251cbecd2b5ca" + "_fingerprint": "41211273cdd1ec56cc330555ecc5be38b9ea2055" } diff --git a/Packages/com.unity.ugui/Editor/TMP/TMP_BaseEditorPanel.cs b/Packages/com.unity.ugui/Editor/TMP/TMP_BaseEditorPanel.cs index 5881c773..257ee2e7 100644 --- a/Packages/com.unity.ugui/Editor/TMP/TMP_BaseEditorPanel.cs +++ b/Packages/com.unity.ugui/Editor/TMP/TMP_BaseEditorPanel.cs @@ -73,6 +73,7 @@ namespace TMPro.EditorUtilities static readonly GUIContent k_TopLabel = new GUIContent("Top"); static readonly GUIContent k_RightLabel = new GUIContent("Right"); static readonly GUIContent k_BottomLabel = new GUIContent("Bottom"); + static readonly GUIContent[] k_MarginLabels = { k_LeftLabel, k_TopLabel, k_RightLabel, k_BottomLabel }; protected static readonly GUIContent k_ExtraSettingsLabel = new GUIContent("Extra Settings"); protected static string[] k_UiStateLabel = new string[] { "(Click to collapse) ", "(Click to expand) " }; @@ -80,6 +81,8 @@ namespace TMPro.EditorUtilities static Dictionary k_AvailableStyles = new Dictionary(); protected Dictionary m_TextStyleIndexLookup = new Dictionary(); + const float kPaddingBetweenMarginFields = 5f; + protected struct Foldout { // Track Inspector foldout panel states, globally. @@ -1126,25 +1129,7 @@ namespace TMPro.EditorUtilities protected void DrawMargins() { - EditorGUI.BeginChangeCheck(); DrawMarginProperty(m_MarginProp, k_MarginsLabel); - if (EditorGUI.EndChangeCheck()) - { - // Value range check on margins to make sure they are not excessive. - Vector4 margins = m_MarginProp.vector4Value; - Rect textContainerSize = m_RectTransform.rect; - - margins.x = Mathf.Clamp(margins.x, -textContainerSize.width, textContainerSize.width); - margins.z = Mathf.Clamp(margins.z, -textContainerSize.width, textContainerSize.width); - - margins.y = Mathf.Clamp(margins.y, -textContainerSize.height, textContainerSize.height); - margins.w = Mathf.Clamp(margins.w, -textContainerSize.height, textContainerSize.height); - - m_MarginProp.vector4Value = margins; - - m_HavePropertiesChanged = true; - } - EditorGUILayout.Space(); } @@ -1410,49 +1395,70 @@ namespace TMPro.EditorUtilities // DRAW MARGIN PROPERTY protected void DrawMarginProperty(SerializedProperty property, GUIContent label) { - Rect rect = EditorGUILayout.GetControlRect(false, 2 * 18); - - EditorGUI.BeginProperty(rect, label, property); + Rect rect = EditorGUILayout.GetControlRect(false, 2 * EditorGUIUtility.singleLineHeight); + rect.y += 2; - Rect pos0 = new Rect(rect.x, rect.y + 2, rect.width - 15, 18); - - float width = rect.width + 3; + Rect pos0 = rect; pos0.width = EditorGUIUtility.labelWidth; - EditorGUI.PrefixLabel(pos0, label); - - Vector4 margins = property.vector4Value; - - float widthB = width - EditorGUIUtility.labelWidth; - float fieldWidth = widthB / 4; - pos0.width = Mathf.Max(fieldWidth - 5, 45f); - // Labels - pos0.x = EditorGUIUtility.labelWidth + 15; - margins.x = DrawMarginField(pos0, "Left", margins.x); + // BeginProperty ensures that the property works correctly with prefabs + EditorGUI.BeginProperty(pos0, label, property); - pos0.x += fieldWidth; - margins.y = DrawMarginField(pos0, "Top", margins.y); + int controlId = GUIUtility.GetControlID(FocusType.Keyboard, pos0); + pos0 = EditorGUI.PrefixLabel(pos0, controlId, label); - pos0.x += fieldWidth; - margins.z = DrawMarginField(pos0, "Right", margins.z); + float width = rect.xMax + kPaddingBetweenMarginFields - pos0.xMin; + float fieldWidth = width / 4f; + pos0.width = Mathf.Max(fieldWidth - kPaddingBetweenMarginFields, 45f); - pos0.x += fieldWidth; - margins.w = DrawMarginField(pos0, "Bottom", margins.w); - - property.vector4Value = margins; + // Draw each margin component by iterating the serialized sub-properties + var subProperty = property.Copy(); + for (int i = 0; i < 4; i++) + { + // The first Next() needs to enter the children + subProperty.Next(i == 0); + // The X (i==0) and Z (i==2) components are horizontal + var axis = i % 2 == 0 ? RectTransform.Axis.Horizontal : RectTransform.Axis.Vertical; + DrawMarginField(pos0, k_MarginLabels[i], subProperty, axis); + pos0.x += fieldWidth; + } EditorGUI.EndProperty(); } - float DrawMarginField(Rect position, string label, float value) + bool DrawMarginField(Rect position, GUIContent label, SerializedProperty prop, RectTransform.Axis axis) { + // BeginProperty ensures that each margin field works correctly with prefabs + EditorGUI.BeginProperty(position, label, prop); + int controlId = GUIUtility.GetControlID(FocusType.Keyboard, position); - EditorGUI.PrefixLabel(position, controlId, new GUIContent(label)); + position.yMax -= EditorGUIUtility.singleLineHeight; + EditorGUI.PrefixLabel(position, controlId, label); - Rect dragZone = new Rect(position.x, position.y, position.width, position.height); + Rect dragZone = position; position.y += EditorGUIUtility.singleLineHeight; - return EditorGUI.DoFloatField(EditorGUI.s_RecycledEditor, position, dragZone, controlId, value, EditorGUI.kFloatFieldFormatString, EditorStyles.numberField, true); + EditorGUI.BeginChangeCheck(); + // Do not update the property value directly. Cache the new + // value and update the property if there was a change. + var newValue = EditorGUI.DoFloatField(EditorGUI.s_RecycledEditor, position, dragZone, controlId, prop.floatValue, EditorGUI.kFloatFieldFormatString, EditorStyles.numberField, true); + bool hasChanged = EditorGUI.EndChangeCheck(); + if (hasChanged) + { + // Loop through all selected objects and calculate their minimum width/height. + float size = float.MaxValue; + foreach (TMP_Text target in serializedObject.targetObjects) + { + var rect = target.rectTransform.rect; + size = Mathf.Min(size, axis == RectTransform.Axis.Horizontal ? rect.width : rect.height); + } + // Clamp the new value to be within the size. + prop.floatValue = Mathf.Clamp(newValue, -size, size); + m_HavePropertiesChanged = true; + } + EditorGUI.EndProperty(); + + return hasChanged; } protected void DrawPropertySlider(GUIContent label, SerializedProperty property) @@ -1467,6 +1473,5 @@ namespace TMPro.EditorUtilities // Special Handling of Undo / Redo Events. protected abstract void OnUndoRedo(); - } } diff --git a/Packages/com.unity.ugui/Runtime/UGUI/UI/Core/Slider.cs b/Packages/com.unity.ugui/Runtime/UGUI/UI/Core/Slider.cs index 27c44ec1..abe5392f 100644 --- a/Packages/com.unity.ugui/Runtime/UGUI/UI/Core/Slider.cs +++ b/Packages/com.unity.ugui/Runtime/UGUI/UI/Core/Slider.cs @@ -2,6 +2,10 @@ using System; using UnityEngine.Events; using UnityEngine.EventSystems; +#if UNITY_EDITOR +using UnityEditor; +#endif + namespace UnityEngine.UI { [AddComponentMenu("UI/Slider", 34)] @@ -428,10 +432,17 @@ namespace UnityEngine.UI Set(m_Value, false); // Update rects since they need to be initialized correctly. UpdateVisuals(); +#if UNITY_EDITOR + Undo.undoRedoEvent -= OnUndoRedoEvent; + Undo.undoRedoEvent += OnUndoRedoEvent; +#endif } protected override void OnDisable() { +#if UNITY_EDITOR + Undo.undoRedoEvent -= OnUndoRedoEvent; +#endif m_Tracker.Clear(); base.OnDisable(); } @@ -553,6 +564,13 @@ namespace UnityEngine.UI UpdateVisuals(); } +#if UNITY_EDITOR + void OnUndoRedoEvent(in UndoRedoInfo undo) + { + UpdateVisuals(); + } +#endif + enum Axis { Horizontal = 0, diff --git a/Packages/com.unity.ugui/package.json b/Packages/com.unity.ugui/package.json index 7610648a..044c13ba 100644 --- a/Packages/com.unity.ugui/package.json +++ b/Packages/com.unity.ugui/package.json @@ -19,5 +19,5 @@ "com.unity.modules.ui": "1.0.0", "com.unity.modules.imgui": "1.0.0" }, - "_fingerprint": "e375ff18e90f823f9c3d4ffbc1532d6cde85ed48" + "_fingerprint": "f250afc9b68ddb0d3ebf8e3274ec22b51a03153c" } diff --git a/Packages/com.unity.visualeffectgraph/Editor/Controls/VFXEnumValuePopup.cs b/Packages/com.unity.visualeffectgraph/Editor/Controls/VFXEnumValuePopup.cs index 153835ba..6363f3a6 100644 --- a/Packages/com.unity.visualeffectgraph/Editor/Controls/VFXEnumValuePopup.cs +++ b/Packages/com.unity.visualeffectgraph/Editor/Controls/VFXEnumValuePopup.cs @@ -7,7 +7,7 @@ namespace UnityEditor.VFX.UI { class VFXEnumValuePopup : VisualElement, INotifyValueChanged { - DropdownField m_DropDownButton; + readonly DropdownField m_DropDownButton; long m_Value; public IEnumerable choices => m_DropDownButton.choices; @@ -32,26 +32,20 @@ namespace UnityEditor.VFX.UI set => SetValueAndNotify(value); } - public void SetValueAndNotify(long newValue) + private void SetValueAndNotify(long newValue) { if (!EqualityComparer.Default.Equals(value, newValue)) { - using (ChangeEvent evt = ChangeEvent.GetPooled(value, newValue)) - { - evt.target = this; - SetValueWithoutNotify(newValue); - SendEvent(evt); - } + using var evt = ChangeEvent.GetPooled(value, newValue); + evt.target = this; + SetValueWithoutNotify(newValue); + m_DropDownButton.value = m_DropDownButton.choices[(int)m_Value]; + SendEvent(evt); } } public void SetValueWithoutNotify(long newValue) { - if (newValue >= 0 && newValue < m_DropDownButton.choices.Count) - { - m_Value = newValue; - } - m_Value = Math.Clamp(newValue, 0, m_DropDownButton.choices.Count - 1); } } diff --git a/Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/PropertyRM.cs b/Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/PropertyRM.cs index 5564ff69..3ed93216 100644 --- a/Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/PropertyRM.cs +++ b/Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/PropertyRM.cs @@ -624,7 +624,7 @@ namespace UnityEditor.VFX.UI if (m_Field is IVFXNotifyValueChanged vfxNotifyValueChanged) vfxNotifyValueChanged.SetValueWithoutNotify(value, force); else - m_Field.SetValueWithoutNotify(value); + m_Field.value = value; } catch (System.Exception ex) { diff --git a/Packages/com.unity.visualeffectgraph/package.json b/Packages/com.unity.visualeffectgraph/package.json index e896326a..fa6496e9 100644 --- a/Packages/com.unity.visualeffectgraph/package.json +++ b/Packages/com.unity.visualeffectgraph/package.json @@ -36,5 +36,5 @@ ] } ], - "_fingerprint": "6d3d05586bc2aab621743074b2ce44852b579423" + "_fingerprint": "7835942a56c9513d672c10fa1c3a99a2c633fc98" }