CapersProject/Assets/02.Scripts/Character/Enemy/Boss/GhostBarrel/GhostBarrel.cs

157 lines
4.8 KiB
C#
Raw Normal View History

using System.Collections;
using BlueWater.Items;
using BlueWater.Maps;
using Sirenix.OdinInspector;
using UnityEngine;
namespace BlueWater.Enemies.Bosses.GhostBarrel
{
public enum GhostBarrelSkill
{
None = 0,
}
public enum GhostBarrelSkin
{
}
public enum GhostBarrelAnimation
{
None = 0,
Empty,
Idle,
In,
Out
}
public class GhostBarrel : SpineBoss
{
// Variables
#region Variables
public GhostBarrelData GhostBarrelData { get; private set; }
public GhostBarrelMapController GhostBarrelMapController { get; private set; }
[Title("효과")]
[SerializeField]
private float _spawnDissolveTime = 2f;
[SerializeField]
private float _dieDissolveTime = 1f;
// Hashes
private static readonly int _dissolveValueHash = Shader.PropertyToID("_DissolveValue");
#endregion
// Unity events
#region Unity events
protected override void OnDestroy()
{
base.OnDestroy();
//BossHealthPoint.OnHealthChanged -= SummonMiniSandMole;
}
#endregion
// Initialize methods
#region Initialize methods
protected override void InitializeComponents()
{
base.InitializeComponents();
//SandMoleStatus = GetComponent<SandMoleStatus>();
GhostBarrelData = BossData as GhostBarrelData;
GhostBarrelMapController = MapManager.Instance.GhostBarrelMapController;
}
public override void Initialize()
{
StartCoroutine(InitializeCoroutine());
}
private IEnumerator InitializeCoroutine()
{
HitBoxCollider.enabled = false;
BossHealthPoint.Initialize(true, GhostBarrelData.MaxHealthPoint,
GhostBarrelData.DisplayName, GhostBarrelMapController.ParticleInstanceLocation);
BossSkillController.Initialize(BossData.SkillDataList);
SetMoveSpeed(GhostBarrelData.MoveSpeed);
StopMove();
SpineController.PlayAnimation(BoomBarrelAnimation.In.ToString(), false);
MaterialPropertyBlock.SetFloat(_dissolveValueHash, 0f);
MeshRenderer.SetPropertyBlock(MaterialPropertyBlock);
var elapsedTime = 0f;
while (elapsedTime <= _spawnDissolveTime)
{
if (CurrentHealthPoint == 0) yield break;
var value = Mathf.Lerp(0f, 1f, elapsedTime / _spawnDissolveTime);
MaterialPropertyBlock.SetFloat(_dissolveValueHash, value);
MeshRenderer.SetPropertyBlock(MaterialPropertyBlock);
elapsedTime += Time.deltaTime;
yield return null;
}
MaterialPropertyBlock.SetFloat(_dissolveValueHash, 1f);
MeshRenderer.SetPropertyBlock(MaterialPropertyBlock);
BehaviorTree.EnableBehavior();
HitBoxCollider.enabled = true;
}
#endregion
// Methods
#region Methods
protected override void Die()
{
StartCoroutine(DieCoroutine());
}
private IEnumerator DieCoroutine()
{
BossSkillController.StopAllCoroutine();
BehaviorTree.DisableBehavior();
StopMove();
HitBoxCollider.enabled = false;
if (Rigidbody)
{
Rigidbody.linearVelocity = Vector3.zero;
Rigidbody.isKinematic = true;
}
GhostBarrelMapController.ClearMap(gameObject);
// TODO : 죽는 애니메이션 추가
//SpineController.SetSkin(SandMoleSkin.Idle.ToString());
//var dieTrack = SpineController.PlayAnimation(SandMoleAnimation.Die.ToString(), false);
//await SpineController.WaitForAnimationCompletion(dieTrack);
MaterialPropertyBlock.SetFloat(_dissolveValueHash, 1f);
MeshRenderer.SetPropertyBlock(MaterialPropertyBlock);
var elapsedTime = 0f;
while (elapsedTime <= _dieDissolveTime)
{
var value = Mathf.Lerp(1f, 0f, elapsedTime / _dieDissolveTime);
MaterialPropertyBlock.SetFloat(_dissolveValueHash, value);
MeshRenderer.SetPropertyBlock(MaterialPropertyBlock);
elapsedTime += Time.deltaTime;
yield return null;
}
MaterialPropertyBlock.SetFloat(_dissolveValueHash, 0f);
MeshRenderer.SetPropertyBlock(MaterialPropertyBlock);
Destroy(gameObject);
}
#endregion
}
}