Skip to content

Commit

Permalink
fix: '3D' scale toggle in the inspector does not keep on reload
Browse files Browse the repository at this point in the history
close #346
  • Loading branch information
mob-sakai committed Dec 22, 2024
1 parent fe4fcc5 commit 934f4b8
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions Packages/src/Editor/UIParticleEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ namespace Coffee.UIExtensions
[CanEditMultipleObjects]
internal class UIParticleEditor : GraphicEditor
{
internal class State : ScriptableSingleton<State>
{
public bool is3DScaleMode;
}

//################################
// Constant or Static Members.
//################################
Expand All @@ -46,7 +51,6 @@ internal class UIParticleEditor : GraphicEditor
private static readonly GUIContent s_ContentPrimary = new GUIContent("Primary");
private static readonly Regex s_RegexBuiltInGuid = new Regex(@"^0{16}.0{15}$", RegexOptions.Compiled);
private static readonly List<Material> s_TempMaterials = new List<Material>();
private static bool s_XYZMode;

private SerializedProperty _maskable;
private SerializedProperty _scale3D;
Expand All @@ -60,6 +64,7 @@ internal class UIParticleEditor : GraphicEditor
private SerializedProperty _customViewSize;
private ReorderableList _ro;
private bool _showMax;
private bool _is3DScaleMode;

private static readonly HashSet<Shader> s_Shaders = new HashSet<Shader>();
#if UNITY_2018 || UNITY_2019
Expand Down Expand Up @@ -163,6 +168,19 @@ protected override void OnEnable()
uip.RefreshParticles(uip.particles);
}
}

// Initialize 3D scale mode.
_is3DScaleMode = State.instance.is3DScaleMode;
if (!_is3DScaleMode)
{
var x = _scale3D.FindPropertyRelative("x");
var y = _scale3D.FindPropertyRelative("y");
var z = _scale3D.FindPropertyRelative("z");
_is3DScaleMode = !Mathf.Approximately(x.floatValue, y.floatValue) ||
!Mathf.Approximately(y.floatValue, z.floatValue) ||
y.hasMultipleDifferentValues ||
z.hasMultipleDifferentValues;
}
}

/// <summary>
Expand All @@ -181,7 +199,11 @@ public override void OnInspectorGUI()

// Scale
EditorGUI.BeginDisabledGroup(!_meshSharing.hasMultipleDifferentValues && _meshSharing.intValue == 4);
s_XYZMode = DrawFloatOrVector3Field(_scale3D, s_XYZMode);
if (DrawFloatOrVector3Field(_scale3D, _is3DScaleMode) != _is3DScaleMode)
{
State.instance.is3DScaleMode = _is3DScaleMode = !_is3DScaleMode;
}

EditorGUI.EndDisabledGroup();

// AnimatableProperties
Expand Down

0 comments on commit 934f4b8

Please sign in to comment.