2020-08-20 03:42:16 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Profiling;
|
|
|
|
|
|
|
|
namespace Coffee.UIExtensions
|
|
|
|
{
|
2020-10-01 15:15:57 +08:00
|
|
|
internal static class UIParticleUpdater
|
2020-08-20 03:42:16 +08:00
|
|
|
{
|
|
|
|
static readonly List<UIParticle> s_ActiveParticles = new List<UIParticle>();
|
2021-06-03 02:03:16 +08:00
|
|
|
private static int frameCount = 0;
|
2020-08-28 13:38:13 +08:00
|
|
|
|
2022-06-11 21:32:14 +08:00
|
|
|
public static int uiParticleCount
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return s_ActiveParticles.Count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-20 03:42:16 +08:00
|
|
|
public static void Register(UIParticle particle)
|
|
|
|
{
|
|
|
|
if (!particle) return;
|
|
|
|
s_ActiveParticles.Add(particle);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Unregister(UIParticle particle)
|
|
|
|
{
|
|
|
|
if (!particle) return;
|
|
|
|
s_ActiveParticles.Remove(particle);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
[UnityEditor.InitializeOnLoadMethod]
|
|
|
|
#endif
|
|
|
|
[RuntimeInitializeOnLoadMethod]
|
|
|
|
private static void InitializeOnLoad()
|
|
|
|
{
|
|
|
|
Canvas.willRenderCanvases -= Refresh;
|
|
|
|
Canvas.willRenderCanvases += Refresh;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void Refresh()
|
|
|
|
{
|
2021-06-03 02:03:16 +08:00
|
|
|
// Do not allow it to be called in the same frame.
|
|
|
|
if (frameCount == Time.frameCount) return;
|
|
|
|
frameCount = Time.frameCount;
|
|
|
|
|
2020-09-02 13:15:30 +08:00
|
|
|
Profiler.BeginSample("[UIParticle] Refresh");
|
2020-08-20 03:42:16 +08:00
|
|
|
for (var i = 0; i < s_ActiveParticles.Count; i++)
|
|
|
|
{
|
2022-06-11 21:32:14 +08:00
|
|
|
var uip = s_ActiveParticles[i];
|
2020-08-20 03:42:16 +08:00
|
|
|
try
|
|
|
|
{
|
2022-06-11 21:32:14 +08:00
|
|
|
uip.UpdateTransformScale();
|
|
|
|
uip.UpdateRenderers();
|
2020-08-20 03:42:16 +08:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Debug.LogException(e);
|
|
|
|
}
|
|
|
|
}
|
2020-09-02 13:15:30 +08:00
|
|
|
Profiler.EndSample();
|
2020-08-20 03:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|