using System; using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 方向类型 /// public enum EDirectionType { UP, DOWN, LEFT, RIGHT, } /// /// 玩家信息 /// [Serializable] public class PlayerInfo { [SerializeField] private int _health; [SerializeField] private int _attack; [SerializeField] private int _defence; [SerializeField] private int _gold; [SerializeField] private int _weaponID; [SerializeField] private int _armorID; [SerializeField] private string _notepadInfo; public int Health { get => _health; set { _health = value < 0 ? 0 : value; GameManager.Instance.EventManager.OnHealthChanged?.Invoke(_health); } } public int Attack { get => _attack; set { _attack = value < 0 ? 0 : value; GameManager.Instance.EventManager.OnAttackChanged?.Invoke(_attack); } } public int Defence { get => _defence; set { _defence = value < 0 ? 0 : value; GameManager.Instance.EventManager.OnDefenceChanged?.Invoke(_defence); } } public int Gold { get => _gold; set { _gold = value; GameManager.Instance.EventManager.OnGoldChanged?.Invoke(_gold); } } public int WeaponID { get => _weaponID; set { _weaponID = value; GameManager.Instance.EventManager.OnWeaponChanged?.Invoke(_weaponID); } } public int ArmorID { get => _armorID; set { _armorID = value; GameManager.Instance.EventManager.OnArmorChanged?.Invoke(_armorID); } } public string NotepadInfo { get => _notepadInfo; set { _notepadInfo = value; GameManager.Instance.EventManager.OnNotepadChanged?.Invoke(_notepadInfo); } } } public class PlayerManager : Singleton { public bool LockEnable; // 开关加锁 private PlayerController _playerController; private bool _enable = true; private PlayerInfo _playerInfo; public PlayerInfo PlayerInfo { get => _playerInfo; set { _playerInfo = value; // 手动赋值刷新 UI _playerInfo.Health = _playerInfo.Health; _playerInfo.Attack = _playerInfo.Attack; _playerInfo.Defence = _playerInfo.Defence; _playerInfo.Gold = _playerInfo.Gold; _playerInfo.WeaponID = _playerInfo.WeaponID; _playerInfo.ArmorID = _playerInfo.ArmorID; _playerInfo.NotepadInfo = _playerInfo.NotepadInfo; } } public bool Enable { get => _enable; set { if (!LockEnable) _enable = value; } } public PlayerController PlayerController { get => _playerController; } /// /// 绑定玩家 /// /// public void BindPlayer(PlayerController playerController) { this._playerController = playerController; } /// /// 解绑玩家 /// public void UnbindPlayer() { this._playerController = null; } /// /// 检查输入 /// public void CheckInput() { if (_playerController && _enable) { if (Input.GetKeyDown(KeyCode.UpArrow)) GameManager.Instance.EventManager.OnMoveInput?.Invoke(EDirectionType.UP); if (Input.GetKeyDown(KeyCode.DownArrow)) GameManager.Instance.EventManager.OnMoveInput?.Invoke(EDirectionType.DOWN); if (Input.GetKeyDown(KeyCode.LeftArrow)) GameManager.Instance.EventManager.OnMoveInput?.Invoke(EDirectionType.LEFT); if (Input.GetKeyDown(KeyCode.RightArrow)) GameManager.Instance.EventManager.OnMoveInput?.Invoke(EDirectionType.RIGHT); if (Input.GetKeyDown(KeyCode.S)) GameManager.Instance.EventManager.OnSaveGameInput?.Invoke(); if (Input.GetKeyDown(KeyCode.Escape)) GameManager.Instance.EventManager.OnBackHomeInput?.Invoke(); if (Input.GetKeyDown(KeyCode.PageUp)) GameManager.Instance.EventManager.OnArtifactUp?.Invoke(); if (Input.GetKeyDown(KeyCode.PageDown)) GameManager.Instance.EventManager.OnArtifactDown?.Invoke(); //PSV if (Input.GetKeyDown(KeyCode.JoystickButton8)) GameManager.Instance.EventManager.OnMoveInput?.Invoke(EDirectionType.UP); if (Input.GetKeyDown(KeyCode.JoystickButton10)) GameManager.Instance.EventManager.OnMoveInput?.Invoke(EDirectionType.DOWN); if (Input.GetKeyDown(KeyCode.JoystickButton11)) GameManager.Instance.EventManager.OnMoveInput?.Invoke(EDirectionType.LEFT); if (Input.GetKeyDown(KeyCode.JoystickButton9)) GameManager.Instance.EventManager.OnMoveInput?.Invoke(EDirectionType.RIGHT); if (Input.GetKeyDown(KeyCode.JoystickButton7)) GameManager.Instance.EventManager.OnSaveGameInput?.Invoke(); //三角形 替代 空格 //SELECT if (Input.GetKeyDown(KeyCode.JoystickButton6)) GameManager.Instance.EventManager.OnBackHomeInput?.Invoke(); if (Input.GetKeyDown(KeyCode.JoystickButton3)) GameManager.Instance.EventManager.OnArtifactUp?.Invoke(); if (Input.GetKeyDown(KeyCode.JoystickButton0)) GameManager.Instance.EventManager.OnArtifactDown?.Invoke(); ////循环遍历输出 //if (Input.anyKeyDown) //{ // foreach (KeyCode keyCode in Enum.GetValues(typeof(KeyCode))) // { // if (Input.GetKeyDown(keyCode)) // { // Debug.LogError("Current Key is : " + keyCode.ToString()); // } // } //} } } /// /// 添加信息到记事本 /// /// 信息内容 public void AddInfoToNotepad(string info) { // 判断是否有记事本 if (!GameManager.Instance.BackpackManager.BackpackDictionary.ContainsKey(11)) return; _playerInfo.NotepadInfo += $"{info}\n\r\n\r"; } }