Added VR/Keyboard input controls

This commit is contained in:
r.nikolin 2023-10-18 11:59:26 +03:00
parent 20f6616987
commit 15218a6698
23 changed files with 667 additions and 253 deletions

View File

@ -973,6 +973,98 @@
"isPartOfComposite": false
}
]
},
{
"name": "Keyboard",
"id": "1acadf6d-d4ac-4c4e-b174-acd7e9df043e",
"actions": [
{
"name": "Boost",
"type": "PassThrough",
"id": "49c8b27f-b628-48a1-b5ed-78c2c8bb590b",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Horizontal",
"type": "PassThrough",
"id": "fdf561df-291a-4904-9d76-72ceff940a0b",
"expectedControlType": "Vector2",
"processors": "",
"interactions": "",
"initialStateCheck": false
}
],
"bindings": [
{
"name": "",
"id": "c8fddc38-1058-4d94-90b1-5b16028ddc55",
"path": "<Keyboard>/w",
"interactions": "",
"processors": "",
"groups": "",
"action": "Boost",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "2D Vector",
"id": "497d5b14-d58e-4e45-8ad5-f9e9091ed1f2",
"path": "2DVector",
"interactions": "",
"processors": "",
"groups": "",
"action": "Horizontal",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "up",
"id": "22075d35-d4b8-4783-aabd-5c45d1a6b740",
"path": "",
"interactions": "",
"processors": "",
"groups": "",
"action": "Horizontal",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "down",
"id": "1b79a88f-966c-4f20-a344-619cd41985d4",
"path": "",
"interactions": "",
"processors": "",
"groups": "",
"action": "Horizontal",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "left",
"id": "e0cc3fda-02af-405f-b820-585887e0ec14",
"path": "<Keyboard>/a",
"interactions": "",
"processors": "",
"groups": "",
"action": "Horizontal",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "right",
"id": "ab4e5871-c251-4a44-8459-d155c6104b08",
"path": "<Keyboard>/d",
"interactions": "",
"processors": "",
"groups": "",
"action": "Horizontal",
"isComposite": false,
"isPartOfComposite": true
}
]
}
],
"controlSchemes": [

View File

@ -538,6 +538,9 @@ namespace BNG {
public void ForceRelease()
{
if (heldByGrabbers == null)
return;
for (int x = 0; x < heldByGrabbers.Count; x++)
{
Grabber g = heldByGrabbers[x];

View File

@ -0,0 +1,31 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
[CreateAssetMenu(fileName = "KeyboardInput", menuName = "PlayerInput/KeyboardInput")]
public class KeyboardPlayerInput : PlayerInputReference
{
public InputActionReference BoostInput;
public InputActionReference HorizontalInput;
private DeviceDisconnectController deviceDisconnect;
public override bool Boost()
{
Debug.Log($"{BoostInput}:{BoostInput.action}:{BoostInput.action.inProgress}");
return BoostInput.action.inProgress;
}
public override float Horizontal()
{
return -HorizontalInput.action.ReadValue<Vector2>().x;
}
public override void Init()
{
GameManager.Instance.OnStartGame();
deviceDisconnect = FindObjectOfType<DeviceDisconnectController>();
deviceDisconnect.enabled = false;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 586e1d639c330f84e941a1856c366a37
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
Assets/PlayerInput.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: afb280d878a77ae4cb4aceeebce90110
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,18 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 586e1d639c330f84e941a1856c366a37, type: 3}
m_Name: KeyboardInput
m_EditorClassIdentifier:
BoostInput: {fileID: -1146683932412500244, guid: e39f4b35a6db18348b41eb0262520e69,
type: 3}
HorizontalInput: {fileID: 6310607998171100063, guid: e39f4b35a6db18348b41eb0262520e69,
type: 3}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 82105cbfaf0c0434eb43067cf6fdff9c
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,18 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: cda07857e7c29264cb9fd3d037c09c94, type: 3}
m_Name: VRInput
m_EditorClassIdentifier:
LeftTrigger: {fileID: -5982496924579745919, guid: e39f4b35a6db18348b41eb0262520e69,
type: 3}
RightTrigger: {fileID: 83097790271614945, guid: e39f4b35a6db18348b41eb0262520e69,
type: 3}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 304e51c4c6ea6da44bdd2105828d9cec
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,23 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerInputHandler : MonoBehaviour
{
[SerializeField]
private PlayerInputReference _playerInput;
public bool Boost => _playerInput.Boost();
public float Horizontal => _playerInput.Horizontal();
private void Awake()
{
Init();
}
private void Init()
{
_playerInput.Init();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0afcff33d501c7a4f8bccfed2ec0d516
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class PlayerInputReference : ScriptableObject
{
public abstract bool Boost();
public abstract float Horizontal();
public abstract void Init();
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8780c7e83a360cd4b97fe7c76b59c7c7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -2167,19 +2167,7 @@ MonoBehaviour:
m_Calls: []
onValueChange:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 4574774227375387068}
m_TargetAssemblyTypeName: ShipMoveSides, Assembly-CSharp
m_MethodName: UpdateInput
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_Calls: []
ShowEditorGizmos: 1
--- !u!114 &4574774226773336104
MonoBehaviour:
@ -2261,6 +2249,7 @@ MonoBehaviour:
m_BoolArgument: 1
m_CallState: 2
StartActive: 0
Active: 0
--- !u!95 &8265706549432649492
Animator:
serializedVersion: 4
@ -2767,6 +2756,7 @@ GameObject:
- component: {fileID: 4574774227375387068}
- component: {fileID: 5885267486567841784}
- component: {fileID: 5885267486567841781}
- component: {fileID: 3467886818215254708}
m_Layer: 9
m_Name: Classic Hovership (Arcade)
m_TagString: Untagged
@ -2930,10 +2920,6 @@ MonoBehaviour:
brakeSpeed: 1
brakeReleaseSpeed: 0.5
soundFadeLength: 0.15
LeftTrigger: {fileID: -5982496924579745919, guid: e39f4b35a6db18348b41eb0262520e69,
type: 3}
RightTrigger: {fileID: 83097790271614945, guid: e39f4b35a6db18348b41eb0262520e69,
type: 3}
OnSpeedChange:
m_PersistentCalls:
m_Calls:
@ -2970,6 +2956,19 @@ MonoBehaviour:
SpeedPercent: 0
_boostBreakSpeed: 5
IsBot: 0
--- !u!114 &3467886818215254708
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4574774227375387060}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0afcff33d501c7a4f8bccfed2ec0d516, type: 3}
m_Name:
m_EditorClassIdentifier:
_playerInput: {fileID: 11400000, guid: 304e51c4c6ea6da44bdd2105828d9cec, type: 2}
--- !u!1 &4898943821327698614
GameObject:
m_ObjectHideFlags: 0

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -40,6 +40,7 @@ public class PlayerSetup : MonoBehaviour
public void AddPlayerScore(int score)
{
if (_currentPlayer != null)
_currentPlayer.Score += score;
}

View File

@ -17,12 +17,18 @@ public class ShipMoveSides : MonoBehaviour
private bool _isEnable = true;
private ShipPathFollower _pathFollower;
private PlayerInputHandler _playerInput;
private void Awake()
{
_pathFollower = GetComponent<ShipPathFollower>();
}
private void Start()
{
_playerInput = GetComponent<PlayerInputHandler>();
}
public float Radius => _radius;
private void Update()
@ -72,6 +78,9 @@ public class ShipMoveSides : MonoBehaviour
private void ApplyMovement()
{
if (_playerInput != null)
_value = -_playerInput.Horizontal;
var newPos = transform.localPosition + _value * Vector3.right;
newPos.x = Mathf.Clamp(newPos.x, -_radius, _radius);

View File

@ -29,10 +29,6 @@ public class ShipPathFollower : MonoBehaviour, ITextChangable
private float addForce = 0f;
public float soundFadeLength = 0.15f;
public InputActionReference LeftTrigger;
public InputActionReference RightTrigger;
public UnityEvent<object> OnTextChange => _OnTextChange;
private UnityEvent<object> _OnTextChange = new UnityEvent<object>();
@ -43,16 +39,24 @@ public class ShipPathFollower : MonoBehaviour, ITextChangable
public float SpeedPercent;
private float _boostSpeed;
[SerializeField] private float _boostBreakSpeed;
[SerializeField]
private float _boostBreakSpeed;
private PlayerInputHandler playerInput;
public bool IsBot = false;
// Update is called once per frame
private void Start()
{
playerInput = GetComponent<PlayerInputHandler>();
}
void Update()
{
if (_isCutsceneMovement)
return;
if (!IsBot && (Input.GetKey(KeyCode.W) || RightTrigger.action.inProgress && LeftTrigger.action.inProgress))
if (!IsBot && playerInput.Boost)
{
AddForce(1);
}
@ -126,9 +130,6 @@ public class ShipPathFollower : MonoBehaviour, ITextChangable
public void AddForce(float amount)
{
addForce = amount;
if (!IsBot)
addForce *= RightTrigger.action.ReadValue<float>() * LeftTrigger.action.ReadValue<float>();
}
private bool _isCutsceneMovement = false;

View File

@ -14,7 +14,7 @@ public class WheelActivator : MonoBehaviour
public bool StartActive = false;
private bool _isActive = false;
public bool Active = false;
private void Awake()
{
@ -26,16 +26,14 @@ public class WheelActivator : MonoBehaviour
private void Activate()
{
_isActive = true;
Active = true;
OnActivate?.Invoke();
Debug.Log("Activate");
}
private void Deactivate()
{
_isActive = false;
Active = false;
OnDeactivate?.Invoke();
Debug.Log("Deactivate");
}
public void TryActivate(Grabber grabber)

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,31 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
[CreateAssetMenu(fileName ="VRInput", menuName = "PlayerInput/VRInput")]
public class VRPlayerInputReference : PlayerInputReference
{
public InputActionReference LeftTrigger;
public InputActionReference RightTrigger;
private WheelActivator _wheelActivator;
private BNG.SteeringWheel _steeringWheel;
public override void Init()
{
_wheelActivator = FindObjectOfType<WheelActivator>();
_steeringWheel = FindObjectOfType<BNG.SteeringWheel>();
}
public override bool Boost()
{
return RightTrigger.action.inProgress && LeftTrigger.action.inProgress && _wheelActivator.Active;
}
public override float Horizontal()
{
return _steeringWheel.ScaleValue;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cda07857e7c29264cb9fd3d037c09c94
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: