fix on editor: on select UIParticle, particles will be cleared

pull/225/head
mob-sakai 2022-06-21 19:47:08 +09:00
parent 8c959b257c
commit 4fe9a3200d
3 changed files with 22 additions and 6 deletions

View File

@ -68,6 +68,7 @@ namespace Coffee.UIExtensions
static private bool _xyzMode; static private bool _xyzMode;
private bool _showMax; private bool _showMax;
private static readonly HashSet<Shader> s_Shaders = new HashSet<Shader>();
private static readonly List<string> s_MaskablePropertyNames = new List<string> private static readonly List<string> s_MaskablePropertyNames = new List<string>
{ {
"_Stencil", "_Stencil",
@ -192,6 +193,15 @@ namespace Coffee.UIExtensions
t.RefreshParticles(t.particles); t.RefreshParticles(t.particles);
} }
}; };
// On select UIParticle, refresh particles.
if (!Application.isPlaying)
{
foreach (UIParticle t in targets)
{
t.RefreshParticles(t.particles);
}
}
} }
private static void MaterialField(Rect rect, GUIContent label, SerializedProperty sp, int index) private static void MaterialField(Rect rect, GUIContent label, SerializedProperty sp, int index)
@ -260,6 +270,8 @@ namespace Coffee.UIExtensions
{ {
if (!mat || !mat.shader) continue; if (!mat || !mat.shader) continue;
var shader = mat.shader; var shader = mat.shader;
if (s_Shaders.Contains(shader)) continue;
s_Shaders.Add(shader);
foreach (var propName in s_MaskablePropertyNames) foreach (var propName in s_MaskablePropertyNames)
{ {
if (mat.HasProperty(propName)) continue; if (mat.HasProperty(propName)) continue;
@ -269,6 +281,7 @@ namespace Coffee.UIExtensions
} }
} }
} }
s_Shaders.Clear();
// UIParticle for trail should be removed. // UIParticle for trail should be removed.
if (FixButton(current.m_IsTrail, "This UIParticle component should be removed. The UIParticle for trails is no longer needed.")) if (FixButton(current.m_IsTrail, "This UIParticle component should be removed. The UIParticle for trails is no longer needed."))
@ -286,7 +299,7 @@ namespace Coffee.UIExtensions
if (0 < allPsRenderers.Length) if (0 < allPsRenderers.Length)
{ {
var so = new SerializedObject(allPsRenderers); var so = new SerializedObject(allPsRenderers);
var sp = so.FindProperty("m_ApplyActiveColorSpace");//.boolValue = false; var sp = so.FindProperty("m_ApplyActiveColorSpace");
if (FixButton(sp.boolValue || sp.hasMultipleDifferentValues, "When using linear color space, the particle colors are not output correctly.\nTo fix, set 'Apply Active Color Space' in renderer module to false.")) if (FixButton(sp.boolValue || sp.hasMultipleDifferentValues, "When using linear color space, the particle colors are not output correctly.\nTo fix, set 'Apply Active Color Space' in renderer module to false."))
{ {
sp.boolValue = false; sp.boolValue = false;

View File

@ -272,11 +272,6 @@ namespace Coffee.UIExtensions
{ {
GetComponentsInChildren(m_Renderers); GetComponentsInChildren(m_Renderers);
for (var i = 0; i < m_Renderers.Count; i++)
{
GetRenderer(i).Clear(i);
}
var j = 0; var j = 0;
for (var i = 0; i < particles.Count; i++) for (var i = 0; i < particles.Count; i++)
{ {
@ -286,6 +281,11 @@ namespace Coffee.UIExtensions
GetRenderer(j++).Set(this, particles[i], true); GetRenderer(j++).Set(this, particles[i], true);
} }
} }
for (; j < m_Renderers.Count; j++)
{
GetRenderer(j).Clear(j);
}
} }
internal void UpdateTransformScale() internal void UpdateTransformScale()

View File

@ -135,6 +135,9 @@ namespace Coffee.UIExtensions
gameObject.layer = parent.gameObject.layer; gameObject.layer = parent.gameObject.layer;
_particleSystem = particleSystem; _particleSystem = particleSystem;
#if UNITY_EDITOR
if (Application.isPlaying)
#endif
if (_particleSystem.isPlaying) if (_particleSystem.isPlaying)
{ {
_particleSystem.Clear(); _particleSystem.Clear();