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

87 lines
2.5 KiB
C#
Raw Normal View History

2024-10-19 03:04:15 +08:00
using System;
2024-10-23 18:46:37 +08:00
using Framework.GamePool.manager;
2024-10-19 03:04:15 +08:00
using Framework.Timer;
2024-10-23 18:46:37 +08:00
using Sirenix.Utilities;
2024-10-19 03:04:15 +08:00
using UnityEngine;
namespace Game.Component.SceneProp
{
/// <summary>
/// 所有交互道具基类
/// </summary>
public class BaseProp : MonoBehaviour
{
2024-10-23 18:46:37 +08:00
[SerializeField, Header ("触发特效")] private string effectPoolPath;
2024-10-19 03:04:15 +08:00
// 间隔cd
2024-10-23 18:46:37 +08:00
[SerializeField , Header ("间隔cd")] private float _invalidTime = 0f;
2024-10-19 03:04:15 +08:00
[SerializeField] protected bool HasOnce = true;
2024-10-23 18:46:37 +08:00
private TimeHandler _timeHandler;
2024-10-19 03:04:15 +08:00
protected bool isReady => this._timeHandler == null || this._timeHandler.IsDone;
2024-10-23 14:56:16 +08:00
public void ResetProp ()
{
this.gameObject.SetActive (true);
RefreshInvalidTime ();
}
2024-10-19 03:04:15 +08:00
protected virtual void OnTriggerEnter2D (Collider2D other)
{
if (other.gameObject.CompareTag ("Player"))
{
if (isReady)
{
var entity = other.gameObject.GetComponent<PlayerEntity> ();
2024-10-23 18:46:37 +08:00
if (!this.effectPoolPath.IsNullOrWhitespace ())
{
var transform1 = this.transform;
GamePoolManager.Instance.InstantiatePoolObject<PropEffect_PoolObject> (this.effectPoolPath).transform.position
= transform1.position;
}
2024-10-19 03:04:15 +08:00
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;
}
}
}