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.
89 lines
2.5 KiB
89 lines
2.5 KiB
using System;
|
|
using UnityEngine;
|
|
|
|
using Spine.Unity;
|
|
|
|
[Serializable]
|
|
public struct IVMateProperty
|
|
{
|
|
public uint id;
|
|
public float defaultSkillCoolTime;
|
|
public float defaultMoveSpeed;
|
|
}
|
|
|
|
public class IVMate : MonoBehaviour
|
|
{
|
|
[SerializeField] IVMateProperty property;
|
|
[SerializeField] SkeletonAnimation skeletonAnimation;
|
|
[SerializeField] StateHandler stateHandler;
|
|
|
|
float elapsedCoolTime;
|
|
|
|
public IVMateProperty Property => property;
|
|
public SkeletonAnimation SkeletonAnimation => skeletonAnimation;
|
|
|
|
public float ElapsedCoolTimeRate { get; private set; }
|
|
public bool IsAvailableSkill => elapsedCoolTime >= property.defaultSkillCoolTime;
|
|
public bool IsSafeToCallUseSkill => stateHandler.CurrentState is IVMateIdleState;
|
|
public Vector2 LookDirection { get; private set; }
|
|
|
|
public void UpdateSkillCoolTime()
|
|
{
|
|
if (elapsedCoolTime >= property.defaultSkillCoolTime) return;
|
|
elapsedCoolTime += Time.fixedUnscaledDeltaTime;
|
|
ElapsedCoolTimeRate = Mathf.Clamp01(elapsedCoolTime / property.defaultSkillCoolTime);
|
|
}
|
|
|
|
public void Spawn(IVCharacter player, Vector2 lookDir, Transform spawnPosition = null)
|
|
{
|
|
elapsedCoolTime = 0f;
|
|
|
|
if(spawnPosition != null)
|
|
{
|
|
transform.position = spawnPosition.position;
|
|
}
|
|
else
|
|
{
|
|
var rnd = UnityEngine.Random.insideUnitCircle * GameProperty.Instance.DistFromPlayerWhenFirstMateSpawn;
|
|
transform.position = player.transform.position + new Vector3(rnd.x, rnd.y, 0f);
|
|
}
|
|
|
|
ChangeLookDirection(lookDir);
|
|
|
|
gameObject.SetActive(true);
|
|
|
|
stateHandler?.ChangeState(new IVMateAppearState(this, player));
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
stateHandler?.ChangeState(new IVMateDisappearState(this, () => gameObject.SetActive(false)));
|
|
}
|
|
|
|
public void UseSkill()
|
|
{
|
|
if (!IsSafeToCallUseSkill || !IsAvailableSkill) return;
|
|
elapsedCoolTime = 0f;
|
|
|
|
// TODO: change state to use skill
|
|
}
|
|
|
|
public void ChangeLookDirection(Transform lookTarget)
|
|
{
|
|
ChangeLookDirection((Vector2)lookTarget.position - (Vector2)transform.position);
|
|
}
|
|
|
|
public void ChangeLookDirection(Vector2 lookDirection)
|
|
{
|
|
if (lookDirection.x >= 0)
|
|
{
|
|
LookDirection = Vector2.right;
|
|
transform.rotation = Quaternion.Euler(Vector3.zero);
|
|
}
|
|
else
|
|
{
|
|
LookDirection = Vector2.left;
|
|
transform.rotation = Quaternion.Euler(Global.V3_RotRev);
|
|
}
|
|
}
|
|
}
|