实现长按移动

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
{
ShopComm.E_ShopFloor floor = ShopComm.E_ShopFloor.F4;

View File

@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
/// <summary>
@ -156,6 +157,32 @@ public class PlayerManager : Singleton<PlayerManager>
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>
@ -199,6 +226,51 @@ public class PlayerManager : Singleton<PlayerManager>
// }
// }
//}
#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
}
}

View File

@ -88,7 +88,7 @@ public class SoundManager : MonoSingleton<SoundManager>
/// <param name="clipName">音频名称</param>
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
{
switch (type)