实现长按移动

This commit is contained in:
sin365 2024-05-06 11:22:04 +08:00
parent 36a961c130
commit 36d0b12ff8
3 changed files with 85 additions and 21 deletions

View File

@ -1,11 +1,3 @@
public enum ERandomShopType
{
Health,
Attack,
Defence,
Gold,
}
public class EventLevel4Actor1 : ActorController public class EventLevel4Actor1 : ActorController
{ {
ShopComm.E_ShopFloor floor = ShopComm.E_ShopFloor.F4; ShopComm.E_ShopFloor floor = ShopComm.E_ShopFloor.F4;

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using UnityEngine; using UnityEngine;
/// <summary> /// <summary>
@ -156,6 +157,32 @@ public class PlayerManager : Singleton<PlayerManager>
this._playerController = null; this._playerController = null;
} }
const float KeepKeyTime = 0.2f;
Dictionary<KeyCode, float> DictKeyKeep = new Dictionary<KeyCode, float>()
{
{KeyCode.UpArrow,-1 },
{KeyCode.DownArrow,-1 },
{KeyCode.LeftArrow,-1 },
{KeyCode.RightArrow,-1 },
{KeyCode.JoystickButton8,-1 },
{KeyCode.JoystickButton10,-1 },
{KeyCode.JoystickButton11,-1},
{KeyCode.JoystickButton9,-1},
};
KeyCode[] KeepKeys = {
KeyCode.UpArrow,
KeyCode.DownArrow,
KeyCode.LeftArrow,
KeyCode.RightArrow,
KeyCode.JoystickButton8,
KeyCode.JoystickButton10,
KeyCode.JoystickButton1,
KeyCode.JoystickButton9,
};
/// <summary> /// <summary>
/// 检查输入 /// 检查输入
/// </summary> /// </summary>
@ -188,19 +215,64 @@ public class PlayerManager : Singleton<PlayerManager>
if (Input.GetKeyDown(KeyCode.JoystickButton3)) GameManager.Instance.EventManager.OnArtifactUp?.Invoke(); if (Input.GetKeyDown(KeyCode.JoystickButton3)) GameManager.Instance.EventManager.OnArtifactUp?.Invoke();
if (Input.GetKeyDown(KeyCode.JoystickButton0)) GameManager.Instance.EventManager.OnArtifactDown?.Invoke(); if (Input.GetKeyDown(KeyCode.JoystickButton0)) GameManager.Instance.EventManager.OnArtifactDown?.Invoke();
////循环遍历输出 ////循环遍历输出
//if (Input.anyKeyDown) //if (Input.anyKeyDown)
//{ //{
// foreach (KeyCode keyCode in Enum.GetValues(typeof(KeyCode))) // foreach (KeyCode keyCode in Enum.GetValues(typeof(KeyCode)))
// { // {
// if (Input.GetKeyDown(keyCode)) // if (Input.GetKeyDown(keyCode))
// { // {
// Debug.LogError("Current Key is : " + keyCode.ToString()); // Debug.LogError("Current Key is : " + keyCode.ToString());
// } // }
// } // }
//} //}
#region
for(int i=0; i< KeepKeys.Length; i++)
{
KeyCode key = KeepKeys[i];
if (!Input.GetKey(key))
DictKeyKeep[key] = -1;
else
{
if (DictKeyKeep[key] == -1)
DictKeyKeep[key] = Time.time;
else if(Time.time - DictKeyKeep[key] >= KeepKeyTime)
{
DictKeyKeep[key] = -1;
switch (key)
{
case KeyCode.UpArrow:
case KeyCode.JoystickButton8:
GameManager.Instance.EventManager.OnMoveInput?.Invoke(EDirectionType.UP);
break;
case KeyCode.DownArrow:
case KeyCode.JoystickButton10:
GameManager.Instance.EventManager.OnMoveInput?.Invoke(EDirectionType.DOWN);
break;
case KeyCode.LeftArrow:
case KeyCode.JoystickButton11:
GameManager.Instance.EventManager.OnMoveInput?.Invoke(EDirectionType.LEFT);
break;
case KeyCode.RightArrow:
case KeyCode.JoystickButton9:
GameManager.Instance.EventManager.OnMoveInput?.Invoke(EDirectionType.RIGHT);
break;
}
}
}
}
#endregion
} }
} }
/// <summary> /// <summary>
/// 添加信息到记事本 /// 添加信息到记事本

View File

@ -88,7 +88,7 @@ public class SoundManager : MonoSingleton<SoundManager>
/// <param name="clipName">音频名称</param> /// <param name="clipName">音频名称</param>
public void PlaySound(ESoundType type, string clipName) public void PlaySound(ESoundType type, string clipName)
{ {
Debug.Log($"PlaySound {type}:{clipName} |_musicName {_musicName} | LockEnable {LockEnable} "); //Debug.Log($"PlaySound {type}:{clipName} |_musicName {_musicName} | LockEnable {LockEnable} ");
try try
{ {
switch (type) switch (type)