feat():大改前的提交,这个版本保存了所有冗余的代码

This commit is contained in:
2025-10-17 15:10:19 +08:00
parent 668bfe12eb
commit 3d03c59dc3
68 changed files with 2045 additions and 159 deletions

View File

@@ -1,6 +1,6 @@
using Core;
using UnityEngine;
using Input;
using Script.Gameplay.Input;
namespace Gameplay.Player
{
@@ -10,34 +10,28 @@ namespace Gameplay.Player
/// </summary>
public class PlayerCameraController : MonoBehaviour
{
[Header("References")]
[Tooltip("角色根 Transform用于水平旋转yaw")]
[Header("References")] [Tooltip("角色根 Transform用于水平旋转yaw")]
public Transform playerBody;
[Tooltip("如果相机不是挂载在同一物体上,可以指定相机 Transform可选")]
public Transform cameraTransform;
[Header("Sensitivity & Invert")]
[Tooltip("鼠标灵敏度")]
[Range(0.01f, 1f)]
[Header("Sensitivity & Invert")] [Tooltip("鼠标灵敏度")] [Range(0.01f, 1f)]
public float mouseSensitivity = 0.2f;
[Tooltip("反转垂直轴")]
public bool invertY = false;
[Tooltip("反转垂直轴")] public bool invertY = false;
[Header("Vertical Limits")]
[Tooltip("向上最大仰角(度)")]
[Header("Vertical Limits")] [Tooltip("向上最大仰角(度)")]
public float maxUpAngle = 60f;
[Tooltip("向下最大俯角(度)")]
public float maxDownAngle = 60f;
[Header("Smoothing")]
public bool enableSmoothing = false;
[Tooltip("旋转平滑时间(秒)")]
public float smoothTime = 0.05f;
[Tooltip("向下最大俯角(度)")] public float maxDownAngle = 60f;
[Header("Smoothing")] public bool enableSmoothing = false;
[Tooltip("旋转平滑时间(秒)")] public float smoothTime = 0.05f;
// internal state
private float xRotation = 0f; // 垂直角pitch
private float yaw = 0f; // 水平角yaw
private float yaw = 0f; // 水平角yaw
private float smoothVelocityPitch = 0f;
private float smoothVelocityYaw = 0f;
@@ -50,7 +44,6 @@ namespace Gameplay.Player
Vector3 euler = cameraTransform.localEulerAngles;
xRotation = NormalizeAngle(euler.x);
yaw = NormalizeAngle(playerBody ? playerBody.eulerAngles.y : transform.eulerAngles.y);
}
void Update()
@@ -71,8 +64,10 @@ namespace Gameplay.Player
if (enableSmoothing)
{
float smoothPitch = Mathf.SmoothDampAngle(cameraTransform.localEulerAngles.x, xRotation, ref smoothVelocityPitch, smoothTime);
float smoothYaw = Mathf.SmoothDampAngle(playerBody ? playerBody.eulerAngles.y : transform.eulerAngles.y, yaw, ref smoothVelocityYaw, smoothTime);
float smoothPitch = Mathf.SmoothDampAngle(cameraTransform.localEulerAngles.x, xRotation,
ref smoothVelocityPitch, smoothTime);
float smoothYaw = Mathf.SmoothDampAngle(playerBody ? playerBody.eulerAngles.y : transform.eulerAngles.y,
yaw, ref smoothVelocityYaw, smoothTime);
cameraTransform.localRotation = Quaternion.Euler(smoothPitch, 0f, 0f);
if (playerBody)
@@ -97,5 +92,7 @@ namespace Gameplay.Player
angle = (angle + 180f) % 360f - 180f;
return angle;
}
}
}
}

View File

@@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using UnityEngine;
using Quaternion = UnityEngine.Quaternion;
using Vector3 = UnityEngine.Vector3;
namespace Gameplay.Player
{
public class PlayerCardsController : MonoBehaviour
{
[SerializeField] private float radius = 2f; // 卡牌围绕玩家旋转的半径
[SerializeField] private float rotationSpeed = 50f; // 卡牌旋转
[SerializeField] private float highOffset = 1f; // 卡牌高度偏移
public bool IsRotating = true; // 是否旋转卡牌
[SerializeField] private GameObject cardPrefab; // 卡牌预制体
public List<CardViewer> Cards;
private Transform playerTransform;
private void Update()
{
if (Cards != null)
{
//RotateCards();
}
}
// 生成卡牌实体
// 生成的卡牌实体围绕着玩家旋转
public void GenerateCards(List<Card> cards)
{
playerTransform = this.transform;
Cards = new List<CardViewer>();
for (int i = 0; i < cards.Count; i++)
{
float angle = i * (360f / cards.Count);
float rad = angle * Mathf.Deg2Rad;
Vector3 cardPosition = new Vector3(
playerTransform.position.x + radius * Mathf.Cos(rad),
playerTransform.position.y + highOffset,
playerTransform.position.z + radius * Mathf.Sin(rad)
);
GameObject cardObject = Instantiate(cardPrefab, cardPosition, Quaternion.identity);
Vector3 playerPosition = new Vector3(
playerTransform.position.x,
playerTransform.position.y + highOffset,
playerTransform.position.z
);
Cards[i].transform.LookAt(playerPosition);
CardViewer cardViewer = cardObject.GetComponent<CardViewer>();
cardViewer.SetCard(cards[i]);
Cards.Add(cardViewer);
}
}
// 旋转已经生成的卡牌实体
public void RotateCards()
{
if (!IsRotating) return;
for (int i = 0; i < Cards.Count; i++)
{
float angle = i * (360f / Cards.Count) + Time.time * rotationSpeed;
float rad = angle * Mathf.Deg2Rad;
Vector3 cardPosition = new Vector3(
playerTransform.position.x + radius * Mathf.Cos(rad),
playerTransform.position.y + highOffset,
playerTransform.position.z + radius * Mathf.Sin(rad)
);
Cards[i].transform.position = cardPosition;
Vector3 playerPosition = new Vector3(
playerTransform.position.x,
playerTransform.position.y + highOffset,
playerTransform.position.z
);
Cards[i].transform.LookAt(playerPosition);
// 卡牌绕着y轴旋转180度从而让卡牌正面朝向玩家
Cards[i].transform.Rotate(0, 180, 0);
}
}
public void StopRotatingCards()
{
IsRotating = false;
}
public void StartRotatingCards()
{
IsRotating = true;
}
// 删除卡牌实体
public void DeleteCards(CardViewer card)
{
Cards.Remove(card);
Destroy(card.gameObject);
}
public void ClearCards()
{
foreach (var card in Cards)
{
Destroy(card.gameObject);
}
Cards.Clear();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: cb0c79a8230343c29d902ad22e044d2b
timeCreated: 1760574485

View File

@@ -1,9 +0,0 @@
using UnityEngine;
namespace Gameplay.Player
{
public class PlayerConfig : MonoBehaviour
{
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 6ff9e093e80541dc93d1186499dbfd79
timeCreated: 1760498762

View File

@@ -2,7 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Gameplay;
using Share;
using Interface;
using UnityEngine;
using Core;
@@ -23,21 +23,25 @@ namespace Gameplay.Player
private PlayerMoveController playerMoveController;
private PlayerCameraController playerCameraController;
public PlayerCardsController playerCardsController;
private void Awake()
{
playerMoveController = GetComponent<PlayerMoveController>();
playerCameraController = GetComponent<PlayerCameraController>();
playerCardsController = GetComponent<PlayerCardsController>();
CurrentHealth = MaxHealth;
MyCardBook = new CardBook(cardBookData);
Cards = new List<Card>();
UIViewerControllerLocator.Instance.Register(this);
ControllerLocator.Instance.Register(this);
}
private void Start()
{
Cards.Add(CardLoader.GetCardByID(1));
Cards.Add(CardLoader.GetCardByID(2));
}
@@ -60,6 +64,8 @@ namespace Gameplay.Player
Debug.Log("Player StartCombat");
IsFlight = true;
playerMoveController.SetSpeed(0.5f);
playerCardsController.GenerateCards(Cards);
}
public void EndFlight()
@@ -67,6 +73,8 @@ namespace Gameplay.Player
Debug.Log("Player EndFlight");
IsFlight = false;
playerMoveController.ResetSpeed();
playerCardsController.ClearCards();
}
public bool HasCardsLeft()

View File

@@ -0,0 +1,86 @@
using UnityEngine;
using Interface;
using Script.Gameplay.Input;
namespace Gameplay.Player
{
public class PlayerEditController:MonoBehaviour
{
[SerializeField] private float interactRange = 15f;
[SerializeField] private LayerMask interactableLayer;
[SerializeField] private Camera playerCamera;
[SerializeField] private bool isDrawGizmos;
private IEditable currentTarget; // 射线命中的当前可编辑对象(用于按键交互)
private IEditable previousGazedTarget; // 上一次注视的对象(用于注视进入/离开事件)
private InputManager inputManager;
void Start()
{
inputManager = InputManager.Instance;
if (playerCamera == null)
playerCamera = GameObject.FindWithTag("MainCamera").GetComponent<Camera>();
inputManager.Input.Player.SwitchWatchMode.performed += ctx =>
{
if (currentTarget != null) currentTarget.BeginEdit();
};
}
void Update()
{
DetectInteractable();
}
void DetectInteractable()
{
if (playerCamera == null) return;
Ray ray = new Ray(playerCamera.transform.position, playerCamera.transform.forward);
if (Physics.Raycast(ray, out RaycastHit hit, interactRange, interactableLayer))
{
IEditable hitEditable = hit.collider.GetComponent<IEditable>();
// 如果命中对象与之前注视的不一样,触发进入/离开事件
if (hitEditable != previousGazedTarget)
{
if (previousGazedTarget != null)
{
previousGazedTarget.OnGazeExit(this);
}
if (hitEditable != null)
{
hitEditable.OnGazeEnter(this);
}
previousGazedTarget = hitEditable;
}
currentTarget = hitEditable;
}
else
{
// 没有命中时,如果之前有注视对象,触发离开
if (previousGazedTarget != null)
{
previousGazedTarget.OnGazeExit(this);
previousGazedTarget = null;
}
currentTarget = null;
}
}
void OnDrawGizmos()
{
if(!isDrawGizmos) return;
if (playerCamera == null) return;
Gizmos.color = Color.red;
Vector3 origin = playerCamera.transform.position;
Vector3 direction = playerCamera.transform.forward * interactRange;
Gizmos.DrawLine(origin, origin + direction);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 18842cb320964275a76e2d57bee62adf
timeCreated: 1760664958

View File

@@ -1,7 +1,7 @@
using UnityEngine;
using Share;
using Interface;
using System;
using Input;
using Script.Gameplay.Input;
namespace Gameplay.Player
{
@@ -10,44 +10,70 @@ namespace Gameplay.Player
[SerializeField] private float interactRange = 15f;
[SerializeField] private LayerMask interactableLayer;
[SerializeField] private Camera playerCamera;
[SerializeField] private bool isDrawGizmos;
private IInteractable currentTarget;
private IInteractable currentTarget; // 被射线命中的当前可交互对象(用于按键交互)
private IInteractable previousGazedTarget; // 上一次注视的对象(用于注视进入/离开事件)
void Start()
{
playerCamera = GameObject.FindWithTag("MainCamera").GetComponent<Camera>();
if (playerCamera == null)
playerCamera = GameObject.FindWithTag("MainCamera").GetComponent<Camera>();
var input = InputManager.Instance.Input;
input.Player.SwitchWatchMode.performed += ctx => currentTarget.Interact(this.gameObject);;
}
void Update()
{
DetectInteractable();
if (currentTarget != null && InputManager.Instance.InteractPressed)
{
currentTarget.Interact(this.gameObject);
}
}
void DetectInteractable()
{
if (playerCamera == null) return;
Ray ray = new Ray(playerCamera.transform.position, playerCamera.transform.forward);
if (Physics.Raycast(ray, out RaycastHit hit, interactRange, interactableLayer))
{
currentTarget = hit.collider.GetComponent<IInteractable>();
if (currentTarget != null)
IInteractable hitInteractable = hit.collider.GetComponent<IInteractable>();
// 如果命中对象与之前注视的不一样,触发进入/离开事件
if (hitInteractable != previousGazedTarget)
{
// 这里可以显示交互提示UI例如 “E - 开门”
Debug.Log(currentTarget.GetInteractPrompt());
if (previousGazedTarget != null)
{
previousGazedTarget.OnGazeExit(this.gameObject);
}
if (hitInteractable != null)
{
hitInteractable.OnGazeEnter(this.gameObject);
// 这里可以显示交互提示UI例如 “E - 开门”
Debug.Log(hitInteractable.GetInteractPrompt());
}
previousGazedTarget = hitInteractable;
}
currentTarget = hitInteractable;
}
else
{
// 没有命中时,如果之前有注视对象,触发离开
if (previousGazedTarget != null)
{
previousGazedTarget.OnGazeExit(this.gameObject);
previousGazedTarget = null;
}
currentTarget = null;
}
}
void OnDrawGizmos()
{
if (isDrawGizmos) return;
if (playerCamera == null) return;
Gizmos.color = Color.green;
Vector3 origin = playerCamera.transform.position;

View File

@@ -1,6 +1,6 @@
using System;
using Core;
using Input;
using Script.Gameplay.Input;
using Map;
using UnityEngine;

View File

@@ -0,0 +1,72 @@
using System;
using Script.Gameplay.Input;
using UnityEngine;
namespace Gameplay.Player
{
public enum WatchMode
{
Normal,
Inside,
Outside
}
public class PlayerWatchModeSwitcher : MonoBehaviour
{
[SerializeField] private Camera cam;
private InputManager inputManager;
private WatchMode currentMode = WatchMode.Normal;
private void Start()
{
inputManager = InputManager.Instance;
SetWatchMode(currentMode);
var input = inputManager.Input;
input.Player.SwitchWatchMode.performed += ctx =>
{
currentMode = (WatchMode)(((int)currentMode + 1) % 3);
SetWatchMode(currentMode);
};;
}
public void SetWatchMode(WatchMode mode)
{
currentMode = mode;
SwitchWatchMode(mode);
}
// 实现按Tap键实现在WatchMode 3个模式切换并通过SwitchWatchMode设置正确的相机模式
private void SwitchWatchMode(WatchMode watchMode)
{
switch (watchMode)
{
case WatchMode.Normal:
SetSeeLines(false);
break;
case WatchMode.Inside:
SetSeeLines(false);
break;
case WatchMode.Outside:
SetSeeLines(true);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
private void SetSeeLines(bool seeLine)
{
int linesLayer = LayerMask.NameToLayer("Lines");
int mask = cam.cullingMask;
if (seeLine)
mask |= 1 << linesLayer; // 打开
else
mask &= ~(1 << linesLayer); // 关闭
cam.cullingMask = mask;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2361e682e26b43ffb6ff9615d39c487e
timeCreated: 1760663032