2024-10-21 17:02:25 +08:00
|
|
|
|
using System;
|
2024-10-27 17:14:19 +08:00
|
|
|
|
using Framework.GamePool.manager;
|
2024-10-21 17:02:25 +08:00
|
|
|
|
using Framework.Timer;
|
2024-10-19 03:04:15 +08:00
|
|
|
|
using Framework.Utils.Extend;
|
2024-10-21 17:02:25 +08:00
|
|
|
|
using Game.EventDefine;
|
2024-10-27 17:14:19 +08:00
|
|
|
|
using Sirenix.Utilities;
|
2024-10-16 16:43:53 +08:00
|
|
|
|
using UnityEngine;
|
2024-10-16 00:03:41 +08:00
|
|
|
|
|
|
|
|
|
|
namespace Game.Component
|
|
|
|
|
|
{
|
|
|
|
|
|
public class PlayerEntity : MonoBehaviour
|
|
|
|
|
|
{
|
2024-10-19 03:04:15 +08:00
|
|
|
|
public float speed = 10;
|
2024-10-16 16:43:53 +08:00
|
|
|
|
public Rigidbody2D rigidbody2D;
|
2024-10-27 17:14:19 +08:00
|
|
|
|
public string deadEffect;
|
|
|
|
|
|
|
2024-10-19 03:04:15 +08:00
|
|
|
|
private float speedBuffOffset;
|
|
|
|
|
|
private TimeHandler speedBuffTimer;
|
2024-10-27 17:14:19 +08:00
|
|
|
|
|
2024-10-19 03:04:15 +08:00
|
|
|
|
|
2024-10-23 14:56:16 +08:00
|
|
|
|
public float CurSpeed => MapContent.Instance.MoveGlobalOffset * this.speed *
|
2024-10-19 03:04:15 +08:00
|
|
|
|
(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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-16 00:03:41 +08:00
|
|
|
|
public void OnMove (Vector2 vector)
|
|
|
|
|
|
{
|
2024-10-21 22:29:53 +08:00
|
|
|
|
|
2024-10-16 16:43:53 +08:00
|
|
|
|
var t = this.transform;
|
|
|
|
|
|
// 获取前方方向的世界坐标
|
2024-10-19 03:04:15 +08:00
|
|
|
|
Vector3 forward = (Vector3)vector;
|
2024-10-16 16:43:53 +08:00
|
|
|
|
//根据遥感向量获取一个0,1的移动速度系数
|
2024-10-27 17:06:07 +08:00
|
|
|
|
float speedOffset = forward.magnitude;
|
|
|
|
|
|
Quaternion targetRotation = Quaternion.FromToRotation (Vector3.up , forward.normalized);
|
|
|
|
|
|
var targetRotationEulerAngles = targetRotation.eulerAngles;
|
|
|
|
|
|
targetRotationEulerAngles = new Vector3 (0 , 0 , targetRotationEulerAngles.z);
|
|
|
|
|
|
transform.rotation = Quaternion.Euler (targetRotationEulerAngles);
|
2024-10-16 16:43:53 +08:00
|
|
|
|
// Debug.DrawLine (transform.position , transform.position + forward , Color.magenta);
|
2024-10-19 03:04:15 +08:00
|
|
|
|
this.transform.Translate ( Vector3.up * speedOffset * CurSpeed * Time.deltaTime);
|
2024-10-17 00:46:27 +08:00
|
|
|
|
// this.rigidbody2D.MovePosition (t.position + ((Vector3)vector * speed * Time.deltaTime));
|
2024-10-16 16:43:53 +08:00
|
|
|
|
// Vector3 v = target.position - transform.position;
|
|
|
|
|
|
// v.z = 0; // 确保向量在2D平面上
|
|
|
|
|
|
// float angle = Vector3.SignedAngle(Vector3.up, v, Vector3.forward);
|
|
|
|
|
|
// Quaternion rotation = Quaternion.Euler(0, 0, angle);
|
|
|
|
|
|
t.position = t.position.SetZ (0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnMoveEnd ()
|
|
|
|
|
|
{
|
|
|
|
|
|
this.transform.rotation = Quaternion.Euler (0 , 0 , this.transform.rotation.eulerAngles.z);
|
2024-10-16 00:03:41 +08:00
|
|
|
|
}
|
2024-10-21 16:20:37 +08:00
|
|
|
|
|
|
|
|
|
|
public void RefreshInit ()
|
|
|
|
|
|
{
|
|
|
|
|
|
this.speedBuffTimer?.Kill ();
|
|
|
|
|
|
this.speedBuffTimer = null;
|
|
|
|
|
|
this.speedBuffOffset = 0;
|
|
|
|
|
|
//主角出生初始化
|
|
|
|
|
|
}
|
2024-10-21 17:02:25 +08:00
|
|
|
|
|
|
|
|
|
|
private void OnTriggerEnter2D (Collider2D other)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (other.CompareTag ("Enemy"))
|
|
|
|
|
|
{
|
2024-10-27 17:14:19 +08:00
|
|
|
|
if (!this.deadEffect.IsNullOrWhitespace ())
|
|
|
|
|
|
{
|
|
|
|
|
|
this.gameObject.SetActive (false);
|
|
|
|
|
|
var transform1 = this.transform;
|
|
|
|
|
|
GamePoolManager.Instance.InstantiatePoolObject<PropEffect_PoolObject> (this.deadEffect).transform.position
|
|
|
|
|
|
= transform1.position;
|
|
|
|
|
|
}
|
2024-10-21 17:02:25 +08:00
|
|
|
|
//死亡特效
|
|
|
|
|
|
GameEventDefine.ChangeGameFsm.SendMessage (GameState.FieldGame);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-10-16 00:03:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|