235 lines
5.3 KiB
C#
235 lines
5.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System;
|
|
using UnityEngine;
|
|
|
|
namespace BF
|
|
{
|
|
[ExecuteInEditMode]
|
|
[DisallowMultipleComponent]
|
|
public class EffectHelper : BaseSortingOrderHelper
|
|
{
|
|
private Renderer[] effects;
|
|
private ParticleSystem[] particles;
|
|
private List<int> originOrderList;
|
|
public ParticleSystem RootParticle;
|
|
public float EffectDuration = 0.0f;
|
|
public int AnimatorCount = 0;
|
|
public int TrailRendererCount = 0;
|
|
// 判断战斗翻转特效的时候使用角度翻转或者是ScaleX翻转
|
|
public bool EulerAnglesFlip = false;
|
|
private TrailRenderer[] trailRendererList;
|
|
private ParticleSystemRenderer[] particleSystemRendererList;
|
|
private List<int> particleSystemOriginOrderList;
|
|
private List<float> particleSystemOriginFudgeList;
|
|
|
|
void Awake()
|
|
{
|
|
effects = this.transform.GetComponentsInChildren<Renderer>(true);
|
|
int len = effects.Length;
|
|
if (len > 0)
|
|
{
|
|
originOrderList = new List<int>(len);
|
|
for(int i = 0; i < len; i++)
|
|
{
|
|
originOrderList.Add(effects[i].sortingOrder);
|
|
}
|
|
}
|
|
|
|
if (TrailRendererCount > 0)
|
|
{
|
|
trailRendererList = transform.GetComponentsInChildren<TrailRenderer>(true);
|
|
}
|
|
}
|
|
|
|
public void InitParticleSystemRendererList()
|
|
{
|
|
if (ReferenceEquals(particleSystemRendererList, null))
|
|
{
|
|
particleSystemRendererList = transform.GetComponentsInChildren<ParticleSystemRenderer>(true);
|
|
int length = particleSystemRendererList.Length;
|
|
if (length > 0)
|
|
{
|
|
particleSystemOriginOrderList = new List<int>(length);
|
|
particleSystemOriginFudgeList = new List<float>(length);
|
|
for(int i = 0; i < length; i++)
|
|
{
|
|
particleSystemOriginOrderList.Add(particleSystemRendererList[i].sortingOrder);
|
|
particleSystemOriginFudgeList.Add(particleSystemRendererList[i].sortingFudge);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetLocalPosition(float x, float y, float z)
|
|
{
|
|
this.transform.localPosition = new Vector3(x, y, z);
|
|
}
|
|
|
|
public void SetPosition(float x, float y, float z)
|
|
{
|
|
this.transform.position = new Vector3(x, y, z);
|
|
}
|
|
|
|
public void SetLocalEulerAngles(float x, float y, float z)
|
|
{
|
|
this.transform.localEulerAngles = new Vector3(x, y, z);
|
|
}
|
|
|
|
public void SetEulerAngles(float x, float y, float z)
|
|
{
|
|
this.transform.eulerAngles = new Vector3(x, y, z);
|
|
}
|
|
|
|
public void SetLocalScale(float x, float y, float z)
|
|
{
|
|
this.transform.localScale = new Vector3(x, y, z);
|
|
}
|
|
|
|
public override void SetSortingOrder(int uiOrder, int order)
|
|
{
|
|
GroupOrder = order;
|
|
if (!ReferenceEquals(effects, null))
|
|
{
|
|
int len = effects.Length;
|
|
for(int i = 0; i < len; i++)
|
|
{
|
|
effects[i].sortingOrder = originOrderList[i] + uiOrder + order;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void SetUIOrder(int uiOrder)
|
|
{
|
|
if (!ReferenceEquals(effects, null))
|
|
{
|
|
int len = effects.Length;
|
|
for(int i = 0; i < len; i++)
|
|
{
|
|
effects[i].sortingOrder = originOrderList[i] + uiOrder + GroupOrder;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ChangeSortingOrderToFudge(int order, float coefficient)
|
|
{
|
|
InitParticleSystemRendererList();
|
|
int len = particleSystemRendererList.Length;
|
|
if (len > 0)
|
|
{
|
|
for(int i = 0; i < len; i++)
|
|
{
|
|
particleSystemRendererList[i].sortingFudge = particleSystemOriginFudgeList[i] - particleSystemOriginOrderList[i] / coefficient;
|
|
particleSystemRendererList[i].sortingOrder = order;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Play()
|
|
{
|
|
if(RootParticle != null)
|
|
{
|
|
RootParticle.Play();
|
|
}
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
if(RootParticle != null)
|
|
{
|
|
RootParticle.Clear();
|
|
}
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
if(RootParticle != null)
|
|
{
|
|
RootParticle.Stop();
|
|
}
|
|
}
|
|
|
|
public void StopAndClear()
|
|
{
|
|
if(RootParticle != null)
|
|
{
|
|
RootParticle.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
|
|
}
|
|
}
|
|
|
|
public void ClearTrail()
|
|
{
|
|
if (TrailRendererCount > 0 && !ReferenceEquals(trailRendererList, null))
|
|
{
|
|
int len = trailRendererList.Length;
|
|
if (len > 0)
|
|
{
|
|
for(int i = 0; i < len; i++)
|
|
{
|
|
trailRendererList[i].Clear();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Pause()
|
|
{
|
|
if(RootParticle != null)
|
|
{
|
|
RootParticle.Pause();
|
|
}
|
|
}
|
|
|
|
public void SetTimeScale(float timeScale)
|
|
{
|
|
if(RootParticle != null)
|
|
{
|
|
if (ReferenceEquals(particles, null))
|
|
{
|
|
particles = RootParticle.transform.GetComponentsInChildren<ParticleSystem>(true);
|
|
}
|
|
var mainModule = RootParticle.main;
|
|
mainModule.simulationSpeed = timeScale;
|
|
int len = particles.Length;
|
|
for(int i = 0; i < len; i++)
|
|
{
|
|
mainModule = particles[i].main;
|
|
mainModule.simulationSpeed = timeScale;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetParticleActive(bool active)
|
|
{
|
|
if(!ReferenceEquals(RootParticle, null))
|
|
{
|
|
if (RootParticle.gameObject.activeSelf != active)
|
|
{
|
|
RootParticle.gameObject.SetActive(active);
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool GetIsParticleActive()
|
|
{
|
|
if(ReferenceEquals(RootParticle, null))
|
|
{
|
|
return false;
|
|
}
|
|
return RootParticle.gameObject.activeSelf;
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
if (!ReferenceEquals(effects, null))
|
|
{
|
|
effects = null;
|
|
if (null != originOrderList)
|
|
originOrderList.Clear();
|
|
originOrderList = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|