Files
taptap2024_GJ_chidouren/Assets/Scripts/Game/Component/SceneProp/BaseProp.cs

87 lines
2.5 KiB
C#

using System;
using Framework.GamePool.manager;
using Framework.Timer;
using Sirenix.Utilities;
using UnityEngine;
namespace Game.Component.SceneProp
{
/// <summary>
/// 所有交互道具基类
/// </summary>
public class BaseProp : MonoBehaviour
{
[SerializeField, Header ("触发特效")] protected string effectPoolPath;
// 间隔cd
[SerializeField , Header ("间隔cd")] private float _invalidTime = 0f;
[SerializeField] protected bool HasOnce = true;
private TimeHandler _timeHandler;
protected bool isReady => this._timeHandler == null || this._timeHandler.IsDone;
public void ResetProp ()
{
this.gameObject.SetActive (true);
RefreshInvalidTime ();
}
protected virtual void OnTriggerEnter2D (Collider2D other)
{
if (other.gameObject.CompareTag ("Player"))
{
if (isReady)
{
var entity = other.gameObject.GetComponent<PlayerEntity> ();
if (!this.effectPoolPath.IsNullOrWhitespace ())
{
var transform1 = this.transform;
GamePoolManager.Instance.InstantiatePoolObject<PropEffect_PoolObject> (this.effectPoolPath).transform.position
= transform1.position;
}
this.OnTrigger (entity);
if (HasOnce)
{
this.gameObject.SetActive (false);
}
else
{
RefreshInvalidTime ();
}
}
}
}
protected virtual void OnTrigger (PlayerEntity entity)
{
}
protected virtual void OnReady ()
{
}
protected void RefreshInvalidTime ()
{
if (this._invalidTime <= 0)
{
return;
}
this._timeHandler?.Kill ();
this._timeHandler = null;
this._timeHandler = GameUpdateMgr.Instance.CreateTimer (this._invalidTime, null);
}
private void OnEnable ()
{
OnReady ();
}
private void OnDisable ()
{
this._timeHandler?.Kill ();
this._timeHandler = null;
}
}
}