using Sirenix.OdinInspector; using Spine.Unity; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; public class PHomePlayer : PHomeUnit { [SerializeField] private Camera m_camera; [SerializeField] private float m_moveAudioTimeGap; [SerializeField] private List m_buffPrefabs; [SerializeField] private List m_weaponPrefabs; float currTime; [SerializeField] private GameObject m_proejctilePrefab; [SerializeField] private PHomePlayerScreen m_playerScreen; public PHomePlayerScreen PlayerScreen { get { return m_playerScreen; } } [SerializeField] private int m_killMonsterCount; public int KillMonsterCount { get { return m_killMonsterCount; } set { if (m_killMonsterCount != value) { m_killMonsterCount = value; } } } [SerializeField] private int m_gemCount; public PuzzleGameMode.VoidDelegate OnAfterGemCountChanged; public int GemCount { get { return m_gemCount; } set { if (m_gemCount != value) { m_gemCount = value; OnAfterGemCountChanged?.Invoke(); } } } [SerializeField] private float m_pickRadius; public float PickRadius { get { return m_pickRadius; } set { m_pickRadius = value; } } [SerializeField] private int m_pickMagnet; public int PickMagnet { get { return m_pickMagnet; } set { m_pickMagnet = value; } } public bool HasPickMagnet { get { return m_pickMagnet > 0; } } public PHomeInventory Inventory { get { return PHomeInventory.instance; } } public Transform m_portalPos; #region Debug [BoxGroup("Debug")] [Button] public void LevelUpPets() { foreach (var item in Pets) { PHomeGameMode.main.AddPet(this, item.FromPet); } } #endregion #region Pet public List StartPets; private List m_pets = new List(); public PuzzleGameMode.VoidDelegate OnAfterPetsChanged; public int PetCount { get { return m_pets.Count; } } public List Pets { get { return m_pets; } } public PHomePet GetHavePet(PHomePet testPet) { for (int i = 0; i < Pets.Count; i++) { if(Pets[i].FromPet == testPet) { return Pets[i]; } } return null; } public void RandomPetLevelUp() { int randomPet = Random.Range(0,Pets.Count); Pets[randomPet].SetMaxLevel(); } public void AddPet(PHomePet pet) { pet.SetPetIndex(m_pets.Count); m_pets.Add(pet); OnAfterPetsChanged?.Invoke(); } public void ClearPets() { int count = PetCount; foreach (PHomePet item in m_pets) { Destroy(item.gameObject); } m_pets.Clear(); if (count != 0) { OnAfterPetsChanged?.Invoke(); } } public void ResetPet() { for (int i = 0; i < m_pets.Count; i++) { m_pets[i].MaxHealth *= PHomeGameMode.main.GetMultiWithType(EventTargetUnitType.Pet,EventCardEffectType.Hp); } } #endregion #region Movement // private void Update_Movement() // { // #if UNITY_EDITOR // Vector2 velocity = Vector2.right * Input.GetAxisRaw("Horizontal") + Vector2.up * Input.GetAxisRaw("Vertical"); // Move(velocity); // #endif // } private void OnRightClick() { int br = 1; } public override void SetAimDirection(Vector2? aimDirection) { base.SetAimDirection(aimDirection); foreach (var pet in m_pets) { pet.SetAimDirection(aimDirection); } } #endregion #region Camera private void Awake_Camera() { m_camera = Camera.main; m_healthSpW = m_healthSp.size.x; OnAfterHealthChanged += UpdateHp; } private void UpdateHp() { m_healthSp.size = new Vector2(Health / MaxHealth * m_healthSpW, m_healthSp.size.y); } private void Update_Camera() { if (m_camera == null) { return; } Vector3 newDestPos = transform.position; newDestPos.z = m_camera.transform.position.z; m_camera.transform.position = Vector3.Lerp(m_camera.transform.position, newDestPos, 0.9f); } #endregion #region Input private EysionInputActions m_inputActions; private EysionInputActions InputActions { get { m_inputActions = m_inputActions ?? new EysionInputActions(); return m_inputActions; } } private void Awake_Input() { //InputActions.Player.Move.performed += ctx => Move(ctx.ReadValue()); } private void OnEnable_Input() { InputActions.Player.Enable(); } private void OnDisable_Input() { InputActions.Player.Disable(); } void Update_Input() { Move(InputActions.Player.Move.ReadValue()); } //private void AttackOnce(PHomeMonster monster) //{ // AudioManager.instance.AttackAudio(); // PHomeProjectile proj = PHomeGameMode.main.SpawnProjectile(this, transform.position, m_proejctilePrefab); // proj.Target = monster; // EnterCooldown(); //} //private void Update_Attack() //{ // if (DuringAttackInterval) // { // return; // } // PHomeMonster monster = PHomeGameMode.main.FindClosestMonster(transform.position, m_attackRangeBase, this); // if (monster == null) // { // return; // } // AttackOnce(monster); //} #endregion #region Callback public override void OnAfterHitted(PHomeUnit attacker, PHomeUnit victim) { base.OnAfterHitted(attacker, victim); HandheldUtils.Vibrate(); } #endregion protected override void VirtualAwake() { base.VirtualAwake(); Awake_Camera(); Awake_Input(); } protected override void VirtualStart() { base.VirtualStart(); } protected override void VirtualUpdate() { base.VirtualUpdate(); // Update_Movement(); Update_Camera(); //Update_Attack(); // Update_Anim(); Update_Input(); } protected override void VirutalOnEnable() { base.VirutalOnEnable(); OnEnable_Input(); } protected override void VirtualOnDisable() { base.VirtualOnDisable(); OnDisable_Input(); } }