feat: 'AbsoluteMode' option is renamed to 'PositionMode'

AbsoluteMode property is obsolete
pull/289/head
mob-sakai 2023-08-18 11:42:22 +09:00
parent 4851a1880e
commit 67eff61073
4 changed files with 49 additions and 20 deletions

View File

@ -74,8 +74,8 @@ namespace Coffee.UIExtensions
private SerializedProperty _meshSharing;
private SerializedProperty _groupId;
private SerializedProperty _groupMaxId;
private SerializedProperty _absoluteMode;
private SerializedProperty _ignoreCanvasScaler;
private SerializedProperty _positionMode;
private ReorderableList _ro;
private bool _showMax;
@ -157,8 +157,8 @@ namespace Coffee.UIExtensions
_meshSharing = serializedObject.FindProperty("m_MeshSharing");
_groupId = serializedObject.FindProperty("m_GroupId");
_groupMaxId = serializedObject.FindProperty("m_GroupMaxId");
_absoluteMode = serializedObject.FindProperty("m_AbsoluteMode");
_ignoreCanvasScaler = serializedObject.FindProperty("m_IgnoreCanvasScaler");
_positionMode = serializedObject.FindProperty("m_PositionMode");
var sp = serializedObject.FindProperty("m_Particles");
_ro = new ReorderableList(sp.serializedObject, sp, true, true, true, true)
@ -272,8 +272,8 @@ namespace Coffee.UIExtensions
}
}
// Absolute Mode
EditorGUILayout.PropertyField(_absoluteMode);
// Position Mode
EditorGUILayout.PropertyField(_positionMode);
// Auto Scaling
DrawInversedToggle(_ignoreCanvasScaler, s_ContentAutoScaling, () =>
@ -522,7 +522,6 @@ namespace Coffee.UIExtensions
EditorGUIUtility.labelWidth = 100;
EditorGUILayout.PropertyField(s_SerializedObject.FindProperty("m_Enabled"));
s_XYZMode = DrawFloatOrVector3Field(s_SerializedObject.FindProperty("m_Scale3D"), s_XYZMode);
EditorGUILayout.PropertyField(s_SerializedObject.FindProperty("m_AbsoluteMode"));
DrawInversedToggle(s_SerializedObject.FindProperty("m_IgnoreCanvasScaler"),
s_ContentAutoScaling,
() =>
@ -533,6 +532,7 @@ namespace Coffee.UIExtensions
.ToList()
.ForEach(x => x.transform.localScale = Vector3.one);
});
EditorGUILayout.PropertyField(s_SerializedObject.FindProperty("m_PositionMode"));
EditorGUIUtility.labelWidth = labelWidth;
}

View File

@ -19,7 +19,7 @@ namespace Coffee.UIExtensions
[ExecuteAlways]
[RequireComponent(typeof(RectTransform))]
[RequireComponent(typeof(CanvasRenderer))]
public class UIParticle : MaskableGraphic
public class UIParticle : MaskableGraphic, ISerializationCallbackReceiver
{
public enum MeshSharing
{
@ -30,10 +30,20 @@ namespace Coffee.UIExtensions
Replica
}
public enum PositionMode
{
Relative,
Absolute
}
[HideInInspector]
[SerializeField]
internal bool m_IsTrail;
[HideInInspector]
[SerializeField]
private bool m_AbsoluteMode;
[Tooltip("Particle effect scale")]
[SerializeField]
private Vector3 m_Scale3D = new Vector3(10, 10, 10);
@ -64,13 +74,10 @@ namespace Coffee.UIExtensions
[SerializeField]
private int m_GroupMaxId;
[Tooltip("Relative: The particles will be emitted from the scaled position of ParticleSystem.\n" +
"Absolute: The particles will be emitted from the world position of ParticleSystem.")]
[SerializeField]
[Tooltip("Particle position mode.\n" +
"Absolute Mode: The particles will be emitted from the ParticleSystem position.\n" +
" Move the UIParticle or ParticleSystem to move the particle.\n" +
"Relative Mode: The particles will be emitted from the scaled ParticleSystem position.\n" +
" Move the UIParticle to move the particle.")]
private bool m_AbsoluteMode = false;
private PositionMode m_PositionMode = PositionMode.Relative;
/// <summary>
/// This field uses the inverted value as "AutoScaling".
@ -142,15 +149,24 @@ namespace Coffee.UIExtensions
/// <summary>
/// Particle position mode.
/// Absolute Mode: The particles will be emitted from the ParticleSystem position.
/// Move the UIParticle or ParticleSystem to move the particle.
/// Relative Mode: The particles will be emitted from the scaled ParticleSystem position.
/// Move the UIParticle to move the particle.
/// Relative: The particles will be emitted from the scaled position of the ParticleSystem.
/// Absolute: The particles will be emitted from the world position of the ParticleSystem.
/// </summary>
public PositionMode positionMode
{
get { return m_PositionMode; }
set { m_PositionMode = value; }
}
/// <summary>
/// Particle position mode.
/// Relative: The particles will be emitted from the scaled position of the ParticleSystem.
/// Absolute: The particles will be emitted from the world position of the ParticleSystem.
/// </summary>
public bool absoluteMode
{
get { return m_AbsoluteMode; }
set { m_AbsoluteMode = value; }
get { return m_PositionMode == PositionMode.Absolute; }
set { positionMode = value ? PositionMode.Absolute : PositionMode.Relative; }
}
/// <summary>
@ -306,6 +322,19 @@ namespace Coffee.UIExtensions
}
#endif
void ISerializationCallbackReceiver.OnBeforeSerialize()
{
m_AbsoluteMode = m_PositionMode == PositionMode.Absolute;
}
void ISerializationCallbackReceiver.OnAfterDeserialize()
{
if (m_AbsoluteMode)
{
m_PositionMode = PositionMode.Absolute;
}
}
public void Play()
{
particles.Exec(p => p.Simulate(0, false, true));

View File

@ -185,7 +185,7 @@ namespace Coffee.UIExtensions
dstPos = dstPos.GetScaled(inverseScale, _uiParticle.scale3D.Inverse());
// Relative mode
if (!_uiParticle.absoluteMode)
if (_uiParticle.positionMode == UIParticle.PositionMode.Relative)
{
var diff = _uiParticle.transform.position - psPos;
diff.Scale(_uiParticle.scale3D - inverseScale);

View File

@ -353,7 +353,7 @@ namespace Coffee.UIExtensions
Profiler.BeginSample("[UIParticleRenderer] Combine Mesh");
if (_parent.canSimulate)
{
if (_parent.absoluteMode)
if (_parent.positionMode == UIParticle.PositionMode.Absolute)
{
s_CombineInstances[0].transform =
canvasRenderer.transform.worldToLocalMatrix