pull/33/head
mob-sakai 2018-06-22 19:06:13 +09:00
parent a39f20861c
commit 9ca9a2ad76
1 changed files with 143 additions and 125 deletions

View File

@ -4,23 +4,35 @@ using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.UI;
//[RequireComponent(typeof(ParticleSystem))]
[ExecuteInEditMode]
public class UIParticle : MaskableGraphic
namespace Coffee.UIExtensions
{
/// <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 List<Vector3> s_Vertices = new List<Vector3>();
//################################
// Serialize Members.
//################################
[Tooltip("The ParticleSystem rendered by CanvasRenderer")]
[SerializeField] ParticleSystem m_ParticleSystem;
[Tooltip("The UIParticle to render trail effect")]
[SerializeField] UIParticle m_TrailParticle;
Mesh _mesh;
ParticleSystemRenderer _renderer;
[HideInInspector] [SerializeField] bool m_IsTrail = false;
//################################
// Public/Protected Members.
//################################
public override Texture mainTexture
{
get
@ -54,35 +66,16 @@ public class UIParticle : MaskableGraphic
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()
{
}
//################################
// Private Members.
//################################
Mesh _mesh;
ParticleSystemRenderer _renderer;
void Update()
{
Profiler.BeginSample("CheckTrail");
@ -150,7 +143,32 @@ public class UIParticle : MaskableGraphic
Profiler.BeginSample("Set mesh to CanvasRenderer");
canvasRenderer.SetMesh(_mesh);
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;
}
}
}
}