You've already forked taptap2024_GJ_chidouren
增加场景道具
This commit is contained in:
@@ -34,6 +34,9 @@ namespace Game.Component
|
||||
[Header ("攻击移动速度系数"), Range (0, 1)] public float AttackSpeedOffset = 1;
|
||||
[Header ("速度变化系数&插值t")] public float SpeedChangeT = 0.5f;
|
||||
|
||||
private float _expSpeedOffset; //额外速度系数
|
||||
private TimeHandler _expTimeHandler; //额外速度计时器
|
||||
|
||||
private FsmData _fsmData;
|
||||
private float _curAttackingTime;
|
||||
private float _curAttackCDTime;
|
||||
@@ -121,7 +124,7 @@ namespace Game.Component
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//特殊情况 ,如果值为-1 ,表示不限制
|
||||
//x如果为-1
|
||||
if (this.ActiveArea.x.Compare (-1))
|
||||
@@ -134,7 +137,7 @@ namespace Game.Component
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//y如果为-1
|
||||
if (this.ActiveArea.y.Compare (-1))
|
||||
{
|
||||
@@ -143,6 +146,7 @@ namespace Game.Component
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -161,7 +165,13 @@ namespace Game.Component
|
||||
|
||||
public bool HasRunaway { get; private set; } = false;
|
||||
|
||||
public float CurMoveSpeed => this._curMoveSpeedOffset * this.MaxMoveSpeed;
|
||||
public float CurMoveSpeed => this._curMoveSpeedOffset * (this.MaxMoveSpeed *
|
||||
(1 +
|
||||
( this._expTimeHandler?.IsPlaying ?? false
|
||||
? (1 - this._expTimeHandler.CurProgress) * this._expSpeedOffset
|
||||
: 0f)
|
||||
)
|
||||
);
|
||||
|
||||
private void ResetState ()
|
||||
{
|
||||
@@ -190,6 +200,7 @@ namespace Game.Component
|
||||
|
||||
private void OnDisable ()
|
||||
{
|
||||
this._expTimeHandler?.Kill ();
|
||||
GameUpdateMgr.Instance.RemoveUpdater (DoUpdate);
|
||||
}
|
||||
|
||||
@@ -274,6 +285,14 @@ namespace Game.Component
|
||||
#endregion
|
||||
|
||||
|
||||
public void AddSpeedBuff (float duration , float offset)
|
||||
{
|
||||
this._expSpeedOffset = offset;
|
||||
this._expTimeHandler?.Kill ();
|
||||
this._expTimeHandler = GameUpdateMgr.Instance.CreateTimer (duration , null);
|
||||
|
||||
}
|
||||
|
||||
public void EndAttack ()
|
||||
{
|
||||
this._hasAtkState = false;
|
||||
|
||||
@@ -22,5 +22,7 @@ namespace Game.Component
|
||||
{
|
||||
this.PlayerPosition = PlayerEntity.transform.position;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,38 @@
|
||||
using Framework.Utils.Extend;
|
||||
using Framework.Timer;
|
||||
using Framework.Utils.Extend;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.Component
|
||||
{
|
||||
public class PlayerEntity : MonoBehaviour
|
||||
{
|
||||
public float speed = 10;
|
||||
public float speed = 10;
|
||||
public Rigidbody2D rigidbody2D;
|
||||
|
||||
private float speedBuffOffset;
|
||||
private TimeHandler speedBuffTimer;
|
||||
|
||||
public float CurSpeed => this.speed *
|
||||
(1 + (this.speedBuffTimer?.IsPlaying ?? false ? this.speedBuffOffset * (1 - this.speedBuffTimer.CurProgress) : 0));
|
||||
|
||||
public void AddSpeedBuff (float duration = 3 , float offset = 0.5f)
|
||||
{
|
||||
this.speedBuffOffset = offset;
|
||||
this.speedBuffTimer?.Kill ();
|
||||
this.speedBuffTimer = GameUpdateMgr.Instance.CreateTimer (duration , null);
|
||||
}
|
||||
|
||||
public void OnMove (Vector2 vector)
|
||||
{
|
||||
var t = this.transform;
|
||||
// 获取前方方向的世界坐标
|
||||
Vector3 forward = (Vector3)vector;
|
||||
Vector3 forward = (Vector3)vector;
|
||||
//根据遥感向量获取一个0,1的移动速度系数
|
||||
float speedOffset = forward.magnitude;
|
||||
float speedOffset = forward.magnitude;
|
||||
Quaternion targetRotation = Quaternion.FromToRotation (Vector3.up , forward.normalized);
|
||||
transform.rotation = Quaternion.Lerp (transform.rotation , targetRotation , 0.25f);
|
||||
// Debug.DrawLine (transform.position , transform.position + forward , Color.magenta);
|
||||
this.transform.Translate ( Vector3.up * speedOffset * speed * Time.deltaTime);
|
||||
this.transform.Translate ( Vector3.up * speedOffset * CurSpeed * Time.deltaTime);
|
||||
// this.rigidbody2D.MovePosition (t.position + ((Vector3)vector * speed * Time.deltaTime));
|
||||
// Vector3 v = target.position - transform.position;
|
||||
// v.z = 0; // 确保向量在2D平面上
|
||||
|
||||
3
Assets/Scripts/Game/Component/SceneProp.meta
Normal file
3
Assets/Scripts/Game/Component/SceneProp.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7b0fc1611fe48ccb8edeef198cd786d
|
||||
timeCreated: 1729238675
|
||||
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