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

@@ -5,7 +5,8 @@ namespace Gameplay
public class Card
{
private CardData _cardData;
public Texture Texture => _cardData.CardTexture;
public Texture FrontTexture => _cardData.FrontCardTexture;
public Texture BackTexture => _cardData.BackCardTexture;
public string CardName => _cardData.CardName;
public string CardDescription => _cardData.CardDescription;
public EffectData[] Effects => _cardData.Effects;

View File

@@ -10,7 +10,8 @@ namespace Gameplay
public int CardID;
public string CardName;
public string CardDescription;
public Texture CardTexture;
public Texture FrontCardTexture;
public Texture BackCardTexture;
public EffectData[] Effects;
}

View File

@@ -1,5 +1,5 @@
using UnityEngine;
using Share;
using Interface;
namespace Gameplay
{
public class CardContext

View File

@@ -1,23 +1,62 @@
using System;
using UnityEngine;
using UnityEngine.UI;
using Interface;
using Core;
using Gameplay.Player;
namespace Gameplay
{
public class CardViewer : MonoBehaviour
public class CardViewer : MonoBehaviour, IInteractable
{
public Card Card;
[SerializeField] private MeshRenderer meshRenderer;
[SerializeField] private MeshRenderer frontMeshRenderer;
[SerializeField] private MeshRenderer backMeshRenderer;
[SerializeField] private Text cardNameText;
[SerializeField] private Text cardDescriptionText;
public void Setup(Card card)
private PlayerController _playerController;
private void Start()
{
ControllerLocator.Instance.TryGet<PlayerController>(out _playerController);
}
public void SetCard(Card card)
{
Card = card;
meshRenderer.material.mainTexture = card.Texture;
if (frontMeshRenderer != null && card.FrontTexture != null)
{
frontMeshRenderer.material.mainTexture = card.FrontTexture;
}
if (backMeshRenderer != null && card.BackTexture != null)
{
backMeshRenderer.material.mainTexture = card.BackTexture;
}
cardNameText.text = card.CardName;
cardDescriptionText.text = card.CardDescription;
}
}
}
public string GetInteractPrompt()
{
return "";
}
public void Interact(GameObject interactor)
{
}
public void OnGazeEnter(GameObject editor)
{
if(_playerController != null) _playerController.playerCardsController.StopRotatingCards();
}
public void OnGazeExit(GameObject editor)
{
if (_playerController != null) _playerController.playerCardsController.StartRotatingCards();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5db247b9fcb44b3f85bdcc7cdb634481
timeCreated: 1760575054

View File

@@ -1,7 +1,7 @@
using UnityEngine;
namespace Gameplay
{
// 从Resources文件夹加载卡牌数据的静态类
// 用来加载卡牌数据的静态类
public static class CardLoader
{
public static CardData GetCardDataByID(int cardID)
@@ -17,5 +17,15 @@ namespace Gameplay
Debug.LogError($"Card with ID {cardID} not found!");
return null;
}
public static Card GetCardByID(int cardID)
{
CardData cardData = GetCardDataByID(cardID);
if (cardData != null)
{
return new Card(cardData);
}
return null;
}
}
}

View File

@@ -3,7 +3,7 @@ using System.Collections;
using Core;
using Gameplay.Enemy;
using Gameplay.Player;
using Share;
using Interface;
using UnityEngine;
namespace Gameplay

View File

@@ -1,7 +1,7 @@
using System;
using UnityEngine;
using Gameplay;
using Share;
using Interface;
using Gameplay.Enemy;
using Gameplay.Player;

View File

@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Share;
using Interface;
using UnityEngine;
namespace Gameplay.Enemy

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 09fa458abe0e7c54eafb0cf409eb60d4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
namespace Script.Gameplay.Facility
{
public class EditComponent
{
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bca7c28154234ab4b792dca4d2f92354
timeCreated: 1760629389

View File

@@ -0,0 +1,69 @@
using System;
using Gameplay.Player;
using UnityEngine;
using Interface;
namespace Script.Gameplay.Facility
{
public class FacilityController : MonoBehaviour, IInteractable, IEditable
{
public FacilityModifier facilityModifier;
private void Awake()
{
if (facilityModifier == null)
{
facilityModifier = GetComponent<FacilityModifier>();
}
}
private void Start()
{
}
public string GetInteractPrompt()
{
return "";
}
public void Interact(GameObject interactor)
{
}
public void OnGazeEnter(GameObject editor)
{
// 物体弹出按F可交互菜单
}
public void OnGazeExit(GameObject editor)
{
// 物体取消菜单
}
public void OnGazeEnter(PlayerEditController editor)
{
}
public void OnGazeExit(PlayerEditController editor)
{
}
public void BeginEdit()
{
}
public void EndEdit()
{
}
public IEditable GetEditable()
{
return this;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7986c88b8e1d4944832af56e23188597
timeCreated: 1760664530

View File

@@ -0,0 +1,27 @@
using UnityEngine;
namespace Script.Gameplay.Facility
{
public class FacilityModifier : MonoBehaviour
{
private Transform _transform;
private Collider _collider;
private Rigidbody _rigidbody;
public void ModifyComponent<T>(bool isOpen, T component) where T : Component
{
var targetComponent = this.GetComponent<T>();
if (targetComponent != null)
{
if (isOpen)
{
targetComponent.gameObject.SetActive(true);
}
else
{
targetComponent.gameObject.SetActive(false);
}
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b1db33a437984a1a8fae09ab8c5de7e4
timeCreated: 1760667210

View File

@@ -1,12 +1,13 @@
using System;
using UnityEngine;
using UnityEngine.InputSystem;
using Core;
namespace Input
namespace Script.Gameplay.Input
{
public class InputManager : MonoSingleton<InputManager>, IInputManager
{
private PlayerInputActions _input; // 自动生成的输入类
public PlayerInputActions Input; // 自动生成的输入类
// 当前输入值
public Vector2 Move { get; private set; }
@@ -14,36 +15,43 @@ namespace Input
public bool JumpPressed { get; private set; }
public bool PausePressed { get; private set; }
public bool InteractPressed { get; private set; }
public bool EditPressed { get; private set; }
private bool _hasFocus = true;
private void Awake()
{
_input = new PlayerInputActions();
Input = new PlayerInputActions();
}
private void OnEnable()
{
_input.Enable();
Input.Enable();
// 注册事件
_input.Player.Move.performed += ctx => Move = ctx.ReadValue<Vector2>();
_input.Player.Move.canceled += ctx => Move = Vector2.zero;
Input.Player.Move.performed += ctx => Move = ctx.ReadValue<Vector2>();
Input.Player.Move.canceled += ctx => Move = Vector2.zero;
_input.Player.Look.performed += ctx => Look = ctx.ReadValue<Vector2>();
_input.Player.Look.canceled += ctx => Look = Vector2.zero;
Input.Player.Look.performed += ctx => Look = ctx.ReadValue<Vector2>();
Input.Player.Look.canceled += ctx => Look = Vector2.zero;
_input.Player.Jump.performed += ctx => JumpPressed = true;
_input.Player.Jump.canceled += ctx => JumpPressed = false;
Input.Player.Jump.performed += ctx => JumpPressed = true;
Input.Player.Jump.canceled += ctx => JumpPressed = false;
Input.Player.Pause.performed += ctx => PausePressed = true;
Input.Player.Pause.canceled += ctx => PausePressed = false;
// _input.Player.Pause.performed += ctx => PausePressed = true;
// _input.Player.Pause.canceled += ctx => PausePressed = false;
Input.Player.Interact.performed += ctx => InteractPressed = true;
Input.Player.Interact.canceled += ctx => InteractPressed = false;
_input.Player.Interact.performed += ctx => InteractPressed = true;
_input.Player.Interact.canceled += ctx => InteractPressed = false;
Input.Player.Edit.performed += ctx => EditPressed = true;
Input.Player.Edit.canceled += ctx => EditPressed = false;
}
private void OnDisable()
{
_input.Disable();
// 可选:取消注册以防止重复订阅(简单项目可不解除)
Input.Disable();
}
private void Start()
@@ -57,15 +65,15 @@ namespace Input
// if (PausePressed)
// {
// Debug.Log("Pause Pressed!");
// PausePressed = false; // 手动清除
// PausePressed = false; // 手动清除(如果需要瞬时)
// }
}
// 🔧 示例方法:允许外部模块手动启用/禁用输入(比如暂停菜单)
public void SetInputEnabled(bool enabled)
{
if (enabled) _input.Enable();
else _input.Disable();
if (enabled) Input.Enable();
else Input.Disable();
}
public void SetCursorState(bool visible, CursorLockMode lockMode)
@@ -78,11 +86,11 @@ namespace Input
{
if (enabled)
{
_input.Player.Look.Enable();
Input.Player.Look.Enable();
}
else
{
_input.Player.Look.Disable();
Input.Player.Look.Disable();
Look = Vector2.zero; // 禁用时清除Look值
}
}
@@ -91,13 +99,28 @@ namespace Input
{
if (enabled)
{
_input.Player.Move.Enable();
Input.Player.Move.Enable();
}
else
{
_input.Player.Move.Disable();
Input.Player.Move.Disable();
Move = Vector2.zero; // 禁用时清除Move值
}
}
// 当窗口获得/失去焦点时调用(玩家是否在注视游戏窗口)
private void OnApplicationFocus(bool hasFocus)
{
_hasFocus = hasFocus;
// 失去焦点视为系统级暂停
if (_hasFocus)
{
SetCursorState(_hasFocus, CursorLockMode.Locked);
}
else
{
SetCursorState(_hasFocus, CursorLockMode.None);
}
}
}
}
}

View File

@@ -15,7 +15,7 @@ using System.Collections.Generic;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;
namespace Input
namespace Script.Gameplay.Input
{
public partial class @PlayerInputActions: IInputActionCollection2, IDisposable
{
@@ -64,6 +64,33 @@ namespace Input
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
},
{
""name"": ""Pause"",
""type"": ""Button"",
""id"": ""822c2284-94e3-4636-894c-adfe85ac467d"",
""expectedControlType"": """",
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
},
{
""name"": ""SwitchWatchMode"",
""type"": ""Button"",
""id"": ""73ffcbfd-15ae-4580-99c4-d7d06ff13bb6"",
""expectedControlType"": """",
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
},
{
""name"": ""Edit"",
""type"": ""Button"",
""id"": ""20a9157a-918b-42f1-80b1-9e014426068e"",
""expectedControlType"": """",
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
}
],
""bindings"": [
@@ -165,6 +192,39 @@ namespace Input
""action"": ""Interact"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""943ba523-b024-410e-a250-735a5ffdf786"",
""path"": ""<Keyboard>/escape"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Pause"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""47af0242-9835-4b1a-82c8-e3fc32489870"",
""path"": ""<Keyboard>/tab"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""SwitchWatchMode"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""9e9bf8ec-8b3e-4230-a10c-ae874395711a"",
""path"": ""<Keyboard>/x"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Edit"",
""isComposite"": false,
""isPartOfComposite"": false
}
]
}
@@ -177,6 +237,9 @@ namespace Input
m_Player_Look = m_Player.FindAction("Look", throwIfNotFound: true);
m_Player_Jump = m_Player.FindAction("Jump", throwIfNotFound: true);
m_Player_Interact = m_Player.FindAction("Interact", throwIfNotFound: true);
m_Player_Pause = m_Player.FindAction("Pause", throwIfNotFound: true);
m_Player_SwitchWatchMode = m_Player.FindAction("SwitchWatchMode", throwIfNotFound: true);
m_Player_Edit = m_Player.FindAction("Edit", throwIfNotFound: true);
}
~@PlayerInputActions()
@@ -247,6 +310,9 @@ namespace Input
private readonly InputAction m_Player_Look;
private readonly InputAction m_Player_Jump;
private readonly InputAction m_Player_Interact;
private readonly InputAction m_Player_Pause;
private readonly InputAction m_Player_SwitchWatchMode;
private readonly InputAction m_Player_Edit;
public struct PlayerActions
{
private @PlayerInputActions m_Wrapper;
@@ -255,6 +321,9 @@ namespace Input
public InputAction @Look => m_Wrapper.m_Player_Look;
public InputAction @Jump => m_Wrapper.m_Player_Jump;
public InputAction @Interact => m_Wrapper.m_Player_Interact;
public InputAction @Pause => m_Wrapper.m_Player_Pause;
public InputAction @SwitchWatchMode => m_Wrapper.m_Player_SwitchWatchMode;
public InputAction @Edit => m_Wrapper.m_Player_Edit;
public InputActionMap Get() { return m_Wrapper.m_Player; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
@@ -276,6 +345,15 @@ namespace Input
@Interact.started += instance.OnInteract;
@Interact.performed += instance.OnInteract;
@Interact.canceled += instance.OnInteract;
@Pause.started += instance.OnPause;
@Pause.performed += instance.OnPause;
@Pause.canceled += instance.OnPause;
@SwitchWatchMode.started += instance.OnSwitchWatchMode;
@SwitchWatchMode.performed += instance.OnSwitchWatchMode;
@SwitchWatchMode.canceled += instance.OnSwitchWatchMode;
@Edit.started += instance.OnEdit;
@Edit.performed += instance.OnEdit;
@Edit.canceled += instance.OnEdit;
}
private void UnregisterCallbacks(IPlayerActions instance)
@@ -292,6 +370,15 @@ namespace Input
@Interact.started -= instance.OnInteract;
@Interact.performed -= instance.OnInteract;
@Interact.canceled -= instance.OnInteract;
@Pause.started -= instance.OnPause;
@Pause.performed -= instance.OnPause;
@Pause.canceled -= instance.OnPause;
@SwitchWatchMode.started -= instance.OnSwitchWatchMode;
@SwitchWatchMode.performed -= instance.OnSwitchWatchMode;
@SwitchWatchMode.canceled -= instance.OnSwitchWatchMode;
@Edit.started -= instance.OnEdit;
@Edit.performed -= instance.OnEdit;
@Edit.canceled -= instance.OnEdit;
}
public void RemoveCallbacks(IPlayerActions instance)
@@ -315,6 +402,9 @@ namespace Input
void OnLook(InputAction.CallbackContext context);
void OnJump(InputAction.CallbackContext context);
void OnInteract(InputAction.CallbackContext context);
void OnPause(InputAction.CallbackContext context);
void OnSwitchWatchMode(InputAction.CallbackContext context);
void OnEdit(InputAction.CallbackContext context);
}
}
}

View File

@@ -3,7 +3,7 @@ using UnityEngine;
using Gameplay;
using System.Collections.Generic;
namespace Share
namespace Interface
{
/// <summary>
/// 角色接口可受伤害、治疗和添加Buff、发生战斗

View File

@@ -0,0 +1,13 @@
using UnityEngine;
using Gameplay.Player;
namespace Interface
{
public interface IEditable
{
void OnGazeEnter(PlayerEditController editor); // 玩家开始注视时触发
void OnGazeExit(PlayerEditController editor); // 玩家停止注视时触发
void BeginEdit();
void EndEdit();
IEditable GetEditable();
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8a22b94dcb1d4eb78b7b07ebd8967dc6
timeCreated: 1760629255

View File

@@ -1,9 +1,11 @@
using UnityEngine;
namespace Share
namespace Interface
{
public interface IInteractable
{
string GetInteractPrompt(); // 返回提示文字例如“按E打开门”
void Interact(GameObject interactor); // 当玩家交互时触发
void OnGazeEnter(GameObject editor); // 玩家开始注视时触发
void OnGazeExit(GameObject editor); // 玩家停止注视时触发
}
}

View File

@@ -1,5 +1,5 @@
using UnityEngine;
using Share;
using Interface;
namespace Map
{
public class FlightTrigger : MonoBehaviour

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