You've already forked taptap2024_GJ_chidouren
增加场景道具
This commit is contained in:
71
Assets/Scripts/Game/Component/SceneProp/BaseProp.cs
Normal file
71
Assets/Scripts/Game/Component/SceneProp/BaseProp.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user