清理项目目录,引入 InputModule 做多平台输入适配
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SepCore.InputModule
|
||||
{
|
||||
public sealed class InputContextStack
|
||||
{
|
||||
private readonly List<InputContextId> _contexts = new List<InputContextId>();
|
||||
|
||||
public int Count => _contexts.Count;
|
||||
|
||||
public InputContextId Current => Count > 0 ? _contexts[Count - 1] : InputContextId.None;
|
||||
|
||||
public IReadOnlyList<InputContextId> Items => _contexts;
|
||||
|
||||
public bool Push(InputContextId context)
|
||||
{
|
||||
if (!IsStackable(context) || Current == context)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_contexts.Contains(context))
|
||||
{
|
||||
_contexts.Remove(context);
|
||||
}
|
||||
|
||||
_contexts.Add(context);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Pop(out InputContextId context)
|
||||
{
|
||||
if (Count == 0)
|
||||
{
|
||||
context = InputContextId.None;
|
||||
return false;
|
||||
}
|
||||
|
||||
int index = Count - 1;
|
||||
context = _contexts[index];
|
||||
_contexts.RemoveAt(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Set(InputContextId context)
|
||||
{
|
||||
if (!IsStackable(context))
|
||||
{
|
||||
return Clear();
|
||||
}
|
||||
|
||||
if (Count == 1 && Current == context)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_contexts.Clear();
|
||||
_contexts.Add(context);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Clear()
|
||||
{
|
||||
if (Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_contexts.Clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool IsStackable(InputContextId context)
|
||||
{
|
||||
return context != InputContextId.None && context != InputContextId.Global;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user