You've already forked taptap2024_GJ_chidouren
71 lines
1.9 KiB
C#
71 lines
1.9 KiB
C#
|
|
using System;
|
|||
|
|
using Framework.Timer;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
namespace Game.Component.SceneProp
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 所有交互道具基类
|
|||
|
|
/// </summary>
|
|||
|
|
public class BaseProp : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
// 间隔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;
|
|||
|
|
|
|||
|
|
|
|||
|
|
protected virtual void OnTriggerEnter2D (Collider2D other)
|
|||
|
|
{
|
|||
|
|
if (other.gameObject.CompareTag ("Player"))
|
|||
|
|
{
|
|||
|
|
if (isReady)
|
|||
|
|
{
|
|||
|
|
var entity = other.gameObject.GetComponent<PlayerEntity> ();
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|