feat: shrink rendering by material
NOTE: Performance will be improved, but in some cases the rendering is not correct. Close #113pull/120/head
parent
2ec81da048
commit
46a7dddd11
|
@ -29,6 +29,7 @@ namespace Coffee.UIExtensions
|
||||||
private SerializedProperty _spScale;
|
private SerializedProperty _spScale;
|
||||||
private SerializedProperty _spIgnoreCanvasScaler;
|
private SerializedProperty _spIgnoreCanvasScaler;
|
||||||
private SerializedProperty _spAnimatableProperties;
|
private SerializedProperty _spAnimatableProperties;
|
||||||
|
private SerializedProperty _spShrinkByMaterial;
|
||||||
|
|
||||||
private ReorderableList _ro;
|
private ReorderableList _ro;
|
||||||
private bool _xyzMode;
|
private bool _xyzMode;
|
||||||
|
@ -57,6 +58,7 @@ namespace Coffee.UIExtensions
|
||||||
_spScale = serializedObject.FindProperty("m_Scale3D");
|
_spScale = serializedObject.FindProperty("m_Scale3D");
|
||||||
_spIgnoreCanvasScaler = serializedObject.FindProperty("m_IgnoreCanvasScaler");
|
_spIgnoreCanvasScaler = serializedObject.FindProperty("m_IgnoreCanvasScaler");
|
||||||
_spAnimatableProperties = serializedObject.FindProperty("m_AnimatableProperties");
|
_spAnimatableProperties = serializedObject.FindProperty("m_AnimatableProperties");
|
||||||
|
_spShrinkByMaterial = serializedObject.FindProperty("m_ShrinkByMaterial");
|
||||||
|
|
||||||
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);
|
||||||
|
@ -164,6 +166,9 @@ namespace Coffee.UIExtensions
|
||||||
t.SetMaterialDirty();
|
t.SetMaterialDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ShrinkByMaterial
|
||||||
|
EditorGUILayout.PropertyField(_spShrinkByMaterial);
|
||||||
|
|
||||||
// Target ParticleSystems.
|
// Target ParticleSystems.
|
||||||
_ro.DoLayoutList();
|
_ro.DoLayoutList();
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,9 @@ namespace Coffee.UIExtensions
|
||||||
[Tooltip("Particles")] [SerializeField]
|
[Tooltip("Particles")] [SerializeField]
|
||||||
private List<ParticleSystem> m_Particles = new List<ParticleSystem>();
|
private List<ParticleSystem> m_Particles = new List<ParticleSystem>();
|
||||||
|
|
||||||
|
[Tooltip("Shrink rendering by material on refresh.\nNOTE: Performance will be improved, but in some cases the rendering is not correct.")] [SerializeField]
|
||||||
|
bool m_ShrinkByMaterial = false;
|
||||||
|
|
||||||
#if !SERIALIZE_FIELD_MASKABLE
|
#if !SERIALIZE_FIELD_MASKABLE
|
||||||
[SerializeField] private bool m_Maskable = true;
|
[SerializeField] private bool m_Maskable = true;
|
||||||
#endif
|
#endif
|
||||||
|
@ -81,6 +84,17 @@ namespace Coffee.UIExtensions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool shrinkByMaterial
|
||||||
|
{
|
||||||
|
get { return m_ShrinkByMaterial; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (m_ShrinkByMaterial == value) return;
|
||||||
|
m_ShrinkByMaterial = value;
|
||||||
|
RefreshParticles();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Particle effect scale.
|
/// Particle effect scale.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -217,7 +231,7 @@ namespace Coffee.UIExtensions
|
||||||
}
|
}
|
||||||
|
|
||||||
particles.Exec(p => p.GetComponent<ParticleSystemRenderer>().enabled = !enabled);
|
particles.Exec(p => p.GetComponent<ParticleSystemRenderer>().enabled = !enabled);
|
||||||
particles.SortForRendering(transform);
|
particles.SortForRendering(transform, m_ShrinkByMaterial);
|
||||||
|
|
||||||
SetMaterialDirty();
|
SetMaterialDirty();
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,7 +185,7 @@ namespace Coffee.UIParticleExtensions
|
||||||
|
|
||||||
internal static class ParticleSystemExtensions
|
internal static class ParticleSystemExtensions
|
||||||
{
|
{
|
||||||
public static void SortForRendering(this List<ParticleSystem> self, Transform transform)
|
public static void SortForRendering(this List<ParticleSystem> self, Transform transform, bool sortByMaterial)
|
||||||
{
|
{
|
||||||
self.Sort((a, b) =>
|
self.Sort((a, b) =>
|
||||||
{
|
{
|
||||||
|
@ -200,6 +200,9 @@ namespace Coffee.UIParticleExtensions
|
||||||
if (!aMat) return -1;
|
if (!aMat) return -1;
|
||||||
if (!bMat) return 1;
|
if (!bMat) return 1;
|
||||||
|
|
||||||
|
if (sortByMaterial)
|
||||||
|
return aMat.GetInstanceID() - bMat.GetInstanceID();
|
||||||
|
|
||||||
if (aMat.renderQueue != bMat.renderQueue)
|
if (aMat.renderQueue != bMat.renderQueue)
|
||||||
return aMat.renderQueue - bMat.renderQueue;
|
return aMat.renderQueue - bMat.renderQueue;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue