summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Unit/Components/UnitLensEffect.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts/Unit/Components/UnitLensEffect.cs')
-rw-r--r--Assets/Scripts/Unit/Components/UnitLensEffect.cs24
1 files changed, 19 insertions, 5 deletions
diff --git a/Assets/Scripts/Unit/Components/UnitLensEffect.cs b/Assets/Scripts/Unit/Components/UnitLensEffect.cs
index 5a68faf8..7758c943 100644
--- a/Assets/Scripts/Unit/Components/UnitLensEffect.cs
+++ b/Assets/Scripts/Unit/Components/UnitLensEffect.cs
@@ -77,6 +77,9 @@ public class UnitLensEffect : UnitComponent
private void OnWillRenderUnit()
{
+ if (m_Effects == null || m_Effects.Count == 0)
+ return;
+
PrepareCommandBuffers();
IBodyRendererAgent body = owner.unitRender.body;
@@ -116,8 +119,11 @@ public class UnitLensEffect : UnitComponent
}
}
- private void OnRenderUnit()
- {
+ private void OnRenderUnit()
+ {
+ if (m_Effects == null || m_Effects.Count == 0)
+ return;
+
// 执行每个event的finish
foreach (var cb in m_InUseCommandBuffers)
{
@@ -148,9 +154,6 @@ public class UnitLensEffect : UnitComponent
CameraEvent ce = cb.Key.ToCameraEvent();
MainCamera.Instance.camera.RemoveCommandBuffer(ce, cb.Value);
}
- var temp = m_CachedCommandBuffers;
- m_CachedCommandBuffers = m_InUseCommandBuffers;
- m_InUseCommandBuffers = temp;
}
private void OnWillRenderObj(BodyPartRenderer renderer)
@@ -163,6 +166,12 @@ public class UnitLensEffect : UnitComponent
void PrepareCommandBuffers()
{
+ if(m_InUseCommandBuffers.Count != 0)
+ {
+ var temp = m_CachedCommandBuffers;
+ m_CachedCommandBuffers = m_InUseCommandBuffers;
+ m_InUseCommandBuffers = temp;
+ }
ERenderingEvent usedEvent = ERenderingEvent.None;
for (int i = 0; i < m_Effects.Count; ++i)
{
@@ -207,4 +216,9 @@ public class UnitLensEffect : UnitComponent
cb = null;
}
+ public void AddEffect(LensEffectBase effect)
+ {
+ m_Effects.Add(effect);
+ }
+
}