Refactor
parent
a39f20861c
commit
9ca9a2ad76
|
@ -4,23 +4,35 @@ using UnityEngine;
|
||||||
using UnityEngine.Profiling;
|
using UnityEngine.Profiling;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
//[RequireComponent(typeof(ParticleSystem))]
|
|
||||||
[ExecuteInEditMode]
|
namespace Coffee.UIExtensions
|
||||||
public class UIParticle : MaskableGraphic
|
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Render maskable and sortable particle effect ,without Camera, RenderTexture or Canvas.
|
||||||
|
/// </summary>
|
||||||
|
[ExecuteInEditMode]
|
||||||
|
public class UIParticle : MaskableGraphic
|
||||||
|
{
|
||||||
|
//################################
|
||||||
|
// Constant or Readonly Static Members.
|
||||||
|
//################################
|
||||||
static readonly int s_IdMainTex = Shader.PropertyToID("_MainTex");
|
static readonly int s_IdMainTex = Shader.PropertyToID("_MainTex");
|
||||||
static readonly List<Vector3> s_Vertices = new List<Vector3>();
|
static readonly List<Vector3> s_Vertices = new List<Vector3>();
|
||||||
|
|
||||||
|
|
||||||
|
//################################
|
||||||
|
// Serialize Members.
|
||||||
|
//################################
|
||||||
|
[Tooltip("The ParticleSystem rendered by CanvasRenderer")]
|
||||||
[SerializeField] ParticleSystem m_ParticleSystem;
|
[SerializeField] ParticleSystem m_ParticleSystem;
|
||||||
|
[Tooltip("The UIParticle to render trail effect")]
|
||||||
[SerializeField] UIParticle m_TrailParticle;
|
[SerializeField] UIParticle m_TrailParticle;
|
||||||
|
|
||||||
Mesh _mesh;
|
|
||||||
ParticleSystemRenderer _renderer;
|
|
||||||
|
|
||||||
[HideInInspector] [SerializeField] bool m_IsTrail = false;
|
[HideInInspector] [SerializeField] bool m_IsTrail = false;
|
||||||
|
|
||||||
|
|
||||||
|
//################################
|
||||||
|
// Public/Protected Members.
|
||||||
|
//################################
|
||||||
public override Texture mainTexture
|
public override Texture mainTexture
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -54,35 +66,16 @@ public class UIParticle : MaskableGraphic
|
||||||
base.OnDisable();
|
base.OnDisable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckTrail()
|
|
||||||
{
|
|
||||||
if (isActiveAndEnabled && !m_IsTrail && m_ParticleSystem && m_ParticleSystem.trails.enabled)
|
|
||||||
{
|
|
||||||
if (!m_TrailParticle)
|
|
||||||
{
|
|
||||||
m_TrailParticle = new GameObject("[UIParticle] Trail").AddComponent<UIParticle>();
|
|
||||||
var trans = m_TrailParticle.transform;
|
|
||||||
trans.SetParent(transform);
|
|
||||||
trans.localPosition = Vector3.zero;
|
|
||||||
trans.localRotation = Quaternion.identity;
|
|
||||||
trans.localScale = Vector3.one;
|
|
||||||
|
|
||||||
m_TrailParticle._renderer = GetComponent<ParticleSystemRenderer>();
|
|
||||||
m_TrailParticle.m_ParticleSystem = GetComponent<ParticleSystem>();
|
|
||||||
m_TrailParticle.m_IsTrail = true;
|
|
||||||
}
|
|
||||||
m_TrailParticle.enabled = true;
|
|
||||||
}
|
|
||||||
else if (m_TrailParticle)
|
|
||||||
{
|
|
||||||
m_TrailParticle.enabled = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void UpdateGeometry()
|
protected override void UpdateGeometry()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//################################
|
||||||
|
// Private Members.
|
||||||
|
//################################
|
||||||
|
Mesh _mesh;
|
||||||
|
ParticleSystemRenderer _renderer;
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
Profiler.BeginSample("CheckTrail");
|
Profiler.BeginSample("CheckTrail");
|
||||||
|
@ -150,7 +143,32 @@ public class UIParticle : MaskableGraphic
|
||||||
Profiler.BeginSample("Set mesh to CanvasRenderer");
|
Profiler.BeginSample("Set mesh to CanvasRenderer");
|
||||||
canvasRenderer.SetMesh(_mesh);
|
canvasRenderer.SetMesh(_mesh);
|
||||||
Profiler.EndSample();
|
Profiler.EndSample();
|
||||||
//canvasRenderer.SetColor(color);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckTrail()
|
||||||
|
{
|
||||||
|
if (isActiveAndEnabled && !m_IsTrail && m_ParticleSystem && m_ParticleSystem.trails.enabled)
|
||||||
|
{
|
||||||
|
if (!m_TrailParticle)
|
||||||
|
{
|
||||||
|
m_TrailParticle = new GameObject("[UIParticle] Trail").AddComponent<UIParticle>();
|
||||||
|
var trans = m_TrailParticle.transform;
|
||||||
|
trans.SetParent(transform);
|
||||||
|
trans.localPosition = Vector3.zero;
|
||||||
|
trans.localRotation = Quaternion.identity;
|
||||||
|
trans.localScale = Vector3.one;
|
||||||
|
|
||||||
|
m_TrailParticle._renderer = GetComponent<ParticleSystemRenderer>();
|
||||||
|
m_TrailParticle.m_ParticleSystem = GetComponent<ParticleSystem>();
|
||||||
|
m_TrailParticle.m_IsTrail = true;
|
||||||
|
}
|
||||||
|
m_TrailParticle.enabled = true;
|
||||||
|
}
|
||||||
|
else if (m_TrailParticle)
|
||||||
|
{
|
||||||
|
m_TrailParticle.enabled = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue