feat: added 'autoScalingMode (None, Transform.localScale, UIParticle.scale)' instead of 'autoScaling'
fixed issue when upgrading from 3.x to 4.xpull/289/head
parent
447996ce0f
commit
107f901fe3
|
@ -70,7 +70,7 @@ namespace Coffee.UIExtensions
|
||||||
private SerializedProperty _groupId;
|
private SerializedProperty _groupId;
|
||||||
private SerializedProperty _groupMaxId;
|
private SerializedProperty _groupMaxId;
|
||||||
private SerializedProperty _positionMode;
|
private SerializedProperty _positionMode;
|
||||||
private SerializedProperty _autoScaling;
|
private SerializedProperty _autoScalingMode;
|
||||||
private ReorderableList _ro;
|
private ReorderableList _ro;
|
||||||
private bool _showMax;
|
private bool _showMax;
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ namespace Coffee.UIExtensions
|
||||||
_groupId = serializedObject.FindProperty("m_GroupId");
|
_groupId = serializedObject.FindProperty("m_GroupId");
|
||||||
_groupMaxId = serializedObject.FindProperty("m_GroupMaxId");
|
_groupMaxId = serializedObject.FindProperty("m_GroupMaxId");
|
||||||
_positionMode = serializedObject.FindProperty("m_PositionMode");
|
_positionMode = serializedObject.FindProperty("m_PositionMode");
|
||||||
_autoScaling = serializedObject.FindProperty("m_AutoScaling");
|
_autoScalingMode = serializedObject.FindProperty("m_AutoScalingMode");
|
||||||
|
|
||||||
var sp = serializedObject.FindProperty("m_Particles");
|
var sp = serializedObject.FindProperty("m_Particles");
|
||||||
_ro = new ReorderableList(sp.serializedObject, sp, true, true, true, true)
|
_ro = new ReorderableList(sp.serializedObject, sp, true, true, true, true)
|
||||||
|
@ -271,7 +271,7 @@ namespace Coffee.UIExtensions
|
||||||
EditorGUILayout.PropertyField(_positionMode);
|
EditorGUILayout.PropertyField(_positionMode);
|
||||||
|
|
||||||
// Auto Scaling
|
// Auto Scaling
|
||||||
DrawAutoScaling(_autoScaling, targets.OfType<UIParticle>());
|
DrawAutoScaling(_autoScalingMode, targets.OfType<UIParticle>());
|
||||||
|
|
||||||
// Target ParticleSystems.
|
// Target ParticleSystems.
|
||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
|
@ -478,16 +478,17 @@ namespace Coffee.UIExtensions
|
||||||
|
|
||||||
private static void DrawAutoScaling(SerializedProperty prop, IEnumerable<UIParticle> uiParticles)
|
private static void DrawAutoScaling(SerializedProperty prop, IEnumerable<UIParticle> uiParticles)
|
||||||
{
|
{
|
||||||
|
var isTransformMode = prop.intValue == (int)UIParticle.AutoScalingMode.Transform;
|
||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
EditorGUILayout.PropertyField(prop);
|
EditorGUILayout.PropertyField(prop);
|
||||||
if (!EditorGUI.EndChangeCheck()) return;
|
if (!EditorGUI.EndChangeCheck() || !isTransformMode) return;
|
||||||
|
|
||||||
// on changed true->false, reset scale.
|
// on changed true->false, reset scale.
|
||||||
EditorApplication.delayCall += () =>
|
EditorApplication.delayCall += () =>
|
||||||
{
|
{
|
||||||
foreach (var uip in uiParticles)
|
foreach (var uip in uiParticles)
|
||||||
{
|
{
|
||||||
if (!uip || uip.autoScaling) continue;
|
if (!uip) continue;
|
||||||
uip.transform.localScale = Vector3.one;
|
uip.transform.localScale = Vector3.one;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -509,7 +510,7 @@ namespace Coffee.UIExtensions
|
||||||
EditorGUILayout.PropertyField(s_SerializedObject.FindProperty("m_Enabled"));
|
EditorGUILayout.PropertyField(s_SerializedObject.FindProperty("m_Enabled"));
|
||||||
s_XYZMode = DrawFloatOrVector3Field(s_SerializedObject.FindProperty("m_Scale3D"), s_XYZMode);
|
s_XYZMode = DrawFloatOrVector3Field(s_SerializedObject.FindProperty("m_Scale3D"), s_XYZMode);
|
||||||
EditorGUILayout.PropertyField(s_SerializedObject.FindProperty("m_PositionMode"));
|
EditorGUILayout.PropertyField(s_SerializedObject.FindProperty("m_PositionMode"));
|
||||||
DrawAutoScaling(s_SerializedObject.FindProperty("m_AutoScaling"), uiParticles);
|
DrawAutoScaling(s_SerializedObject.FindProperty("m_AutoScalingMode"), uiParticles);
|
||||||
EditorGUIUtility.labelWidth = labelWidth;
|
EditorGUIUtility.labelWidth = labelWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using Coffee.UIParticleExtensions;
|
using Coffee.UIParticleExtensions;
|
||||||
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Rendering;
|
using UnityEngine.Rendering;
|
||||||
using UnityEngine.Serialization;
|
using UnityEngine.Serialization;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
[assembly: InternalsVisibleTo("Coffee.UIParticle.Editor")]
|
[assembly: InternalsVisibleTo("Coffee.UIParticle.Editor")]
|
||||||
|
|
||||||
|
@ -33,6 +36,13 @@ namespace Coffee.UIExtensions
|
||||||
Absolute
|
Absolute
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum AutoScalingMode
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
UIParticle,
|
||||||
|
Transform
|
||||||
|
}
|
||||||
|
|
||||||
[HideInInspector]
|
[HideInInspector]
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
internal bool m_IsTrail;
|
internal bool m_IsTrail;
|
||||||
|
@ -82,10 +92,14 @@ namespace Coffee.UIExtensions
|
||||||
private PositionMode m_PositionMode = PositionMode.Relative;
|
private PositionMode m_PositionMode = PositionMode.Relative;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
[Tooltip("Transform.lossyScale (=world scale) is automatically set to (1, 1, 1), " +
|
[Tooltip("Prevent the root-Canvas scale from affecting the hierarchy-scaled ParticleSystem.")]
|
||||||
"to prevent the root-Canvas scale from affecting the hierarchy-scaled ParticleSystem.")]
|
|
||||||
private bool m_AutoScaling = true;
|
private bool m_AutoScaling = true;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
[Tooltip("Transform: Transform.lossyScale (=world scale) will be set to (1, 1, 1)." +
|
||||||
|
"UIParticle: UIParticle.scale will be adjusted.")]
|
||||||
|
private AutoScalingMode m_AutoScalingMode = AutoScalingMode.Transform;
|
||||||
|
|
||||||
private readonly List<UIParticleRenderer> _renderers = new List<UIParticleRenderer>();
|
private readonly List<UIParticleRenderer> _renderers = new List<UIParticleRenderer>();
|
||||||
private int _groupId;
|
private int _groupId;
|
||||||
private Camera _orthoCamera;
|
private Camera _orthoCamera;
|
||||||
|
@ -166,16 +180,30 @@ namespace Coffee.UIExtensions
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Transform.lossyScale (=world scale) will be set to (1, 1, 1) on update.
|
/// Prevents the root-Canvas scale from affecting the hierarchy-scaled ParticleSystem.
|
||||||
/// It prevents the root-Canvas scale from affecting the hierarchy-scaled ParticleSystem.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Obsolete("The autoScaling is now obsolete. Please use the autoScalingMode instead.", false)]
|
||||||
public bool autoScaling
|
public bool autoScaling
|
||||||
{
|
{
|
||||||
get { return m_AutoScaling; }
|
get { return m_AutoScalingMode != AutoScalingMode.None; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (m_AutoScaling == value) return;
|
autoScalingMode = value ? AutoScalingMode.Transform : AutoScalingMode.None;
|
||||||
m_AutoScaling = value;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Auto scaling mode.
|
||||||
|
/// Transform: Transform.lossyScale (=world scale) will be set to (1, 1, 1).
|
||||||
|
/// UIParticle: UIParticle.scale will be adjusted.
|
||||||
|
/// </summary>
|
||||||
|
public AutoScalingMode autoScalingMode
|
||||||
|
{
|
||||||
|
get { return m_AutoScalingMode; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (m_AutoScalingMode == value) return;
|
||||||
|
m_AutoScalingMode = value;
|
||||||
UpdateTracker();
|
UpdateTracker();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,6 +262,14 @@ namespace Coffee.UIExtensions
|
||||||
set { m_Scale3D = value; }
|
set { m_Scale3D = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Particle effect scale.
|
||||||
|
/// </summary>
|
||||||
|
public Vector3 scale3DForCalc
|
||||||
|
{
|
||||||
|
get { return autoScalingMode == AutoScalingMode.UIParticle ? m_Scale3D.GetScaled(canvasScale) : m_Scale3D; }
|
||||||
|
}
|
||||||
|
|
||||||
public List<ParticleSystem> particles
|
public List<ParticleSystem> particles
|
||||||
{
|
{
|
||||||
get { return m_Particles; }
|
get { return m_Particles; }
|
||||||
|
@ -267,6 +303,8 @@ namespace Coffee.UIExtensions
|
||||||
|
|
||||||
public Vector3 parentScale { get; private set; }
|
public Vector3 parentScale { get; private set; }
|
||||||
|
|
||||||
|
public Vector3 canvasScale { get; private set; }
|
||||||
|
|
||||||
protected override void OnEnable()
|
protected override void OnEnable()
|
||||||
{
|
{
|
||||||
ResetGroupId();
|
ResetGroupId();
|
||||||
|
@ -320,10 +358,11 @@ namespace Coffee.UIExtensions
|
||||||
|
|
||||||
void ISerializationCallbackReceiver.OnAfterDeserialize()
|
void ISerializationCallbackReceiver.OnAfterDeserialize()
|
||||||
{
|
{
|
||||||
if (m_IgnoreCanvasScaler)
|
if (m_IgnoreCanvasScaler || m_AutoScaling)
|
||||||
{
|
{
|
||||||
m_IgnoreCanvasScaler = false;
|
m_IgnoreCanvasScaler = false;
|
||||||
m_AutoScaling = false;
|
m_AutoScaling = false;
|
||||||
|
m_AutoScalingMode = AutoScalingMode.Transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_AbsoluteMode)
|
if (m_AbsoluteMode)
|
||||||
|
@ -471,8 +510,9 @@ namespace Coffee.UIExtensions
|
||||||
|
|
||||||
internal void UpdateTransformScale()
|
internal void UpdateTransformScale()
|
||||||
{
|
{
|
||||||
|
canvasScale = canvas.rootCanvas.transform.localScale.Inverse();
|
||||||
parentScale = transform.parent.lossyScale;
|
parentScale = transform.parent.lossyScale;
|
||||||
if (!autoScaling) return;
|
if (autoScalingMode != AutoScalingMode.Transform) return;
|
||||||
|
|
||||||
var newScale = parentScale.Inverse();
|
var newScale = parentScale.Inverse();
|
||||||
if (transform.localScale != newScale)
|
if (transform.localScale != newScale)
|
||||||
|
@ -606,7 +646,7 @@ namespace Coffee.UIExtensions
|
||||||
|
|
||||||
private void UpdateTracker()
|
private void UpdateTracker()
|
||||||
{
|
{
|
||||||
if (!enabled || !autoScaling)
|
if (!enabled || !autoScaling || autoScalingMode != AutoScalingMode.Transform)
|
||||||
{
|
{
|
||||||
_tracker.Clear();
|
_tracker.Clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,21 +182,22 @@ namespace Coffee.UIExtensions
|
||||||
if (isUI)
|
if (isUI)
|
||||||
{
|
{
|
||||||
var inverseScale = _uiParticle.parentScale.Inverse();
|
var inverseScale = _uiParticle.parentScale.Inverse();
|
||||||
dstPos = dstPos.GetScaled(inverseScale, _uiParticle.scale3D.Inverse());
|
var scale3d = _uiParticle.scale3DForCalc;
|
||||||
|
dstPos = dstPos.GetScaled(inverseScale, scale3d.Inverse());
|
||||||
|
|
||||||
// Relative mode
|
// Relative mode
|
||||||
if (_uiParticle.positionMode == UIParticle.PositionMode.Relative)
|
if (_uiParticle.positionMode == UIParticle.PositionMode.Relative)
|
||||||
{
|
{
|
||||||
var diff = _uiParticle.transform.position - psPos;
|
var diff = _uiParticle.transform.position - psPos;
|
||||||
diff.Scale(_uiParticle.scale3D - inverseScale);
|
diff.Scale(scale3d - inverseScale);
|
||||||
diff.Scale(_uiParticle.scale3D.Inverse());
|
diff.Scale(scale3d.Inverse());
|
||||||
dstPos += diff;
|
dstPos += diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
if (!Application.isPlaying && !isLocalSpace)
|
if (!Application.isPlaying && !isLocalSpace)
|
||||||
{
|
{
|
||||||
dstPos += psPos - psPos.GetScaled(inverseScale, _uiParticle.scale3D.Inverse());
|
dstPos += psPos - psPos.GetScaled(inverseScale, scale3d.Inverse());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -260,7 +260,7 @@ namespace Coffee.UIExtensions
|
||||||
!isActiveAndEnabled || !_particleSystem || !_parent
|
!isActiveAndEnabled || !_particleSystem || !_parent
|
||||||
|| !canvasRenderer || !canvas || !bakeCamera
|
|| !canvasRenderer || !canvas || !bakeCamera
|
||||||
|| _parent.meshSharing == UIParticle.MeshSharing.Replica
|
|| _parent.meshSharing == UIParticle.MeshSharing.Replica
|
||||||
|| !transform.lossyScale.GetScaled(_parent.scale3D).IsVisible() // Scale is not visible.
|
|| !transform.lossyScale.GetScaled(_parent.scale3DForCalc).IsVisible() // Scale is not visible.
|
||||||
|| (!_particleSystem.IsAlive() && !_particleSystem.isPlaying) // No particle.
|
|| (!_particleSystem.IsAlive() && !_particleSystem.isPlaying) // No particle.
|
||||||
|| (_isTrail && !_particleSystem.trails.enabled) // Trail, but it is not enabled.
|
|| (_isTrail && !_particleSystem.trails.enabled) // Trail, but it is not enabled.
|
||||||
#if UNITY_2018_3_OR_NEWER
|
#if UNITY_2018_3_OR_NEWER
|
||||||
|
@ -462,7 +462,7 @@ namespace Coffee.UIExtensions
|
||||||
private Vector3 GetWorldScale()
|
private Vector3 GetWorldScale()
|
||||||
{
|
{
|
||||||
Profiler.BeginSample("[UIParticleRenderer] GetWorldScale");
|
Profiler.BeginSample("[UIParticleRenderer] GetWorldScale");
|
||||||
var scale = _parent.scale3D.GetScaled(_parent.parentScale);
|
var scale = _parent.scale3DForCalc.GetScaled(_parent.parentScale);
|
||||||
Profiler.EndSample();
|
Profiler.EndSample();
|
||||||
return scale;
|
return scale;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue