diff --git a/Packages/UIParticle/Scripts/Editor/UIParticleEditor.cs b/Packages/UIParticle/Scripts/Editor/UIParticleEditor.cs index 7a38736..7a774cc 100644 --- a/Packages/UIParticle/Scripts/Editor/UIParticleEditor.cs +++ b/Packages/UIParticle/Scripts/Editor/UIParticleEditor.cs @@ -16,6 +16,8 @@ internal class UIParticleEditor : GraphicEditor private static readonly GUIContent s_ContentParticleMaterial = new GUIContent("Particle Material", "The material for rendering particles"); private static readonly GUIContent s_ContentTrailMaterial = new GUIContent("Trail Material", "The material for rendering particle trails"); private static readonly GUIContent s_ContentAdvancedOptions = new GUIContent("Advanced Options"); + private static readonly GUIContent s_Content3D = new GUIContent("3D"); + private static readonly GUIContent s_ContentScale = new GUIContent("Scale"); private static readonly List s_ParticleSystems = new List(); private SerializedProperty _spParticleSystem; @@ -97,6 +99,8 @@ public override void OnInspectorGUI() EditorGUILayout.Space(); EditorGUILayout.LabelField(s_ContentAdvancedOptions, EditorStyles.boldLabel); + _xyzMode = DrawFloatOrVector3Field(_spScale3D, _xyzMode); + EditorGUILayout.PropertyField(_spIgnoreCanvasScaler); // AnimatableProperties @@ -139,5 +143,38 @@ public override void OnInspectorGUI() serializedObject.ApplyModifiedProperties(); } + + private static bool DrawFloatOrVector3Field(SerializedProperty sp, bool showXyz) + { + var x = sp.FindPropertyRelative("x"); + var y = sp.FindPropertyRelative("y"); + var z = sp.FindPropertyRelative("z"); + + showXyz |= !Mathf.Approximately(x.floatValue, y.floatValue) || + !Mathf.Approximately(y.floatValue, z.floatValue) || + y.hasMultipleDifferentValues || + z.hasMultipleDifferentValues; + + EditorGUILayout.BeginHorizontal(); + if (showXyz) + { + EditorGUILayout.PropertyField(sp); + } + else + { + EditorGUI.BeginChangeCheck(); + EditorGUILayout.PropertyField(x, s_ContentScale); + if (EditorGUI.EndChangeCheck()) + z.floatValue = y.floatValue = x.floatValue; + } + + EditorGUI.BeginChangeCheck(); + showXyz = GUILayout.Toggle(showXyz, s_Content3D, EditorStyles.miniButton, GUILayout.Width(30)); + if (EditorGUI.EndChangeCheck() && !showXyz) + z.floatValue = y.floatValue = x.floatValue; + EditorGUILayout.EndHorizontal(); + + return showXyz; + } } } diff --git a/Packages/UIParticle/Scripts/UIParticle.cs b/Packages/UIParticle/Scripts/UIParticle.cs index b6167c4..c0b9980 100755 --- a/Packages/UIParticle/Scripts/UIParticle.cs +++ b/Packages/UIParticle/Scripts/UIParticle.cs @@ -31,6 +31,9 @@ public class UIParticle : MaskableGraphic [Tooltip("Animatable material properties. If you want to change the material properties of the ParticleSystem in Animation, enable it.")] [SerializeField] internal AnimatableProperty[] m_AnimatableProperties = new AnimatableProperty[0]; + [Tooltip("Particle effect scale")] [SerializeField] + internal Vector3 m_Scale3D = Vector3.one; + private readonly Material[] _maskMaterials = new Material[2]; private DrivenRectTransformTracker _tracker; private Mesh _bakedMesh; @@ -72,8 +75,17 @@ internal ParticleSystemRenderer cachedRenderer /// public float scale { - get { return m_Scale; } - set { m_Scale = value; } + get { return m_Scale3D.x; } + set { m_Scale3D.Set(value, value, value); } + } + + /// + /// Particle effect scale. + /// + public Vector3 scale3D + { + get { return m_Scale3D; } + set { m_Scale3D = value; } } internal bool isTrailParticle diff --git a/Packages/UIParticle/Scripts/UIParticleUpdater.cs b/Packages/UIParticle/Scripts/UIParticleUpdater.cs index 30b9cbe..e262bf9 100755 --- a/Packages/UIParticle/Scripts/UIParticleUpdater.cs +++ b/Packages/UIParticle/Scripts/UIParticleUpdater.cs @@ -51,6 +51,10 @@ private static void Refresh(UIParticle particle) { if (!particle) return; + Profiler.BeginSample("Modify scale"); + ModifyScale(particle); + Profiler.EndSample(); + if (!particle.isValid) return; Profiler.BeginSample("Update trail particle"); @@ -85,6 +89,30 @@ private static void Refresh(UIParticle particle) Profiler.EndSample(); } + private static void ModifyScale(UIParticle particle) + { + if (particle.isTrailParticle) return; + + var modifiedScale = particle.m_Scale3D; + + // Ignore Canvas scaling. + if (particle.ignoreCanvasScaler && particle.canvas) + { + var s = particle.canvas.rootCanvas.transform.localScale; + var sInv = new Vector3( + Mathf.Approximately(s.x, 0) ? 1 : 1 / s.x, + Mathf.Approximately(s.y, 0) ? 1 : 1 / s.y, + Mathf.Approximately(s.z, 0) ? 1 : 1 / s.z); + modifiedScale = Vector3.Scale(modifiedScale, sInv); + } + + // Scale is already modified. + var tr = particle.transform; + if (Mathf.Approximately((tr.localScale - modifiedScale).sqrMagnitude, 0)) return; + + tr.localScale = modifiedScale; + } + private static void UpdateMeshAndTexture(UIParticle particle) { // Update mesh.