fix: inactive ParticleSystems are removed from the list on refresh

pull/289/head
mob-sakai 2023-08-17 17:48:48 +09:00
parent 2fe0bde422
commit 4851a1880e
4 changed files with 41 additions and 5 deletions

View File

@ -12,6 +12,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Coffee.UIParticleExtensions;
using UnityEditor; using UnityEditor;
using UnityEditor.UI; using UnityEditor.UI;
using UnityEditorInternal; using UnityEditorInternal;
@ -127,7 +128,7 @@ namespace Coffee.UIExtensions
{ {
var uiParticles = Selection.gameObjects.Select(x => x.GetComponent<ParticleSystem>()) var uiParticles = Selection.gameObjects.Select(x => x.GetComponent<ParticleSystem>())
.Where(x => x) .Where(x => x)
.Select(x => x.GetComponentInParent<UIParticle>()) .Select(x => x.GetComponentInParent<UIParticle>(true))
.Where(x => x && x.canvas) .Where(x => x && x.canvas)
.Concat(Selection.gameObjects.Select(x => x.GetComponent<UIParticle>()) .Concat(Selection.gameObjects.Select(x => x.GetComponent<UIParticle>())
.Where(x => x && x.canvas)) .Where(x => x && x.canvas))
@ -315,7 +316,7 @@ namespace Coffee.UIExtensions
} }
// Does the shader support UI masks? // Does the shader support UI masks?
if (current.maskable && current.GetComponentInParent<Mask>()) if (current.maskable && current.GetComponentInParent<Mask>(false))
{ {
foreach (var mat in current.materials) foreach (var mat in current.materials)
{ {

View File

@ -394,8 +394,8 @@ namespace Coffee.UIExtensions
private void RefreshParticles(GameObject root) private void RefreshParticles(GameObject root)
{ {
if (!root) return; if (!root) return;
root.GetComponentsInChildren(particles); root.GetComponentsInChildren(true, particles);
particles.RemoveAll(x => x.GetComponentInParent<UIParticle>() != this); particles.RemoveAll(x => x.GetComponentInParent<UIParticle>(true) != this);
for (var i = 0; i < particles.Count; i++) for (var i = 0; i < particles.Count; i++)
{ {

View File

@ -248,7 +248,7 @@ namespace Coffee.UIExtensions
return; return;
} }
_uiParticle = m_ParticleSystem.GetComponentInParent<UIParticle>(); _uiParticle = m_ParticleSystem.GetComponentInParent<UIParticle>(true);
if (_uiParticle && !_uiParticle.particles.Contains(m_ParticleSystem)) if (_uiParticle && !_uiParticle.particles.Contains(m_ParticleSystem))
{ {
_uiParticle = null; _uiParticle = null;

View File

@ -244,5 +244,40 @@ namespace Coffee.UIParticleExtensions
Object.Destroy(obj); Object.Destroy(obj);
} }
} }
#if !UNITY_2020_3_OR_NEWER
public static T GetComponentInParent<T>(this Component self, bool includeInactive) where T : Component
{
if (!self) return null;
if (!includeInactive) return self.GetComponentInParent<T>();
var current = self.transform;
while (current)
{
var component = current.GetComponent<T>();
if (component) return component;
current = current.parent;
}
return null;
}
public static T GetComponentInChildren<T>(this Component self, bool includeInactive) where T : Component
{
if (!self) return null;
if (!includeInactive) return self.GetComponentInChildren<T>();
var component = self.GetComponent<T>();
if (component) return component;
foreach (Transform child in self.transform)
{
component = child.GetComponentInChildren<T>(true);
if (component) return component;
}
return null;
}
#endif
} }
} }