You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

91 lines
2.7 KiB

using System;
using UnityEngine;
namespace Skill_V2
{
[Serializable]
public struct Skill_V2Property
{
public uint id;
public float defaultSkillCoolTime;
}
public class Skill : Entity
{
[SerializeField] Skill_V2Property property;
[SerializeField] StateHandler stateHandler;
[SerializeField] SkillState[] sequences;
Entity caster;
int currentSequenceIndex = -1;
float elapsedCoolTime;
public Skill_V2Property Property => property;
public SkillState CurrentSequence => currentSequenceIndex >= 0 ? sequences[currentSequenceIndex] : null;
public bool IsInCoolTime => elapsedCoolTime < property.defaultSkillCoolTime;
public float CoolTimeRemainTime => Mathf.Clamp(property.defaultSkillCoolTime - elapsedCoolTime, 0, property.defaultSkillCoolTime);
public float ElapsedCoolTime => Mathf.Clamp(elapsedCoolTime, 0, property.defaultSkillCoolTime);
public float ElapsedCoolTimeRate { get; private set; }
private void Awake()
{
for (int i = 0; i < sequences.Length; ++i)
{
sequences[i].SetOwner(this);
}
}
private void Update()
{
if (CurrentSequence != null && CurrentSequence.IsDone)
{
currentSequenceIndex++;
if (currentSequenceIndex < sequences.Length)
{
stateHandler.ChangeState(sequences[currentSequenceIndex]);
}
else
{
currentSequenceIndex = -1;
stateHandler.ChangeState(null);
caster = null;
gameObject.SetActive(false);
}
}
}
public void UpdateSkillCoolTime()
{
if (!IsInCoolTime) return;
elapsedCoolTime += Time.fixedUnscaledDeltaTime;
ElapsedCoolTimeRate = Mathf.Clamp01(elapsedCoolTime / property.defaultSkillCoolTime);
}
public void Cast(Entity caster)
{
this.caster = caster;
currentSequenceIndex = 0;
transform.position = caster.CenterPivot;
ChangeLookDirection(caster.LookDirection);
gameObject.SetActive(true);
stateHandler.ChangeState(CurrentSequence);
}
public void StartCoolTime()
{
elapsedCoolTime = 0f;
}
public void Stop()
{
CurrentSequence?.Stop();
currentSequenceIndex = -1;
stateHandler?.ChangeState(null);
caster = null;
gameObject.SetActive(false);
}
}
}