Skip to content

Commit

Permalink
Merge pull request #20 from aaasoft/main
Browse files Browse the repository at this point in the history
增加小米蓝牙手柄的支持
  • Loading branch information
aaasoft authored Jan 11, 2024
2 parents 308add8 + e48004f commit 91314eb
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 177 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Ballance.app
Output.apk
OutputDebug
Adobe After Effects 自动保存/

.vscode/
*.hkt
Ballance.sln
.vsconfig
54 changes: 0 additions & 54 deletions .vscode/launch.json

This file was deleted.

55 changes: 0 additions & 55 deletions .vscode/settings.json

This file was deleted.

2 changes: 1 addition & 1 deletion Assets/Game/Common/Materials/Game/SkyLayer.mat
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Material:
- _MainTex:
m_Texture: {fileID: 2800000, guid: 550bc03f31e06d54e80a12103627045c, type: 3}
m_Scale: {x: 2, y: 2}
m_Offset: {x: 0.5282531, y: 0.05034268}
m_Offset: {x: 0.26713884, y: 0.7892295}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
Expand Down
7 changes: 2 additions & 5 deletions Assets/Game/GamePlay/Scripts/BallManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,8 @@ private void _InitKeys()
keyListener.AddKeyListen(keyRoateCamera, keyRoateCamera2, _Shift_Key);
keyListener.AddKeyListen(keyLeft, _LeftArrow_Key);
keyListener.AddKeyListen(keyRight, _RightArrow_Key);
//当检测到手柄时,则注册手柄相关按键
if (Input.GetJoystickNames().Length > 0)
{
keyListener.SetAxisListen(_AxisListen);
}
keyListener.SetAxisListen(_AxisListen);

//测试按扭
if (GameManager.DebugMode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ RenderTexture:
m_UseDynamicScale: 0
m_BindMS: 0
m_EnableCompatibleFormat: 1
m_EnableRandomWrite: 0
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
Expand Down
63 changes: 50 additions & 13 deletions Assets/System/Scripts/Services/InputManager/KeyListener.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

/*
* Copyright(c) 2021 mengyu
Expand Down Expand Up @@ -37,6 +40,13 @@ namespace Ballance2.Services.InputManager
/// </summary>
public class KeyListener : MonoBehaviour
{
private Gamepad currentGamepad;
private Joystick currentJoystick;
private DpadControl currentJoystickDpad;
private ButtonControl currentJoystickRightStickButton2;
private ButtonControl currentJoystickRightStickButton4;
private AxisControl currentJoystickRightStickAxisY;

/// <summary>
/// 键盘按键事件回调
/// </summary>
Expand All @@ -47,7 +57,7 @@ public class KeyListener : MonoBehaviour
/// </summary>
/// <param name="x">轴名称</param>
/// <param name="y">轴值</param>
public delegate void AxisDelegate(string asisName,float value);
public delegate void AxisDelegate(string asisName, float value);

/// <summary>
/// 从 指定 GameObject 创建键事件侦听器
Expand Down Expand Up @@ -86,15 +96,6 @@ public enum MovementType
public const string AxisName_RightStickHorizontal = "RightStickHorizontal";
public const string AxisName_RightStickVertical = "RightStickVertical";
private AxisDelegate axisDelegate = null;
private string[] axisNames = new string[]
{
AxisName_Horizontal,
AxisName_Vertical,
AxisName_LeftStickHorizontal,
AxisName_LeftStickVertical,
AxisName_RightStickHorizontal,
AxisName_RightStickVertical
};

private LinkedList<KeyListenerItem> items = new LinkedList<KeyListenerItem>();
[SerializeField]
Expand All @@ -117,6 +118,19 @@ public enum MovementType
/// </summary>
public bool AllowMultipleKey = false;

public KeyListener()
{
currentGamepad = Gamepad.current;
currentJoystick = Joystick.current;
if (currentJoystick != null)
{
currentJoystickDpad = currentJoystick.children.FirstOrDefault(t => t is DpadControl) as DpadControl;
currentJoystickRightStickAxisY = currentJoystick.children.FirstOrDefault(t => t.path.EndsWith("rz")) as AxisControl;
var buttonControls = currentJoystick.children.Where(t => t is ButtonControl).Cast<ButtonControl>().ToArray();
currentJoystickRightStickButton2 = buttonControls.Skip(1).FirstOrDefault();
currentJoystickRightStickButton4 = buttonControls.Skip(3).FirstOrDefault();
}
}
/// <summary>
/// 重新发送当前已按下的按键事件
/// </summary>
Expand Down Expand Up @@ -236,7 +250,7 @@ public void ClearKeyListen()
{
items.Clear();
}

private void Update()
{
if (isListenKey)
Expand All @@ -246,8 +260,31 @@ private void Update()
return;
if (axisDelegate != null)
{
foreach (var asixName in axisNames)
axisDelegate(asixName, Input.GetAxisRaw(asixName));
if (currentGamepad != null)
{
axisDelegate(AxisName_Horizontal, currentGamepad.dpad.x.value);
axisDelegate(AxisName_Vertical, currentGamepad.dpad.y.value);
axisDelegate(AxisName_LeftStickHorizontal, currentGamepad.leftStick.x.value);
axisDelegate(AxisName_LeftStickVertical, currentGamepad.leftStick.y.value);
axisDelegate(AxisName_RightStickHorizontal, currentGamepad.rightStick.x.value);
axisDelegate(AxisName_RightStickVertical, currentGamepad.rightStick.y.value);
}
else if (currentJoystick != null)
{
axisDelegate(AxisName_LeftStickHorizontal, currentJoystick.stick.x.value);
axisDelegate(AxisName_LeftStickVertical, currentJoystick.stick.y.value);
if (currentJoystickDpad != null)
{
axisDelegate(AxisName_Horizontal, currentJoystickDpad.x.value);
axisDelegate(AxisName_Vertical, currentJoystickDpad.y.value);
}
if (currentJoystickRightStickButton2 != null)
axisDelegate(AxisName_RightStickHorizontal, currentJoystickRightStickButton2.isPressed ? 1 : 0);
if (currentJoystickRightStickButton4 != null)
axisDelegate(AxisName_RightStickHorizontal, currentJoystickRightStickButton4.isPressed ? -1 : 0);
if (currentJoystickRightStickAxisY != null)
axisDelegate(AxisName_RightStickVertical, currentJoystickRightStickAxisY.value);
}
}
//逆序遍历链表。后添加的按键事件最先处理
LinkedListNode<KeyListenerItem> cur = items.Last;
Expand Down
13 changes: 7 additions & 6 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"dependencies": {
"com.unity.2d.sprite": "1.0.0",
"com.unity.collab-proxy": "2.0.3",
"com.unity.collab-proxy": "2.2.0",
"com.unity.feature.development": "1.0.1",
"com.unity.ide.rider": "3.0.18",
"com.unity.ide.visualstudio": "2.0.17",
"com.unity.ide.rider": "3.0.26",
"com.unity.ide.visualstudio": "2.0.22",
"com.unity.ide.vscode": "1.2.5",
"com.unity.inputsystem": "1.7.0",
"com.unity.mathematics": "1.2.6",
"com.unity.nuget.newtonsoft-json": "3.1.0",
"com.unity.test-framework": "1.1.31",
"com.unity.timeline": "1.6.4",
"com.unity.nuget.newtonsoft-json": "3.2.1",
"com.unity.test-framework": "1.1.33",
"com.unity.timeline": "1.6.5",
"com.unity.ugui": "1.0.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
Expand Down
35 changes: 22 additions & 13 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {}
},
"com.unity.collab-proxy": {
"version": "2.0.3",
"version": "2.2.0",
"depth": 0,
"source": "registry",
"dependencies": {},
Expand All @@ -32,17 +32,17 @@
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.ide.visualstudio": "2.0.14",
"com.unity.ide.rider": "3.0.13",
"com.unity.ide.visualstudio": "2.0.22",
"com.unity.ide.rider": "3.0.26",
"com.unity.ide.vscode": "1.2.5",
"com.unity.editorcoroutines": "1.0.0",
"com.unity.performance.profile-analyzer": "1.1.1",
"com.unity.test-framework": "1.1.31",
"com.unity.testtools.codecoverage": "1.0.1"
"com.unity.performance.profile-analyzer": "1.2.2",
"com.unity.test-framework": "1.1.33",
"com.unity.testtools.codecoverage": "1.2.4"
}
},
"com.unity.ide.rider": {
"version": "3.0.18",
"version": "3.0.26",
"depth": 0,
"source": "registry",
"dependencies": {
Expand All @@ -51,7 +51,7 @@
"url": "https://packages.unity.cn"
},
"com.unity.ide.visualstudio": {
"version": "2.0.17",
"version": "2.0.22",
"depth": 0,
"source": "registry",
"dependencies": {
Expand All @@ -66,6 +66,15 @@
"dependencies": {},
"url": "https://packages.unity.cn"
},
"com.unity.inputsystem": {
"version": "1.7.0",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.modules.uielements": "1.0.0"
},
"url": "https://packages.unity.cn"
},
"com.unity.mathematics": {
"version": "1.2.6",
"depth": 0,
Expand All @@ -74,14 +83,14 @@
"url": "https://packages.unity.cn"
},
"com.unity.nuget.newtonsoft-json": {
"version": "3.1.0",
"version": "3.2.1",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.cn"
},
"com.unity.performance.profile-analyzer": {
"version": "1.1.1",
"version": "1.2.2",
"depth": 1,
"source": "registry",
"dependencies": {},
Expand All @@ -95,7 +104,7 @@
"url": "https://packages.unity.cn"
},
"com.unity.test-framework": {
"version": "1.1.31",
"version": "1.1.33",
"depth": 0,
"source": "registry",
"dependencies": {
Expand All @@ -106,7 +115,7 @@
"url": "https://packages.unity.cn"
},
"com.unity.testtools.codecoverage": {
"version": "1.0.1",
"version": "1.2.4",
"depth": 1,
"source": "registry",
"dependencies": {
Expand All @@ -116,7 +125,7 @@
"url": "https://packages.unity.cn"
},
"com.unity.timeline": {
"version": "1.6.4",
"version": "1.6.5",
"depth": 0,
"source": "registry",
"dependencies": {
Expand Down
Loading

0 comments on commit 91314eb

Please sign in to comment.