86 lines
2.8 KiB
C#
86 lines
2.8 KiB
C#
using System;
|
|
using Lean.Pool;
|
|
using UnityEngine;
|
|
|
|
namespace Cielonos.MainGame
|
|
{
|
|
public partial class TimeSubmodule : AttackAreaSubmoduleBase
|
|
{
|
|
public float lifeTime;
|
|
public float delayTime;
|
|
public float enablingTime;
|
|
public float remainingEnableTime;
|
|
public float remainingLifeTime;
|
|
public Action enableAction;
|
|
public Action timeOutAction;
|
|
|
|
public TimeSubmodule(AttackAreaBase attackArea, float lifeTime, Action timeOutAction = null) : base(attackArea)
|
|
{
|
|
this.isEnabling = true;
|
|
this.lifeTime = lifeTime;
|
|
this.remainingLifeTime = lifeTime;
|
|
this.enablingTime = 0;
|
|
this.remainingEnableTime = lifeTime * 0.25f;
|
|
this.timeOutAction = timeOutAction ?? (() => { LeanPool.Despawn(attackArea.topParent); });
|
|
}
|
|
|
|
public TimeSubmodule(AttackAreaBase attackArea, float lifeTime, float enableTime, float enableDelay, Action enableAction, Action timeOutAction) : base(attackArea)
|
|
{
|
|
this.isEnabling = true;
|
|
this.lifeTime = lifeTime;
|
|
this.delayTime = enableDelay;
|
|
this.attackArea.isEnabling = enableDelay <= 0;
|
|
this.timeOutAction = timeOutAction ?? (() => { LeanPool.Despawn(attackArea.topParent); });
|
|
|
|
if (this.attackArea.isEnabling)
|
|
{
|
|
enableAction?.Invoke();
|
|
}
|
|
this.remainingLifeTime = lifeTime;
|
|
this.enablingTime = 0;
|
|
this.remainingEnableTime = enableTime;
|
|
this.enableAction = enableAction;
|
|
}
|
|
}
|
|
|
|
public partial class TimeSubmodule
|
|
{
|
|
public void Update()
|
|
{
|
|
if (!isEnabling) return;
|
|
|
|
if (delayTime > 0)
|
|
{
|
|
delayTime -= Time.deltaTime; //attackArea.creator.selfTimeModule.EntityDeltaTime;
|
|
return;
|
|
}
|
|
|
|
if (!attackArea.isEnabling)
|
|
{
|
|
attackArea.isEnabling = true;
|
|
enableAction?.Invoke();
|
|
}
|
|
|
|
enablingTime += Time.deltaTime; //attackArea.creator.selfTimeModule.EntityDeltaTime;
|
|
remainingLifeTime -= Time.deltaTime; //attackArea.creator.selfTimeModule.EntityDeltaTime;
|
|
remainingEnableTime -= Time.deltaTime; //attackArea.creator.selfTimeModule.EntityDeltaTime;
|
|
|
|
if (remainingLifeTime <= 0)
|
|
{
|
|
this.isEnabling = false;
|
|
timeOutAction?.Invoke();
|
|
}
|
|
|
|
if (remainingEnableTime <= 0)
|
|
{
|
|
attackArea.isEnabling = false;
|
|
}
|
|
}
|
|
|
|
public void ModifyLifeTime(float modifyValue)
|
|
{
|
|
lifeTime += modifyValue;
|
|
remainingLifeTime += modifyValue;
|
|
}
|
|
}
|
|
} |