Skip to content

Commit

Permalink
Merge pull request #21 from aaasoft/main
Browse files Browse the repository at this point in the history
发布1.0.3版本
  • Loading branch information
aaasoft committed Jan 12, 2024
2 parents 91314eb + b63b4c3 commit 0b4f9d2
Show file tree
Hide file tree
Showing 22 changed files with 283 additions and 1,770 deletions.
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.26713884, y: 0.7892295}
m_Offset: {x: 0.7124696, y: 0.2345556}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
Expand Down
188 changes: 31 additions & 157 deletions Assets/Game/GamePlay/Scripts/BallManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using BallancePhysics.Wapper;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.LowLevel;
using static Ballance2.Services.GameManager;

namespace Ballance2.Game.GamePlay
Expand All @@ -21,10 +23,7 @@ namespace Ballance2.Game.GamePlay
public class BallManager : MonoBehaviour
{
private const string TAG = "BallManager";
//视角切换锁
private bool camRotateLock = false;
//上次移动球的类型
private KeyListener.MovementType lastMovementType = KeyListener.MovementType.Keyboard;
public BallLightningSphere _BallLightningSphere;
public GameObject _BallWood;
public GameObject _BallStone;
Expand Down Expand Up @@ -176,158 +175,41 @@ private void _OnControlSettingsChanged()
_InitKeys();
}

private void _AxisListen(string asixName, float value)
{
KeyListener.MovementType currentMovementType = KeyListener.MovementType.Keyboard;
switch (asixName)
{
case KeyListener.AxisName_Horizontal:
case KeyListener.AxisName_Vertical:
currentMovementType = KeyListener.MovementType.DPad;
break;
case KeyListener.AxisName_LeftStickHorizontal:
case KeyListener.AxisName_LeftStickVertical:
currentMovementType = KeyListener.MovementType.LeftStick;
break;
}
//检测到手柄操作,销毁屏幕键盘
GamePlayUIControl.Instance.DestroyMobileKeyPad();
switch (asixName)
{
//控制左右
case KeyListener.AxisName_Horizontal:
case KeyListener.AxisName_LeftStickHorizontal:
if (Math.Abs(value) < 0.3)
{
if (lastMovementType == currentMovementType)
{
if (KeyStateLeft || KeyStateRight)
{
KeyStateLeft = false;
KeyStateRight = false;
FlushBallPush();
}
}
return;
}
lastMovementType = currentMovementType;
if (value > 0)
{
if (KeyStateLeft || !KeyStateRight)
{
KeyStateLeft = false;
KeyStateRight = true;
FlushBallPush();
}
}
else
{
if (!KeyStateLeft || KeyStateRight)
{
KeyStateLeft = true;
KeyStateRight = false;
FlushBallPush();
}
}
break;
//控制前后
case KeyListener.AxisName_Vertical:
case KeyListener.AxisName_LeftStickVertical:
if (Math.Abs(value) < 0.3)
{
if (lastMovementType == currentMovementType)
{
if (KeyStateForward || KeyStateBack)
{
KeyStateForward = false;
KeyStateBack = false;
FlushBallPush();
}
}
return;
}
lastMovementType = currentMovementType;
if (value > 0)
{
if (!KeyStateForward || KeyStateBack)
{
KeyStateForward = true;
KeyStateBack = false;
FlushBallPush();
}
}
else
{
if (KeyStateForward || !KeyStateBack)
{
KeyStateForward = false;
KeyStateBack = true;
FlushBallPush();
}
}
break;
//右摇杆左右切换摄像机视角
case KeyListener.AxisName_RightStickHorizontal:

if (Math.Abs(value) < 0.5)
return;
if (camRotateLock)
return;
camRotateLock = true;
GameTimer.Delay(0.5F, () => camRotateLock = false);

if (value > 0)
{
if (CanControllCamera)
{
if (reverseRotation)
GamePlayManager.Instance.CamManager.RotateRight();
else
GamePlayManager.Instance.CamManager.RotateLeft();
}
}
else
{
if (CanControllCamera)
{
if (reverseRotation)
GamePlayManager.Instance.CamManager.RotateLeft();
else
GamePlayManager.Instance.CamManager.RotateRight();
}
}
break;
//右摇杆上下切换俯瞰视角
case KeyListener.AxisName_RightStickVertical:
if (Math.Abs(value) < 0.5)
return;
if (camRotateLock)
return;
camRotateLock = true;
GameTimer.Delay(0.5F, () => camRotateLock = false);
if (CanControllCamera)
{
GamePlayManager.Instance.CamManager.RotateUp(!GamePlayManager.Instance.CamManager.CamIsSpaced);
}
break;
}
}

private void _InitKeys()
{
//初始化键盘侦听
keyListener = KeyListener.Get(gameObject);
keyListener.DisableWhenUIFocused = false;
keyListener.ClearKeyListen();
keyListener.AddKeyListen(keyFront, _UpArrow_Key);
keyListener.AddKeyListen(keyBack, _DownArrow_Key);
keyListener.AddKeyListen(keyUp, _Up_Key);
keyListener.AddKeyListen(keyDown, _Down_Key);
keyListener.AddKeyListen(keyUpCamera, _Space_Key);
keyListener.AddKeyListen(keyRoateCamera, keyRoateCamera2, _Shift_Key);
keyListener.AddKeyListen(keyLeft, _LeftArrow_Key);
keyListener.AddKeyListen(keyRight, _RightArrow_Key);
keyListener.SetAxisListen(_AxisListen);
keyListener.AddKeyListen(keyFront, _UpArrow_Key, GamepadButton.DpadUp);
keyListener.AddKeyListen(keyBack, _DownArrow_Key, GamepadButton.DpadDown);
keyListener.AddKeyListen(keyUp, _Up_Key, GamepadButton.LeftTrigger);
keyListener.AddKeyListen(keyDown, _Down_Key, GamepadButton.RightTrigger);
keyListener.AddKeyListen(keyUpCamera, _Space_Key, GamepadButton.Y);
keyListener.AddKeyListen(keyRoateCamera, _Shift_Key);
keyListener.AddKeyListen(keyRoateCamera2, _Shift_Key);
keyListener.AddKeyListen(KeyCode.PageUp, (key, down) =>
{
if (down && CanControllCamera)
{
if (reverseRotation)
GamePlayManager.Instance.CamManager.RotateLeft();
else
GamePlayManager.Instance.CamManager.RotateRight();
}
}, GamepadButton.LeftShoulder);
keyListener.AddKeyListen(KeyCode.PageDown, (key, down) =>
{
if (down && CanControllCamera)
{
if (reverseRotation)
GamePlayManager.Instance.CamManager.RotateRight();
else
GamePlayManager.Instance.CamManager.RotateLeft();
}
}, GamepadButton.RightShoulder);
keyListener.AddKeyListen(keyLeft, _LeftArrow_Key, GamepadButton.DpadLeft);
keyListener.AddKeyListen(keyRight, _RightArrow_Key, GamepadButton.DpadRight);

//测试按扭
if (GameManager.DebugMode)
Expand Down Expand Up @@ -1175,19 +1057,16 @@ public void FastMoveTo(Vector3 pos, float time, SmoothFly.CallbackDelegate callb

private void _UpArrow_Key(KeyCode key, bool down)
{
lastMovementType = KeyListener.MovementType.Keyboard;
KeyStateForward = down;
FlushBallPush();
}
private void _DownArrow_Key(KeyCode key, bool down)
{
lastMovementType = KeyListener.MovementType.Keyboard;
KeyStateBack = down;
FlushBallPush();
}
private void _RightArrow_Key(KeyCode key, bool down)
{
lastMovementType = KeyListener.MovementType.Keyboard;
_RightPressed = down;
if (down)
{
Expand All @@ -1213,7 +1092,6 @@ private void _RightArrow_Key(KeyCode key, bool down)
}
private void _LeftArrow_Key(KeyCode key, bool down)
{
lastMovementType = KeyListener.MovementType.Keyboard;
_LeftPressed = down;
if (down)
{
Expand All @@ -1239,7 +1117,6 @@ private void _LeftArrow_Key(KeyCode key, bool down)
}
private void _Down_Key(KeyCode key, bool down)
{
lastMovementType = KeyListener.MovementType.Keyboard;
if (GameManager.DebugMode)
{
KeyStateDown = down;
Expand All @@ -1248,7 +1125,6 @@ private void _Down_Key(KeyCode key, bool down)
}
private void _Up_Key(KeyCode key, bool down)
{
lastMovementType = KeyListener.MovementType.Keyboard;
if (GameManager.DebugMode)
{
KeyStateUp = down;
Expand All @@ -1257,15 +1133,13 @@ private void _Up_Key(KeyCode key, bool down)
}
private void _Space_Key(KeyCode key, bool down)
{
lastMovementType = KeyListener.MovementType.Keyboard;
if (CanControllCamera)
{
GamePlayManager.Instance.CamManager.RotateUp(down);
}
}
private void _Shift_Key(KeyCode key, bool down)
{
lastMovementType = KeyListener.MovementType.Keyboard;
ShiftPressed = down;
if (_LeftPressed)
{
Expand Down
31 changes: 7 additions & 24 deletions Assets/Game/GamePlay/Scripts/GamePlayManager.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using Ballance2.Base;
using Ballance2.Game.GamePlay.Balls;
using Ballance2.Game.GamePlay.Other;
using Ballance2.Game.GamePlay.Tranfo;
using Ballance2.Game.LevelBuilder;
using Ballance2.Game.Utils;
using Ballance2.Menu;
using Ballance2.Package;
Expand All @@ -13,6 +11,7 @@
using BallancePhysics.Wapper;
using Newtonsoft.Json.Linq;
using UnityEngine;
using UnityEngine.InputSystem.LowLevel;

namespace Ballance2.Game.GamePlay
{
Expand Down Expand Up @@ -110,7 +109,7 @@ public LevelBuilder.LevelBuilder LevelBuilderRef
private int _HideBalloonEndTimerID = 0;
//Used by Tutorial
internal bool _ShouldStartByCustom = false;
private int[] _EscKeyIds = new int[0];
private int _EscKeyIds = 0;

private void Awake()
{
Expand All @@ -136,9 +135,8 @@ protected override void OnDestroy()
{
Log.D(TAG, "Destroy");
if (GameUIManager.Instance != null)
foreach (var id in _EscKeyIds)
GameUIManager.Instance.DeleteKeyListen(id);
GameManager.GameMediator.UnRegisterSingleEvent("CoreGamePlayManagerInitAndStart"); //取消注册全局事件
GameUIManager.Instance.DeleteKeyListen(_EscKeyIds);
GameManager.GameMediator?.UnRegisterSingleEvent("CoreGamePlayManagerInitAndStart"); //取消注册全局事件
this._DeleteEvents();
this._DeleteCommands(); //删除指令
}
Expand Down Expand Up @@ -301,9 +299,8 @@ private void _InitSounds()
}
private void _InitKeyEvents()
{
_EscKeyIds = new int[2];
//ESC键
_EscKeyIds[0] = GameUIManager.Instance.ListenKey(KeyCode.Escape, (key, down) =>
_EscKeyIds = GameUIManager.Instance.ListenKey(KeyCode.Escape, (key, down) =>
{
if (down
&& this.CanEscPause
Expand All @@ -315,21 +312,7 @@ private void _InitKeyEvents()
else
this.ResumeLevel();
}
});
//手柄菜单键
_EscKeyIds[1] = GameUIManager.Instance.ListenKey(KeyCode.Joystick1Button7, (key, down) =>
{
if (down
&& this.CanEscPause
&& this._BallBirthed
&& !this.CurrentLevelPass)
{
if (this._IsGamePlaying)
this.PauseLevel(true);
else
this.ResumeLevel();
}
});
}, GamepadButton.Start);
}
private void _InitSettings()
{
Expand Down Expand Up @@ -461,7 +444,7 @@ private void _InitEvents()
}
private void _DeleteEvents()
{
GameManager.GameMediator.UnRegisterEventEmitter("GamePlay");
GameManager.GameMediator?.UnRegisterEventEmitter("GamePlay");
}

#endregion
Expand Down
Loading

0 comments on commit 0b4f9d2

Please sign in to comment.