Updated input system, added touch inputs
Now InputTranslator has its own interface to provide polymorphism in GameSession class Touch input read only if target platform is android
This commit is contained in:
parent
e1c8070226
commit
f2797a5355
1
.gitignore
vendored
1
.gitignore
vendored
@ -56,6 +56,7 @@ ExportedObj/
|
|||||||
sysinfo.txt
|
sysinfo.txt
|
||||||
|
|
||||||
# Builds
|
# Builds
|
||||||
|
/[Aa]ndroidBuild*
|
||||||
*.apk
|
*.apk
|
||||||
*.aab
|
*.aab
|
||||||
*.unitypackage
|
*.unitypackage
|
||||||
|
@ -607,7 +607,6 @@ Transform:
|
|||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 1858832248}
|
- {fileID: 1858832248}
|
||||||
- {fileID: 1791311983}
|
- {fileID: 1791311983}
|
||||||
- {fileID: 378990291}
|
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 10
|
m_RootOrder: 10
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
@ -746,107 +745,6 @@ CanvasRenderer:
|
|||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 377940177}
|
m_GameObject: {fileID: 377940177}
|
||||||
m_CullTransparentMesh: 1
|
m_CullTransparentMesh: 1
|
||||||
--- !u!1 &378990290
|
|
||||||
GameObject:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
serializedVersion: 6
|
|
||||||
m_Component:
|
|
||||||
- component: {fileID: 378990291}
|
|
||||||
- component: {fileID: 378990294}
|
|
||||||
- component: {fileID: 378990293}
|
|
||||||
- component: {fileID: 378990292}
|
|
||||||
m_Layer: 5
|
|
||||||
m_Name: ScoreCanvas
|
|
||||||
m_TagString: Untagged
|
|
||||||
m_Icon: {fileID: 0}
|
|
||||||
m_NavMeshLayer: 0
|
|
||||||
m_StaticEditorFlags: 0
|
|
||||||
m_IsActive: 1
|
|
||||||
--- !u!224 &378990291
|
|
||||||
RectTransform:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 378990290}
|
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
|
||||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
|
||||||
m_LocalScale: {x: 0, y: 0, z: 0}
|
|
||||||
m_ConstrainProportionsScale: 0
|
|
||||||
m_Children:
|
|
||||||
- {fileID: 678372250}
|
|
||||||
m_Father: {fileID: 245285643}
|
|
||||||
m_RootOrder: 2
|
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
|
||||||
m_AnchorMin: {x: 0, y: 0}
|
|
||||||
m_AnchorMax: {x: 0, y: 0}
|
|
||||||
m_AnchoredPosition: {x: 0, y: 0}
|
|
||||||
m_SizeDelta: {x: 0, y: 0}
|
|
||||||
m_Pivot: {x: 0, y: 0}
|
|
||||||
--- !u!114 &378990292
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 378990290}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
m_IgnoreReversedGraphics: 1
|
|
||||||
m_BlockingObjects: 0
|
|
||||||
m_BlockingMask:
|
|
||||||
serializedVersion: 2
|
|
||||||
m_Bits: 4294967295
|
|
||||||
--- !u!114 &378990293
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 378990290}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
m_UiScaleMode: 1
|
|
||||||
m_ReferencePixelsPerUnit: 100
|
|
||||||
m_ScaleFactor: 1
|
|
||||||
m_ReferenceResolution: {x: 800, y: 600}
|
|
||||||
m_ScreenMatchMode: 0
|
|
||||||
m_MatchWidthOrHeight: 0
|
|
||||||
m_PhysicalUnit: 3
|
|
||||||
m_FallbackScreenDPI: 96
|
|
||||||
m_DefaultSpriteDPI: 96
|
|
||||||
m_DynamicPixelsPerUnit: 1
|
|
||||||
m_PresetInfoIsWorld: 0
|
|
||||||
--- !u!223 &378990294
|
|
||||||
Canvas:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 378990290}
|
|
||||||
m_Enabled: 1
|
|
||||||
serializedVersion: 3
|
|
||||||
m_RenderMode: 0
|
|
||||||
m_Camera: {fileID: 0}
|
|
||||||
m_PlaneDistance: 100
|
|
||||||
m_PixelPerfect: 0
|
|
||||||
m_ReceivesEvents: 1
|
|
||||||
m_OverrideSorting: 0
|
|
||||||
m_OverridePixelPerfect: 0
|
|
||||||
m_SortingBucketNormalizedSize: 0
|
|
||||||
m_AdditionalShaderChannelsFlag: 25
|
|
||||||
m_SortingLayerID: 0
|
|
||||||
m_SortingOrder: 0
|
|
||||||
m_TargetDisplay: 0
|
|
||||||
--- !u!1 &634835457
|
--- !u!1 &634835457
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -2172,6 +2070,7 @@ RectTransform:
|
|||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 220002229}
|
- {fileID: 220002229}
|
||||||
- {fileID: 1754320530}
|
- {fileID: 1754320530}
|
||||||
|
- {fileID: 678372250}
|
||||||
m_Father: {fileID: 245285643}
|
m_Father: {fileID: 245285643}
|
||||||
m_RootOrder: 0
|
m_RootOrder: 0
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
@ -2852,7 +2751,7 @@ PrefabInstance:
|
|||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Modification:
|
m_Modification:
|
||||||
m_TransformParent: {fileID: 378990291}
|
m_TransformParent: {fileID: 1858832248}
|
||||||
m_Modifications:
|
m_Modifications:
|
||||||
- target: {fileID: 6634832997822410792, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
- target: {fileID: 6634832997822410792, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
||||||
propertyPath: m_SizeDelta.x
|
propertyPath: m_SizeDelta.x
|
||||||
@ -2892,7 +2791,7 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
||||||
propertyPath: m_RootOrder
|
propertyPath: m_RootOrder
|
||||||
value: 0
|
value: 2
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
||||||
propertyPath: m_AnchorMax.x
|
propertyPath: m_AnchorMax.x
|
||||||
@ -2904,31 +2803,31 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
||||||
propertyPath: m_AnchorMin.x
|
propertyPath: m_AnchorMin.x
|
||||||
value: 1
|
value: 0
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
||||||
propertyPath: m_AnchorMin.y
|
propertyPath: m_AnchorMin.y
|
||||||
value: 1
|
value: 0
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
||||||
propertyPath: m_SizeDelta.x
|
propertyPath: m_SizeDelta.x
|
||||||
value: 161.66
|
value: 0
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
||||||
propertyPath: m_SizeDelta.y
|
propertyPath: m_SizeDelta.y
|
||||||
value: 36.7283
|
value: 0.14001465
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
||||||
propertyPath: m_LocalScale.x
|
propertyPath: m_LocalScale.x
|
||||||
value: 1.1175
|
value: 1
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
||||||
propertyPath: m_LocalScale.y
|
propertyPath: m_LocalScale.y
|
||||||
value: 1.1175
|
value: 1
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
||||||
propertyPath: m_LocalScale.z
|
propertyPath: m_LocalScale.z
|
||||||
value: 1.1175
|
value: 1
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
||||||
propertyPath: m_LocalPosition.x
|
propertyPath: m_LocalPosition.x
|
||||||
@ -2960,11 +2859,11 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
||||||
propertyPath: m_AnchoredPosition.x
|
propertyPath: m_AnchoredPosition.x
|
||||||
value: -90.33002
|
value: 0
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
||||||
propertyPath: m_AnchoredPosition.y
|
propertyPath: m_AnchoredPosition.y
|
||||||
value: -18.084717
|
value: 0.21002197
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
- target: {fileID: 6634832998035864265, guid: 68d36a24cad029f4a91d5c8e7aa18281, type: 3}
|
||||||
propertyPath: m_LocalEulerAnglesHint.x
|
propertyPath: m_LocalEulerAnglesHint.x
|
||||||
|
@ -12,7 +12,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 9055f72a604bc3f4ba01bc120f0643d2, type: 3}
|
m_Script: {fileID: 11500000, guid: 9055f72a604bc3f4ba01bc120f0643d2, type: 3}
|
||||||
m_Name: PlayerData
|
m_Name: PlayerData
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
<InvincibilityTime>k__BackingField: 3
|
<InvincibilityTime>k__BackingField: 300
|
||||||
<JumpHeight>k__BackingField: 5.3
|
<JumpHeight>k__BackingField: 5.3
|
||||||
<LaneSwitchSpeed>k__BackingField: 25
|
<LaneSwitchSpeed>k__BackingField: 25
|
||||||
<Speed>k__BackingField: 20
|
<Speed>k__BackingField: 20
|
||||||
|
@ -8,8 +8,7 @@ public class GameSession : MonoBehaviour,IResettable
|
|||||||
public static GameSession Instance { get; private set; }
|
public static GameSession Instance { get; private set; }
|
||||||
|
|
||||||
[SerializeField] private Player currentPlayer;
|
[SerializeField] private Player currentPlayer;
|
||||||
|
private IInputTranslator inputTranslator;
|
||||||
private InputTranslator<KeyBinding> InputTranslator;
|
|
||||||
|
|
||||||
private bool isSessionPaused = false;
|
private bool isSessionPaused = false;
|
||||||
private bool isInputAlreadyRestricted = false;
|
private bool isInputAlreadyRestricted = false;
|
||||||
@ -21,32 +20,39 @@ public class GameSession : MonoBehaviour,IResettable
|
|||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
InputTranslator.Tick();
|
inputTranslator.Tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Init()
|
private void Init()
|
||||||
{
|
{
|
||||||
InputTranslator = new InputTranslator<KeyBinding>();
|
if (ApplicationUtil.platform == RuntimePlatform.Android || ApplicationUtil.platform == RuntimePlatform.IPhonePlayer)
|
||||||
IBindingHolder<KeyBinding> holder = new KeyBindingHolder();
|
{
|
||||||
InputTranslator.Init(holder);
|
IBindingHolder<TouchBinding> touchHolder = new TouchBindingHolder();
|
||||||
|
inputTranslator = new InputTranslator<TouchBinding>(touchHolder);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IBindingHolder<KeyBinding> keyHolder = new KeyBindingHolder();
|
||||||
|
inputTranslator = new InputTranslator<KeyBinding>(keyHolder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddCommandTranslator(ICommandTranslator translator)
|
public void AddCommandTranslator(ICommandTranslator translator)
|
||||||
{
|
{
|
||||||
InputTranslator.AddCommandTranslator(translator);
|
inputTranslator.AddCommandTranslator(translator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void PauseSession(bool isPaused)
|
public void PauseSession(bool isPaused)
|
||||||
{
|
{
|
||||||
Time.timeScale = isPaused ? 0 : 1;
|
Time.timeScale = isPaused ? 0 : 1;
|
||||||
if (!isSessionPaused && InputTranslator.IsTranslationResticted(InputConstants.InGameCommands))
|
if (!isSessionPaused && inputTranslator.IsTranslationResticted(InputConstants.InGameCommands))
|
||||||
{
|
{
|
||||||
isInputAlreadyRestricted = true;
|
isInputAlreadyRestricted = true;
|
||||||
isSessionPaused = isPaused;
|
isSessionPaused = isPaused;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!InputTranslator.IsTranslationResticted(InputConstants.InGameCommands))
|
if (!inputTranslator.IsTranslationResticted(InputConstants.InGameCommands))
|
||||||
{
|
{
|
||||||
isInputAlreadyRestricted = false;
|
isInputAlreadyRestricted = false;
|
||||||
}
|
}
|
||||||
@ -60,13 +66,15 @@ public class GameSession : MonoBehaviour,IResettable
|
|||||||
|
|
||||||
public void RestrictInputs(List<ECommand> commands,bool isRestricted)
|
public void RestrictInputs(List<ECommand> commands,bool isRestricted)
|
||||||
{
|
{
|
||||||
InputTranslator.RestictTranslation(commands, isRestricted);
|
inputTranslator.RestictTranslation(commands, isRestricted);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RestartSession()
|
public void RestartSession()
|
||||||
{
|
{
|
||||||
SceneManager.LoadScene("GameScene", LoadSceneMode.Single);
|
SceneManager.LoadScene("GameScene", LoadSceneMode.Single);
|
||||||
ResetToDefault();
|
ResetToDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GoToMainMenu()
|
public void GoToMainMenu()
|
||||||
{
|
{
|
||||||
SceneManager.LoadScene("MainMenu", LoadSceneMode.Single);
|
SceneManager.LoadScene("MainMenu", LoadSceneMode.Single);
|
||||||
|
24
Assets/Scripts/Input/BindableHolders/TouchBindingHolder.cs
Normal file
24
Assets/Scripts/Input/BindableHolders/TouchBindingHolder.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
|
||||||
|
public class TouchBindingHolder : IBindingHolder<TouchBinding>
|
||||||
|
{
|
||||||
|
public Dictionary<ECommand, TouchBinding> InputBindings { get; private set; }
|
||||||
|
|
||||||
|
private readonly Dictionary<ECommand, TouchBinding> DefaultTouchBindings = new Dictionary<ECommand, TouchBinding>
|
||||||
|
{
|
||||||
|
{ECommand.NONE, new TouchBinding(ETouchGesture.NONE)},
|
||||||
|
{ECommand.DOWN, new TouchBinding(ETouchGesture.SWIPE_DOWN)},
|
||||||
|
{ECommand.UP, new TouchBinding(ETouchGesture.SWIPE_UP)},
|
||||||
|
{ECommand.LEFT, new TouchBinding(ETouchGesture.SWIPE_LEFT)},
|
||||||
|
{ECommand.RIGHT, new TouchBinding(ETouchGesture.SWIPE_RIGHT)},
|
||||||
|
};
|
||||||
|
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
if (InputBindings == null)
|
||||||
|
InputBindings = DefaultTouchBindings;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 23353de203a94c447af7be38973acc1d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -3,7 +3,7 @@ using UnityEngine;
|
|||||||
|
|
||||||
public interface IBinding
|
public interface IBinding
|
||||||
{
|
{
|
||||||
public bool IsPressed { get; }
|
public bool IsPressed();
|
||||||
public bool IsReleased { get; }
|
public bool IsReleased();
|
||||||
public bool IsRestricted { get; set; }
|
public bool IsRestricted { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,6 @@ public class KeyBinding : IBinding
|
|||||||
{
|
{
|
||||||
private KeyCode keyBinding;
|
private KeyCode keyBinding;
|
||||||
private KeyCode alternativeKeyBinding;
|
private KeyCode alternativeKeyBinding;
|
||||||
public bool IsPressed => Input.GetKeyDown(keyBinding) || Input.GetKeyDown(alternativeKeyBinding);
|
|
||||||
public bool IsReleased => Input.GetKeyUp(keyBinding) || Input.GetKeyUp(alternativeKeyBinding);
|
|
||||||
public bool IsRestricted { get; set; }
|
public bool IsRestricted { get; set; }
|
||||||
|
|
||||||
public KeyBinding(KeyCode key,KeyCode alternative = KeyCode.None)
|
public KeyBinding(KeyCode key,KeyCode alternative = KeyCode.None)
|
||||||
@ -24,4 +22,14 @@ public class KeyBinding : IBinding
|
|||||||
keyBinding = key;
|
keyBinding = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsReleased()
|
||||||
|
{
|
||||||
|
return Input.GetKeyUp(keyBinding) || Input.GetKeyUp(alternativeKeyBinding);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsPressed()
|
||||||
|
{
|
||||||
|
return Input.GetKeyDown(keyBinding) || Input.GetKeyDown(alternativeKeyBinding);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
127
Assets/Scripts/Input/Bindings/TouchBinding.cs
Normal file
127
Assets/Scripts/Input/Bindings/TouchBinding.cs
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public enum ETouchGesture
|
||||||
|
{
|
||||||
|
NONE,
|
||||||
|
TAP,
|
||||||
|
SWIPE_LEFT,
|
||||||
|
SWIPE_RIGHT,
|
||||||
|
SWIPE_UP,
|
||||||
|
SWIPE_DOWN
|
||||||
|
}
|
||||||
|
public class TouchBinding : IBinding
|
||||||
|
{
|
||||||
|
private ETouchGesture wantedTouchGesture;
|
||||||
|
private ETouchGesture actualGesture;
|
||||||
|
private bool isDragging = false;
|
||||||
|
private int swipeThreshold = 100;
|
||||||
|
private Vector2 startTouch;
|
||||||
|
private Vector2 swipeDelta;
|
||||||
|
|
||||||
|
public bool IsPressed()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (wantedTouchGesture == ETouchGesture.NONE)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ReadGesture();
|
||||||
|
|
||||||
|
if (actualGesture == wantedTouchGesture)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsReleased()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsRestricted { get; set; }
|
||||||
|
|
||||||
|
public TouchBinding(ETouchGesture gesture)
|
||||||
|
{
|
||||||
|
wantedTouchGesture = gesture;
|
||||||
|
IsRestricted = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReadGesture()
|
||||||
|
{
|
||||||
|
actualGesture = ETouchGesture.NONE;
|
||||||
|
|
||||||
|
#region ForPC
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
if (Input.GetMouseButtonDown(0))
|
||||||
|
{
|
||||||
|
actualGesture = ETouchGesture.TAP;
|
||||||
|
isDragging = true;
|
||||||
|
startTouch = Input.mousePosition;
|
||||||
|
}
|
||||||
|
else if (Input.GetMouseButtonUp(0))
|
||||||
|
{
|
||||||
|
isDragging = false;
|
||||||
|
actualGesture = ETouchGesture.NONE;
|
||||||
|
Reset();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
if (Input.touches.Length > 0)
|
||||||
|
{
|
||||||
|
if (Input.touches[0].phase == TouchPhase.Began)
|
||||||
|
{
|
||||||
|
actualGesture = ETouchGesture.TAP;
|
||||||
|
isDragging = true;
|
||||||
|
startTouch = Input.touches[0].position;
|
||||||
|
}
|
||||||
|
else if (Input.touches[0].phase == TouchPhase.Ended || Input.touches[0].phase == TouchPhase.Canceled)
|
||||||
|
{
|
||||||
|
isDragging = false;
|
||||||
|
Reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
swipeDelta = Vector2.zero;
|
||||||
|
if (isDragging)
|
||||||
|
{
|
||||||
|
if (Input.touches.Length < 0)
|
||||||
|
swipeDelta = Input.touches[0].position - startTouch;
|
||||||
|
else if (Input.GetMouseButton(0))
|
||||||
|
swipeDelta = (Vector2)Input.mousePosition - startTouch;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (swipeDelta.magnitude > swipeThreshold)
|
||||||
|
{
|
||||||
|
float x = swipeDelta.x;
|
||||||
|
float y = swipeDelta.y;
|
||||||
|
if (Mathf.Abs(x) > Mathf.Abs(y))
|
||||||
|
{
|
||||||
|
|
||||||
|
if (x < 0)
|
||||||
|
actualGesture = ETouchGesture.SWIPE_LEFT;
|
||||||
|
else
|
||||||
|
actualGesture = ETouchGesture.SWIPE_RIGHT;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
if (y < 0)
|
||||||
|
actualGesture = ETouchGesture.SWIPE_DOWN;
|
||||||
|
else
|
||||||
|
actualGesture = ETouchGesture.SWIPE_UP;
|
||||||
|
}
|
||||||
|
Reset();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Reset()
|
||||||
|
{
|
||||||
|
startTouch = swipeDelta = Vector2.zero;
|
||||||
|
isDragging = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
11
Assets/Scripts/Input/Bindings/TouchBinding.cs.meta
Normal file
11
Assets/Scripts/Input/Bindings/TouchBinding.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6aea6c10fce13c64f924ba743d8f421b
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -1,16 +1,34 @@
|
|||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
public class InputTranslator<T> where T : IBinding
|
|
||||||
|
public interface IInputTranslator
|
||||||
|
{
|
||||||
|
//public void Init(IBindingHolder<T> holder);
|
||||||
|
public void AddCommandTranslator(ICommandTranslator translator);
|
||||||
|
public void RemoveCommandTranslator(ICommandTranslator translator);
|
||||||
|
public void RestictTranslation(List<ECommand> commands, bool isRestricted);
|
||||||
|
|
||||||
|
public bool IsTranslationResticted(List<ECommand> commands);
|
||||||
|
|
||||||
|
public void Tick();
|
||||||
|
}
|
||||||
|
public class InputTranslator<T> : IInputTranslator where T : IBinding
|
||||||
{
|
{
|
||||||
private List<ICommandTranslator> commandTranslators;
|
private List<ICommandTranslator> commandTranslators;
|
||||||
private IBindingHolder<T> bindingHolder;
|
private IBindingHolder<T> bindingHolder;
|
||||||
|
|
||||||
public void Init(IBindingHolder<T> holder)
|
public InputTranslator(IBindingHolder<T> holder)
|
||||||
{
|
{
|
||||||
commandTranslators = new List<ICommandTranslator>();
|
commandTranslators = new List<ICommandTranslator>();
|
||||||
bindingHolder = holder;
|
bindingHolder = holder;
|
||||||
bindingHolder.Init();
|
bindingHolder.Init();
|
||||||
}
|
}
|
||||||
|
//public void Init(IBindingHolder<T> holder)
|
||||||
|
//{
|
||||||
|
// commandTranslators = new List<ICommandTranslator>();
|
||||||
|
// bindingHolder = holder;
|
||||||
|
// bindingHolder.Init();
|
||||||
|
//}
|
||||||
|
|
||||||
public void AddCommandTranslator(ICommandTranslator translator)
|
public void AddCommandTranslator(ICommandTranslator translator)
|
||||||
{
|
{
|
||||||
@ -60,10 +78,10 @@ public class InputTranslator<T> where T : IBinding
|
|||||||
{
|
{
|
||||||
if (keyBinding.Value.IsRestricted)
|
if (keyBinding.Value.IsRestricted)
|
||||||
continue;
|
continue;
|
||||||
if (keyBinding.Value.IsPressed)
|
if (keyBinding.Value.IsPressed())
|
||||||
commands.Add(keyBinding.Key, new PressedState(keyBinding.Value.IsPressed, keyBinding.Value.IsReleased));
|
commands.Add(keyBinding.Key, new PressedState(true, false));
|
||||||
if (keyBinding.Value.IsReleased)
|
if (keyBinding.Value.IsReleased())
|
||||||
commands.Add(keyBinding.Key, new PressedState(keyBinding.Value.IsPressed, keyBinding.Value.IsReleased));
|
commands.Add(keyBinding.Key, new PressedState(false, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commands.Count == 0)
|
if (commands.Count == 0)
|
||||||
|
21
Assets/Scripts/Utils/ApplicationUtil.cs
Normal file
21
Assets/Scripts/Utils/ApplicationUtil.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class ApplicationUtil
|
||||||
|
{
|
||||||
|
public static RuntimePlatform platform
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
#if UNITY_ANDROID
|
||||||
|
return RuntimePlatform.Android;
|
||||||
|
#elif UNITY_IOS
|
||||||
|
return RuntimePlatform.IPhonePlayer;
|
||||||
|
#elif UNITY_STANDALONE_OSX
|
||||||
|
return RuntimePlatform.OSXPlayer;
|
||||||
|
#elif UNITY_STANDALONE_WIN
|
||||||
|
return RuntimePlatform.WindowsPlayer;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/Utils/ApplicationUtil.cs.meta
Normal file
11
Assets/Scripts/Utils/ApplicationUtil.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: dc32e4a16f3dd1540b5208d59de19e2c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
14
ProjectSettings/BurstAotSettings_Android.json
Normal file
14
ProjectSettings/BurstAotSettings_Android.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"MonoBehaviour": {
|
||||||
|
"Version": 4,
|
||||||
|
"EnableBurstCompilation": true,
|
||||||
|
"EnableOptimisations": true,
|
||||||
|
"EnableSafetyChecks": false,
|
||||||
|
"EnableDebugInAllBuilds": false,
|
||||||
|
"CpuMinTargetX32": 0,
|
||||||
|
"CpuMaxTargetX32": 0,
|
||||||
|
"CpuMinTargetX64": 0,
|
||||||
|
"CpuMaxTargetX64": 0,
|
||||||
|
"OptimizeFor": 0
|
||||||
|
}
|
||||||
|
}
|
@ -12,12 +12,12 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 13964, guid: 0000000000000000e000000000000000, type: 0}
|
m_Script: {fileID: 13964, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
m_EnablePreReleasePackages: 0
|
m_EnablePreReleasePackages: 1
|
||||||
m_EnablePackageDependencies: 0
|
m_EnablePackageDependencies: 0
|
||||||
m_AdvancedSettingsExpanded: 1
|
m_AdvancedSettingsExpanded: 1
|
||||||
m_ScopedRegistriesSettingsExpanded: 1
|
m_ScopedRegistriesSettingsExpanded: 1
|
||||||
m_SeeAllPackageVersions: 0
|
m_SeeAllPackageVersions: 0
|
||||||
oneTimeWarningShown: 0
|
oneTimeWarningShown: 1
|
||||||
m_Registries:
|
m_Registries:
|
||||||
- m_Id: main
|
- m_Id: main
|
||||||
m_Name:
|
m_Name:
|
||||||
|
@ -68,7 +68,7 @@ PlayerSettings:
|
|||||||
androidRenderOutsideSafeArea: 1
|
androidRenderOutsideSafeArea: 1
|
||||||
androidUseSwappy: 1
|
androidUseSwappy: 1
|
||||||
androidBlitType: 0
|
androidBlitType: 0
|
||||||
androidResizableWindow: 0
|
androidResizableWindow: 1
|
||||||
androidDefaultWindowWidth: 1920
|
androidDefaultWindowWidth: 1920
|
||||||
androidDefaultWindowHeight: 1080
|
androidDefaultWindowHeight: 1080
|
||||||
androidMinimumWindowWidth: 400
|
androidMinimumWindowWidth: 400
|
||||||
@ -154,7 +154,8 @@ PlayerSettings:
|
|||||||
resetResolutionOnWindowResize: 0
|
resetResolutionOnWindowResize: 0
|
||||||
androidSupportedAspectRatio: 1
|
androidSupportedAspectRatio: 1
|
||||||
androidMaxAspectRatio: 2.1
|
androidMaxAspectRatio: 2.1
|
||||||
applicationIdentifier: {}
|
applicationIdentifier:
|
||||||
|
Android: com.DefaultCompany.AwesomeRunner
|
||||||
buildNumber:
|
buildNumber:
|
||||||
Standalone: 0
|
Standalone: 0
|
||||||
iPhone: 0
|
iPhone: 0
|
||||||
@ -413,7 +414,7 @@ PlayerSettings:
|
|||||||
m_BuildTargetGraphicsAPIs:
|
m_BuildTargetGraphicsAPIs:
|
||||||
- m_BuildTarget: AndroidPlayer
|
- m_BuildTarget: AndroidPlayer
|
||||||
m_APIs: 0b00000008000000
|
m_APIs: 0b00000008000000
|
||||||
m_Automatic: 0
|
m_Automatic: 1
|
||||||
- m_BuildTarget: iOSSupport
|
- m_BuildTarget: iOSSupport
|
||||||
m_APIs: 10000000
|
m_APIs: 10000000
|
||||||
m_Automatic: 1
|
m_Automatic: 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user