Files
beyond/Assets/Scripts/Healing/HealAnimatorBase.cs
2024-11-20 15:21:28 +01:00

96 lines
2.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using Invector;
using Invector.vCharacterController;
using Sirenix.OdinInspector;
using UnityEngine;
namespace Beyond
{
[RequireComponent(typeof(vIHealthController))]
[RequireComponent(typeof(QuestObject))]
public class HealAnimatorBase : MonoBehaviour
{
[SerializeField] protected Renderer m_renderer;
protected Material m_material;
public float m_healTime = 2f;
public Ease m_easeType = Ease.InCubic;
protected QuestObject m_questObject;
protected vIHealthController m_healthController;
protected v_SpriteHealth m_spriteBar;
//protected bTriggerGenericAction m_trigger;
protected virtual void Init()
{
if (m_renderer == null)
m_renderer = GetComponent<MeshRenderer>();
if (m_renderer == null)
{
Debug.LogError("No renderer found!", this);
return;
}
m_material = m_renderer.material;
m_healthController = GetComponent<vIHealthController>();
m_spriteBar = gameObject.GetComponentInChildren<v_SpriteHealth>();
m_questObject = GetComponent<QuestObject>();
//m_trigger = GetComponent<bTriggerGenericAction>();
//m_trigger.OnPressActionInput.AddListener(Heal);
}
/// <summary>
/// Reveals healthbar
/// </summary>
public virtual void Reveal()
{
if (m_spriteBar)
m_spriteBar.gameObject.SetActive(true);
if (m_questObject)
{
m_questObject.enabled = true;
}
}
protected virtual void Start()
{
if (m_spriteBar)
m_spriteBar.gameObject.SetActive(false);
if (m_questObject)
{
m_questObject.SetAlpha(0f);
m_questObject.enabled = false;
}
}
protected virtual void Awake()
{
Init();
}
[Button]
public virtual void Heal()
{
if (m_material == null)
{
Init();
}
DOTween.Kill(m_material);
if (m_questObject)
{
m_questObject.SetAlpha(0f);
m_questObject.enabled = false;
}
m_healthController.ResetHealth();
}
[Button]
public virtual void Unheal()
{
if (m_material == null)
{
Init();
}
DOTween.Kill(m_material);
}
}
}