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;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Game/Component/SceneProp/BaseProp.cs.meta
Normal file
3
Assets/Scripts/Game/Component/SceneProp/BaseProp.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea0309bfd995417689f04cf447916cbf
|
||||
timeCreated: 1729238685
|
||||
27
Assets/Scripts/Game/Component/SceneProp/BlueProp.cs
Normal file
27
Assets/Scripts/Game/Component/SceneProp/BlueProp.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.Component.SceneProp
|
||||
{
|
||||
public class BlueProp : BaseProp
|
||||
{
|
||||
[SerializeField ,Header ("加速时长")] private float _duration = 3.0f;
|
||||
[SerializeField ,Header ("额外加速幅度")] private float _speedOffset = 0.5f;
|
||||
|
||||
protected override void OnTrigger (PlayerEntity entity)
|
||||
{
|
||||
entity.AddSpeedBuff (this._duration , this._speedOffset);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected void OnDrawGizmos ()
|
||||
{
|
||||
//绘制一个蓝色圆形
|
||||
Gizmos.color = Color.blue;
|
||||
Gizmos.DrawWireSphere (transform.position , 0.5f);
|
||||
//文字提示“加速”
|
||||
UnityEditor.Handles.Label (transform.position , "加速");
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Game/Component/SceneProp/BlueProp.cs.meta
Normal file
3
Assets/Scripts/Game/Component/SceneProp/BlueProp.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3dd24663aeb41cab20ae2e84799c6bb
|
||||
timeCreated: 1729244994
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Game.Component.SceneProp
|
||||
{
|
||||
public class ColliderTriggerAction : MonoBehaviour
|
||||
{
|
||||
[SerializeField] public UnityEvent<Collider2D> OnTriggerEnterAction;
|
||||
|
||||
private void OnTriggerEnter2D (Collider2D other)
|
||||
{
|
||||
OnTriggerEnterAction?.Invoke(other);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35f96c77f18c4e579c04ff086160bb57
|
||||
timeCreated: 1729272887
|
||||
75
Assets/Scripts/Game/Component/SceneProp/GreenProp.cs
Normal file
75
Assets/Scripts/Game/Component/SceneProp/GreenProp.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.Component.SceneProp
|
||||
{
|
||||
public class GreenProp : BaseProp
|
||||
{
|
||||
[SerializeField] private ColliderTriggerAction _spawn;
|
||||
[SerializeField, Header ("持续时长")] private float _skillDuration;
|
||||
|
||||
[SerializeField, Header ("速度buff 持续时间")]
|
||||
private float _buffDuration;
|
||||
|
||||
[SerializeField, Header ("速度buff额外系数")]
|
||||
private float _buffSpeedOffset;
|
||||
|
||||
protected override void OnTriggerEnter2D (Collider2D other)
|
||||
{
|
||||
if (other.gameObject.CompareTag ("Player"))
|
||||
{
|
||||
if (this.isReady)
|
||||
{
|
||||
var entity = other.gameObject.GetComponent<PlayerEntity> ();
|
||||
this.OnTrigger (entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override async void OnTrigger (PlayerEntity entity)
|
||||
{
|
||||
this._spawn.gameObject.SetActive (true);
|
||||
await UniTask.Delay ( (int)(this._skillDuration * 1000));
|
||||
this._spawn.gameObject.SetActive (false);
|
||||
if (HasOnce)
|
||||
{
|
||||
this.gameObject.SetActive (false);
|
||||
}
|
||||
else
|
||||
{
|
||||
RefreshInvalidTime ();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnReady ()
|
||||
{
|
||||
this._spawn.gameObject.SetActive (false);
|
||||
}
|
||||
|
||||
public void OnTriggerEnterAction (Collider2D other)
|
||||
{
|
||||
if (other.gameObject.CompareTag ("Enemy"))
|
||||
{
|
||||
var entity = other.gameObject.GetComponent<EnemyEntity> ();
|
||||
OnSubEnemySpeed (entity , this._buffSpeedOffset , this._buffDuration);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void OnSubEnemySpeed (EnemyEntity entity , float speedOffset , float duration)
|
||||
{
|
||||
entity.AddSpeedBuff (duration , speedOffset);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
protected void OnDrawGizmos ()
|
||||
{
|
||||
//减速球, 绿色标签
|
||||
Gizmos.color = Color.green;
|
||||
Gizmos.DrawWireSphere (transform.position , 0.5f);
|
||||
UnityEditor.Handles.Label (transform.position, "减速球");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3a143df6abc45dc8a49808d637d70f7
|
||||
timeCreated: 1729245078
|
||||
18
Assets/Scripts/Game/Component/SceneProp/NormalLightProp.cs
Normal file
18
Assets/Scripts/Game/Component/SceneProp/NormalLightProp.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Game.EventDefine;
|
||||
|
||||
namespace Game.Component.SceneProp
|
||||
{
|
||||
public class NormalLightProp : BaseProp
|
||||
{
|
||||
protected override void OnReady ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void OnTrigger (PlayerEntity entity)
|
||||
{
|
||||
GameEventDefine.OverlyCoin.SendMessage (1);
|
||||
//此处可以增加交互反馈
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b0556f3ae8f4cdd9e0f9dfc239b5e5a
|
||||
timeCreated: 1729244345
|
||||
73
Assets/Scripts/Game/Component/SceneProp/RedProp.cs
Normal file
73
Assets/Scripts/Game/Component/SceneProp/RedProp.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.Component.SceneProp
|
||||
{
|
||||
public class RedProp : BaseProp
|
||||
{
|
||||
[SerializeField, Header ("施法时间")] private float _actionDelay = 0.5f;
|
||||
[SerializeField, Header ("a区传送点")] private Transform _a_pos;
|
||||
[SerializeField, Header ( "b区传送点")] private Transform _b_pos;
|
||||
|
||||
protected override void OnTrigger (PlayerEntity entity)
|
||||
{
|
||||
//从a点到b
|
||||
this.ToPos (entity, this._a_pos);
|
||||
}
|
||||
|
||||
public void OnTriggerEnterAction (Collider2D other)
|
||||
{
|
||||
if (other.gameObject.CompareTag ("Player"))
|
||||
{
|
||||
if (isReady)
|
||||
{
|
||||
var player = other.gameObject.GetComponent<PlayerEntity> ();
|
||||
this.ToPos (player , this._b_pos);
|
||||
if (HasOnce)
|
||||
{
|
||||
this.gameObject.SetActive (false);
|
||||
}
|
||||
else
|
||||
{
|
||||
RefreshInvalidTime ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async UniTask ToPos (PlayerEntity playerEntity, Transform target)
|
||||
{
|
||||
//消失动画
|
||||
playerEntity.gameObject.SetActive (false);
|
||||
var playerEntityTransform = playerEntity.transform;
|
||||
playerEntityTransform.position = target.position;
|
||||
playerEntityTransform.rotation = target.rotation;
|
||||
await UniTask.Delay ((int)(this._actionDelay * 1000));
|
||||
playerEntity.gameObject.SetActive (true);
|
||||
//出场动画
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
private void OnDrawGizmos ()
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._a_pos != null)
|
||||
{
|
||||
Gizmos.color = new Color (1f, 0.38f, 0.13f);
|
||||
Gizmos.DrawWireSphere (this._a_pos.position, 0.2f);
|
||||
}
|
||||
|
||||
if (this._b_pos != null)
|
||||
{
|
||||
Gizmos.color = new Color (0.2f, 0.4f, 1f);
|
||||
Gizmos.DrawWireSphere (this._b_pos.position, 0.2f);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Game/Component/SceneProp/RedProp.cs.meta
Normal file
3
Assets/Scripts/Game/Component/SceneProp/RedProp.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 360c9ffc49c94f4598e35b18b63a6c99
|
||||
timeCreated: 1729244985
|
||||
15
Assets/Scripts/Game/Component/SceneProp/WhiteProp.cs
Normal file
15
Assets/Scripts/Game/Component/SceneProp/WhiteProp.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Game.EventDefine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.Component.SceneProp
|
||||
{
|
||||
public class WhiteProp : BaseProp
|
||||
{
|
||||
[SerializeField] private float _duration = 1.5f;
|
||||
protected override void OnTrigger (PlayerEntity entity)
|
||||
{
|
||||
Debug.Log ("wtf?");
|
||||
GameEventDefine.GlobalRunaway.SendMessage (this._duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 39738f45a609446db7e107b4fd98b734
|
||||
timeCreated: 1729244810
|
||||
Reference in New Issue
Block a user