138 lines
3.9 KiB
C#
138 lines
3.9 KiB
C#
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace AxibugEmuOnline.Client
|
|||
|
{
|
|||
|
public class CommandDispatcher : MonoBehaviour
|
|||
|
{
|
|||
|
public static CommandDispatcher Instance { get; private set; }
|
|||
|
|
|||
|
/// <summary> ƽ<><C6BD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧָ<D3A6><D6B8> </summary>
|
|||
|
List<CommandExecuter> m_register = new List<CommandExecuter>();
|
|||
|
/// <summary> <20><>ռע<D5BC><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,ָ<><D6B8><EFBFBD>ᱻ<EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ </summary>
|
|||
|
List<CommandExecuter> m_registerHigh = new List<CommandExecuter>();
|
|||
|
|
|||
|
ICommandListener m_listener;
|
|||
|
/// <summary> <20><>UI<55><49><EFBFBD><EFBFBD> </summary>
|
|||
|
public IKeyMapperChanger Normal { get; private set; }
|
|||
|
/// <summary> <20><>Ϸ<EFBFBD><CFB7>UI<55><49><EFBFBD><EFBFBD> </summary>
|
|||
|
public IKeyMapperChanger Gaming { get; private set; }
|
|||
|
|
|||
|
private IKeyMapperChanger m_current;
|
|||
|
public IKeyMapperChanger Current
|
|||
|
{
|
|||
|
get => m_current;
|
|||
|
set
|
|||
|
{
|
|||
|
m_current = value;
|
|||
|
|
|||
|
SetKeyMapper(m_current);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
Instance = this;
|
|||
|
|
|||
|
//<2F><>ʼ<EFBFBD><CABC>command<6E><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
m_listener = new CommandListener();
|
|||
|
|
|||
|
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><DEB8><EFBFBD>
|
|||
|
Normal = new NormalChanger();
|
|||
|
Gaming = new GamingChanger();
|
|||
|
}
|
|||
|
|
|||
|
private void OnDestroy()
|
|||
|
{
|
|||
|
Instance = null;
|
|||
|
}
|
|||
|
|
|||
|
public bool IsRegisted(CommandExecuter commandExecuter)
|
|||
|
{
|
|||
|
return m_register.Contains(commandExecuter) || m_registerHigh.Contains(commandExecuter);
|
|||
|
}
|
|||
|
|
|||
|
public void RegistController(CommandExecuter controller)
|
|||
|
{
|
|||
|
if (!controller.AloneMode)
|
|||
|
{
|
|||
|
if (m_register.Contains(controller)) { return; }
|
|||
|
|
|||
|
m_register.Add(controller);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (m_registerHigh.Contains(controller)) { return; }
|
|||
|
|
|||
|
m_registerHigh.Add(controller);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void UnRegistController(CommandExecuter menuItemController)
|
|||
|
{
|
|||
|
if (!menuItemController.AloneMode)
|
|||
|
m_register.Remove(menuItemController);
|
|||
|
else
|
|||
|
m_registerHigh.Remove(menuItemController);
|
|||
|
}
|
|||
|
|
|||
|
readonly List<CommandExecuter> oneFrameRegister = new List<CommandExecuter>();
|
|||
|
private void Update()
|
|||
|
{
|
|||
|
if (!InputUI.IsInputing)
|
|||
|
{
|
|||
|
peekRegister(oneFrameRegister);
|
|||
|
m_listener.Update(oneFrameRegister);
|
|||
|
}
|
|||
|
|
|||
|
//<2F><>λӳ<CEBB><D3B3><EFBFBD>ڰ<EFBFBD><DAB0><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>Ķ<EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if (m_waitMapperSetting != null)
|
|||
|
{
|
|||
|
m_listener.ApplyKeyMapper(m_waitMapperSetting);
|
|||
|
m_waitMapperSetting = null;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
IKeyMapperChanger m_waitMapperSetting = null;
|
|||
|
void SetKeyMapper(IKeyMapperChanger keyMapChanger)
|
|||
|
{
|
|||
|
m_waitMapperSetting = keyMapChanger;
|
|||
|
}
|
|||
|
|
|||
|
private List<CommandExecuter> peekRegister(List<CommandExecuter> results)
|
|||
|
{
|
|||
|
results.Clear();
|
|||
|
|
|||
|
if (m_registerHigh.Count > 0)
|
|||
|
{
|
|||
|
for (int i = m_registerHigh.Count - 1; i >= 0; i--)
|
|||
|
{
|
|||
|
var controller = m_registerHigh[i];
|
|||
|
if (controller.Enable)
|
|||
|
{
|
|||
|
results.Add(controller);
|
|||
|
return results;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
foreach (var controller in m_register)
|
|||
|
{
|
|||
|
if (!controller.Enable) continue;
|
|||
|
|
|||
|
results.Add(controller);
|
|||
|
}
|
|||
|
|
|||
|
return results;
|
|||
|
}
|
|||
|
|
|||
|
#if UNITY_EDITOR
|
|||
|
public void GetRegisters(out IReadOnlyList<CommandExecuter> normal, out IReadOnlyList<CommandExecuter> alone)
|
|||
|
{
|
|||
|
normal = m_register;
|
|||
|
alone = m_registerHigh;
|
|||
|
}
|
|||
|
#endif
|
|||
|
}
|
|||
|
}
|