ParticleEffectForUGUI/Assets/Demo/Performance Demo/Scripts/UIParticle_PerformanceDemo.cs

86 lines
2.3 KiB
C#
Raw Normal View History

2024-11-21 00:36:51 +08:00
using Coffee.UIParticleInternal;
2024-01-23 22:17:57 +08:00
using UnityEngine;
2023-08-17 08:43:02 +08:00
using UnityEngine.Serialization;
2022-06-14 12:39:13 +08:00
namespace Coffee.UIExtensions.Demo
{
public class UIParticle_PerformanceDemo : MonoBehaviour
{
2023-08-17 08:43:02 +08:00
[FormerlySerializedAs("copyOrigin")]
[SerializeField]
private GameObject m_CopyOrigin;
[FormerlySerializedAs("copyCount")]
[SerializeField]
public int m_CopyCount;
[FormerlySerializedAs("root")]
[SerializeField]
public Canvas m_RootCanvas;
2022-06-14 12:39:13 +08:00
private void Start()
{
Application.targetFrameRate = 60;
2023-08-17 08:43:02 +08:00
if (m_CopyOrigin)
2022-06-14 12:39:13 +08:00
{
2023-08-17 08:43:02 +08:00
m_CopyOrigin.SetActive(false);
2022-06-14 12:39:13 +08:00
2023-08-17 08:43:02 +08:00
var parent = m_CopyOrigin.transform.parent;
for (var i = 0; i < m_CopyCount; i++)
2022-06-14 12:39:13 +08:00
{
2023-08-17 08:43:02 +08:00
var go = Instantiate(m_CopyOrigin, parent, false);
go.name = string.Format("{0} {1}", m_CopyOrigin.name, i + 1);
2022-06-14 12:39:13 +08:00
go.hideFlags = HideFlags.DontSave;
go.SetActive(true);
}
}
}
2023-08-17 08:43:02 +08:00
public void UIParticle_Enable(bool flag)
2022-06-14 12:39:13 +08:00
{
2023-08-17 08:43:02 +08:00
foreach (var uip in m_RootCanvas.GetComponentsInChildren<UIParticle>(true))
2022-06-14 12:39:13 +08:00
{
2023-08-17 08:43:02 +08:00
uip.enabled = flag;
2022-06-14 12:39:13 +08:00
}
2023-08-17 08:43:02 +08:00
if (!flag)
2022-06-14 12:39:13 +08:00
{
2024-11-21 00:36:51 +08:00
foreach (var ps in Misc.FindObjectsOfType<ParticleSystem>())
2022-06-14 12:39:13 +08:00
{
ps.Play(false);
}
}
}
2023-08-17 08:43:02 +08:00
public void UIParticle_MeshSharing(bool flag)
2022-06-14 12:39:13 +08:00
{
2023-08-17 08:43:02 +08:00
foreach (var uip in m_RootCanvas.GetComponentsInChildren<UIParticle>(true))
2022-06-14 12:39:13 +08:00
{
2023-08-17 08:43:02 +08:00
uip.meshSharing = flag
? UIParticle.MeshSharing.Auto
: UIParticle.MeshSharing.None;
2022-06-14 12:39:13 +08:00
}
}
2023-08-17 08:43:02 +08:00
public void UIParticle_RandomGroup(bool flag)
2022-06-14 12:39:13 +08:00
{
2023-08-17 08:43:02 +08:00
foreach (var uip in m_RootCanvas.GetComponentsInChildren<UIParticle>(true))
2022-06-14 12:39:13 +08:00
{
2023-08-17 08:43:02 +08:00
uip.groupMaxId = flag
? 4
: 0;
2022-06-14 12:39:13 +08:00
}
}
public void ParticleSystem_SetScale(float scale)
{
2024-11-21 00:36:51 +08:00
foreach (var ps in Misc.FindObjectsOfType<ParticleSystem>())
2022-06-14 12:39:13 +08:00
{
ps.transform.localScale = new Vector3(scale, scale, scale);
}
}
}
}