Skip to content

Commit

Permalink
migrate to use input system
Browse files Browse the repository at this point in the history
  • Loading branch information
voidf committed Jul 20, 2023
1 parent 07ce2ac commit 899a666
Show file tree
Hide file tree
Showing 21 changed files with 1,327 additions and 138 deletions.
125 changes: 125 additions & 0 deletions Assets/Prefab/hero.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ GameObject:
- component: {fileID: 8425220715333947331}
- component: {fileID: 2265433074758437570}
- component: {fileID: 8411979683909697343}
- component: {fileID: 7684051673031476508}
- component: {fileID: 7955639450026482950}
m_Layer: 0
m_Name: hero
m_TagString: Untagged
Expand Down Expand Up @@ -398,7 +400,130 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1ca47003ad4a29d46811157a863b40cd, type: 3}
m_Name:
m_EditorClassIdentifier:
PlayerID: 0
default_weapon_prefab: {fileID: 2112534196463791616, guid: 02636af39f6cf9347958eab97e329dda, type: 3}
horizontal_accelare: 5
horizontal_velocity_limit: 10
floating_jump_cnt_limit: 1
--- !u!114 &7684051673031476508
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8096651696447350411}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 62899f850307741f2a39c98a8b639597, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Actions: {fileID: -944628639613478452, guid: b8f482daefa7e51459723d06e6f57146, type: 3}
m_NotificationBehavior: 2
m_UIInputModule: {fileID: 0}
m_DeviceLostEvent:
m_PersistentCalls:
m_Calls: []
m_DeviceRegainedEvent:
m_PersistentCalls:
m_Calls: []
m_ControlsChangedEvent:
m_PersistentCalls:
m_Calls: []
m_ActionEvents:
- m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 7955639450026482950}
m_TargetAssemblyTypeName: InputSystemBridge, Assembly-CSharp
m_MethodName: Down
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_ActionId: 12409e67-8435-4dcd-b859-d40a69425413
m_ActionName: Movement/Down[/Keyboard/s,/Keyboard/downArrow]
- m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 7955639450026482950}
m_TargetAssemblyTypeName: InputSystemBridge, Assembly-CSharp
m_MethodName: Jump
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_ActionId: aae125ec-1711-4b09-968d-ee1244f49681
m_ActionName: Movement/Jump[/Keyboard/space,/Keyboard/w,/Keyboard/upArrow]
- m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 7955639450026482950}
m_TargetAssemblyTypeName: InputSystemBridge, Assembly-CSharp
m_MethodName: Horizontal
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_ActionId: 8820f35d-415a-464b-814d-a011e570be6d
m_ActionName: Movement/Horizontal[/Keyboard/a,/Keyboard/d,/Keyboard/leftArrow,/Keyboard/rightArrow]
- m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 7955639450026482950}
m_TargetAssemblyTypeName: InputSystemBridge, Assembly-CSharp
m_MethodName: Fire
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_ActionId: 2225bd57-3ba5-4f7d-b383-21b55cf84e5d
m_ActionName: Movement/Fire[/Keyboard/j,/Keyboard/period]
- m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 7955639450026482950}
m_TargetAssemblyTypeName: InputSystemBridge, Assembly-CSharp
m_MethodName: Bomb
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_ActionId: 254dfb2d-2976-4096-8120-ca620a8a0827
m_ActionName: Movement/Bomb[/Keyboard/k,/Keyboard/slash]
m_NeverAutoSwitchControlSchemes: 0
m_DefaultControlScheme:
m_DefaultActionMap: Movement
m_SplitScreenIndex: -1
m_Camera: {fileID: 0}
--- !u!114 &7955639450026482950
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8096651696447350411}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 44a0119a67ae5074f94dded2a2140a5c, type: 3}
m_Name:
m_EditorClassIdentifier:
92 changes: 46 additions & 46 deletions Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ GameObject:
m_Component:
- component: {fileID: 407847810}
- component: {fileID: 407847809}
- component: {fileID: 407847811}
m_Layer: 0
m_Name: JoiningSceneManager
m_TagString: Untagged
Expand All @@ -147,7 +148,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 407847808}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3f9cf27d4c7f91644a096ef84ce41e72, type: 3}
m_Name:
Expand All @@ -169,6 +170,50 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &407847811
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 407847808}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 621567455fd1c4ceb811cc8a00b6a1a5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_NotificationBehavior: 0
m_MaxPlayerCount: -1
m_AllowJoining: 1
m_JoinBehavior: 0
m_PlayerJoinedEvent:
m_PersistentCalls:
m_Calls: []
m_PlayerLeftEvent:
m_PersistentCalls:
m_Calls: []
m_JoinAction:
m_UseReference: 0
m_Action:
m_Name:
m_Type: 0
m_ExpectedControlType:
m_Id:
m_Processors:
m_Interactions:
m_SingletonActionBindings: []
m_Flags: 0
m_Reference: {fileID: 0}
m_PlayerPrefab: {fileID: 8096651696447350411, guid: 589973631ae32a2409fe3c5dc77c8974, type: 3}
m_SplitScreen: 0
m_MaintainAspectRatioInSplitScreen: 0
m_FixedNumberOfSplitScreens: -1
m_SplitScreenRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
--- !u!1 &512850202
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -200,8 +245,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6442dc8070ceb41f094e44de0bf87274, type: 3}
m_Name:
m_EditorClassIdentifier:
offsetX: 0
offsetY: 0
--- !u!114 &512850204
MonoBehaviour:
m_ObjectHideFlags: 0
Expand All @@ -214,23 +257,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6b0fecffa3f624585964b0d0eb21b18e, type: 3}
m_Name:
m_EditorClassIdentifier:
port: 7777
DualMode: 1
NoDelay: 1
Interval: 10
Timeout: 10000
RecvBufferSize: 7361536
SendBufferSize: 7361536
FastResend: 2
ReceiveWindowSize: 4096
SendWindowSize: 4096
MaxRetransmit: 40
MaximizeSocketBuffers: 1
ReliableMaxMessageSize: 297433
UnreliableMaxMessageSize: 1195
debugLog: 0
statisticsGUI: 0
statisticsLog: 0
--- !u!114 &512850205
MonoBehaviour:
m_ObjectHideFlags: 0
Expand All @@ -243,32 +269,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 8aab4c8111b7c411b9b92cf3dbc5bd4e, type: 3}
m_Name:
m_EditorClassIdentifier:
dontDestroyOnLoad: 1
runInBackground: 1
autoStartServerBuild: 1
autoConnectClientBuild: 0
sendRate: 30
offlineScene: Assets/Scenes/SampleScene.unity
onlineScene: Assets/Scenes/SampleScene.unity
transport: {fileID: 0}
networkAddress: localhost
maxConnections: 100
authenticator: {fileID: 0}
playerPrefab: {fileID: 0}
autoCreatePlayer: 1
playerSpawnMethod: 0
spawnPrefabs: []
snapshotSettings:
bufferTimeMultiplier: 2
catchupNegativeThreshold: -1
catchupPositiveThreshold: 1
catchupSpeed: 0.019999999552965164
slowdownSpeed: 0.03999999910593033
driftEmaDuration: 1
dynamicAdjustment: 1
dynamicAdjustmentTolerance: 1
deliveryTimeEmaDuration: 2
timeInterpolationGui: 0
--- !u!4 &512850206
Transform:
m_ObjectHideFlags: 0
Expand Down
79 changes: 79 additions & 0 deletions Assets/Script/InputController/InputSystemBridge.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.InputSystem;

public class InputSystemBridge : MonoBehaviour
{
private PlayerInput _playerInput;

private PlayerPhysicalController _physicalCtrl;

// Start is called before the first frame update
private void Awake()
{
_playerInput = GetComponent<PlayerInput>();
//var PlayerControllers = FindObjectsOfType<PlayerPhysicalController>();
_physicalCtrl = GetComponent<PlayerPhysicalController>();
//_physicalCtrl = PlayerControllers.FirstOrDefault(m => m.GetPlayerID() == _playerInput.playerIndex);
Debug.Log("GOT CTRL " + _physicalCtrl);
}

public void Horizontal(InputAction.CallbackContext context)
{
//if (_physicalCtrl != null)
//{
var v = context.ReadValue<float>();
Debug.Log("Horizontal" + v);
_physicalCtrl.ctrl.SetHorizon(v);
//}
}
// 触发
public void Jump(InputAction.CallbackContext context)
{
if (_physicalCtrl != null)
{
Debug.Log("Jump" + context);
_physicalCtrl.ctrl.SetUp(); // 触发操作,所以不判回弹
}
}

public void Down(InputAction.CallbackContext context)
{
if (_physicalCtrl != null)
{
Debug.Log("Down" + context);
_physicalCtrl.ctrl.SetDown(); // 触发操作,所以不判回弹
}
}

// 长压
public void Fire(InputAction.CallbackContext context)
{
if (_physicalCtrl != null)
{
int is_fire = context.ReadValue<int>();
Debug.Log("Fire" + context + is_fire);
if (is_fire > 0)
_physicalCtrl.ctrl.SetFire();
else
_physicalCtrl.ctrl.UnsetFire();
}
}

public void Bomb(InputAction.CallbackContext context)
{
if (_physicalCtrl != null)
{
int is_bomb = context.ReadValue<int>();
Debug.Log("Bomb" + context + is_bomb);
if (is_bomb > 0)
_physicalCtrl.ctrl.SetBomb();
else
_physicalCtrl.ctrl.UnsetBomb();
}
}


}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Assets/Script/InputController/JoyStickInputController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public JoyStickInputController(int id, string name)
static KeyCode KC(int id, int k) => (KeyCode)(k + joystick_offset + (id-1) * joystick_num_offset);

// 开火键测试,长押开火键加入
public static bool JoinKeyDownTest(int id) { return Input.GetKeyDown(KC(id, fire)); }
public static bool JoinKeyUpTest(int id) { return Input.GetKeyUp(KC(id, fire)); }
public static bool JoinKeyDownTest(int id) { return Input.GetButtonDown($"joystick {id} button {fire}"); }
public static bool JoinKeyUpTest(int id) { return Input.GetButtonUp($"joystick {id} button {fire}"); }


public override void OnLogicFrameUpdate()
{
Expand Down
Loading

0 comments on commit 899a666

Please sign in to comment.