From 234c25bc8761a4d41bc5b4aa362449cf3e806e13 Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 17 Sep 2021 20:09:19 +0800 Subject: *unit image effect --- Assets/Scripts/Unit/Components/UnitImageEffect.cs | 36 +++++++++++++++-------- 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'Assets/Scripts/Unit/Components/UnitImageEffect.cs') diff --git a/Assets/Scripts/Unit/Components/UnitImageEffect.cs b/Assets/Scripts/Unit/Components/UnitImageEffect.cs index a2689ca1..8af48a3e 100644 --- a/Assets/Scripts/Unit/Components/UnitImageEffect.cs +++ b/Assets/Scripts/Unit/Components/UnitImageEffect.cs @@ -17,14 +17,17 @@ public class UnitImageEffectHolder } } -public delegate void UnitImageEffectStepCallback(float normalizedTime); - public class UnitImageEffectHandle { - public float lifeTime; + public delegate void UnitImageEffectStepCallback(float normalizedTime); + public delegate void UnitImageEffectEndCallback(); + + public float lifeTime; public float curTime; public UnitImageEffectHolder holder; + public UnitImageEffectStepCallback stepFunc; + public UnitImageEffectEndCallback onStop; } //Unit后处理效果 @@ -49,6 +52,7 @@ public class UnitImageEffect : UnitComponent if(handle.curTime > handle.lifeTime) { temp.Add(handle); + handle.onStop?.Invoke(); continue; } handle.stepFunc?.Invoke(handle.curTime / handle.lifeTime); @@ -123,7 +127,6 @@ public class UnitImageEffect : UnitComponent holder = null; } - #region effects public void ShowMotionBlur(float lifeTime, float angle, float distance) { @@ -155,9 +158,11 @@ public class UnitImageEffect : UnitComponent effects.Add(handle); } - public void ShowGlitch(float lifeTime) + public void ShowGlitch(float lifeTime, bool hideUnitInMainCamera = true) { - UnitImageEffectHandle handle = m_HandlePool.Get(); + PCController pc = UnitManager.Instance.pc as PCController; + + UnitImageEffectHandle handle = m_HandlePool.Get(); handle.lifeTime = lifeTime; handle.curTime = 0; @@ -171,18 +176,25 @@ public class UnitImageEffect : UnitComponent handle.holder.renderer.GetPropertyBlock(block); handle.holder.renderer.SetPropertyBlock(block); - handle.stepFunc = (float normalTime) => - { + handle.stepFunc = (float normalTime) => { + UnitCamera.Instance.Render(); + handle.holder.gameObject.transform.position = UnitManager.Instance.pc.center; handle.holder.renderer.GetPropertyBlock(block); handle.holder.renderer.SetPropertyBlock(block); }; - effects.Add(handle); - } + if (hideUnitInMainCamera) + { + pc.unitRender.SetVisibilityInAllCameras(false); + } - - #endregion + handle.onStop = () => { + pc.unitRender.SetVisibilityInAllCameras(true); + }; + + effects.Add(handle); + } } \ No newline at end of file -- cgit v1.1-26-g67d0