Skip to content

Commit 934f4b8

Browse files
committed
fix: '3D' scale toggle in the inspector does not keep on reload
close #346
1 parent fe4fcc5 commit 934f4b8

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

Packages/src/Editor/UIParticleEditor.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ namespace Coffee.UIExtensions
2828
[CanEditMultipleObjects]
2929
internal class UIParticleEditor : GraphicEditor
3030
{
31+
internal class State : ScriptableSingleton<State>
32+
{
33+
public bool is3DScaleMode;
34+
}
35+
3136
//################################
3237
// Constant or Static Members.
3338
//################################
@@ -46,7 +51,6 @@ internal class UIParticleEditor : GraphicEditor
4651
private static readonly GUIContent s_ContentPrimary = new GUIContent("Primary");
4752
private static readonly Regex s_RegexBuiltInGuid = new Regex(@"^0{16}.0{15}$", RegexOptions.Compiled);
4853
private static readonly List<Material> s_TempMaterials = new List<Material>();
49-
private static bool s_XYZMode;
5054

5155
private SerializedProperty _maskable;
5256
private SerializedProperty _scale3D;
@@ -60,6 +64,7 @@ internal class UIParticleEditor : GraphicEditor
6064
private SerializedProperty _customViewSize;
6165
private ReorderableList _ro;
6266
private bool _showMax;
67+
private bool _is3DScaleMode;
6368

6469
private static readonly HashSet<Shader> s_Shaders = new HashSet<Shader>();
6570
#if UNITY_2018 || UNITY_2019
@@ -163,6 +168,19 @@ protected override void OnEnable()
163168
uip.RefreshParticles(uip.particles);
164169
}
165170
}
171+
172+
// Initialize 3D scale mode.
173+
_is3DScaleMode = State.instance.is3DScaleMode;
174+
if (!_is3DScaleMode)
175+
{
176+
var x = _scale3D.FindPropertyRelative("x");
177+
var y = _scale3D.FindPropertyRelative("y");
178+
var z = _scale3D.FindPropertyRelative("z");
179+
_is3DScaleMode = !Mathf.Approximately(x.floatValue, y.floatValue) ||
180+
!Mathf.Approximately(y.floatValue, z.floatValue) ||
181+
y.hasMultipleDifferentValues ||
182+
z.hasMultipleDifferentValues;
183+
}
166184
}
167185

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

182200
// Scale
183201
EditorGUI.BeginDisabledGroup(!_meshSharing.hasMultipleDifferentValues && _meshSharing.intValue == 4);
184-
s_XYZMode = DrawFloatOrVector3Field(_scale3D, s_XYZMode);
202+
if (DrawFloatOrVector3Field(_scale3D, _is3DScaleMode) != _is3DScaleMode)
203+
{
204+
State.instance.is3DScaleMode = _is3DScaleMode = !_is3DScaleMode;
205+
}
206+
185207
EditorGUI.EndDisabledGroup();
186208

187209
// AnimatableProperties

0 commit comments

Comments
 (0)