From 3ade281440f2bda343689e00cea89a29f17bedf0 Mon Sep 17 00:00:00 2001 From: Maxim-Godovikov Date: Sun, 17 Oct 2021 19:14:41 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BA=D1=80=D0=B8=D0=BF=D1=82=D1=8B:=20?= =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20?= =?UTF-8?q?=D1=81=D1=82=D0=B8=D0=BB=D0=B8=D1=81=D1=82=D0=B8=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82=D0=BE=D0=B2=20=D0=B2=D0=B2?= =?UTF-8?q?=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scenes/Level_1.unity | 15 ++-- Assets/Scenes/Level_2.unity | 15 ++-- Assets/Scripts/Global/CustomInput.cs | 105 +++++++++++------------- Assets/Scripts/Global/InputManagment.cs | 15 +--- 4 files changed, 65 insertions(+), 85 deletions(-) diff --git a/Assets/Scenes/Level_1.unity b/Assets/Scenes/Level_1.unity index 97a9e42d..64cbea23 100644 --- a/Assets/Scenes/Level_1.unity +++ b/Assets/Scenes/Level_1.unity @@ -243,9 +243,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: e3cee3b8892508d478b1c4d0fad4801c, type: 3} m_Name: m_EditorClassIdentifier: - maxSize: 7.5 - camExpandSmoothness: 0.01 - trackingPlayer: 1 + _maxSize: 7.5 + _camExpandSmoothness: 0.01 + _trackingPlayer: 1 _cam: {fileID: 95433828} --- !u!1 &112562703 stripped GameObject: @@ -2768,11 +2768,10 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: bc14c61ebbe85804bacfb5a675a95310, type: 3} m_Name: m_EditorClassIdentifier: - controlType: 0 - leftJoystick: {fileID: 1712987976} - rightJoystick: {fileID: 2060963491} - attackJoystick: {fileID: 320155194} - defendJoystick: {fileID: 1105100998} + _leftJoystick: {fileID: 1712987976} + _rightJoystick: {fileID: 2060963491} + _attackJoystick: {fileID: 320155194} + _defendJoystick: {fileID: 1105100998} --- !u!114 &1102420990 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/Level_2.unity b/Assets/Scenes/Level_2.unity index 80cccfc9..bdfaa606 100644 --- a/Assets/Scenes/Level_2.unity +++ b/Assets/Scenes/Level_2.unity @@ -486,9 +486,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: e3cee3b8892508d478b1c4d0fad4801c, type: 3} m_Name: m_EditorClassIdentifier: - maxSize: 7.5 - camExpandSmoothness: 0.01 - trackingPlayer: 1 + _maxSize: 7.5 + _camExpandSmoothness: 0.01 + _trackingPlayer: 1 _cam: {fileID: 95433828} --- !u!1 &112562703 stripped GameObject: @@ -3288,11 +3288,10 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: bc14c61ebbe85804bacfb5a675a95310, type: 3} m_Name: m_EditorClassIdentifier: - controlType: 0 - leftJoystick: {fileID: 1129072376} - rightJoystick: {fileID: 1129072379} - attackJoystick: {fileID: 1129072378} - defendJoystick: {fileID: 1129072377} + _leftJoystick: {fileID: 1129072376} + _rightJoystick: {fileID: 1129072379} + _attackJoystick: {fileID: 1129072378} + _defendJoystick: {fileID: 1129072377} --- !u!114 &1102420990 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Global/CustomInput.cs b/Assets/Scripts/Global/CustomInput.cs index cda89471..66da03d9 100644 --- a/Assets/Scripts/Global/CustomInput.cs +++ b/Assets/Scripts/Global/CustomInput.cs @@ -1,51 +1,61 @@ using System; -using System.Collections; -using System.Collections.Generic; using UnityEngine; -using System; public class CustomInput : MonoBehaviour { - public static Vector2 leftInput, rightInput; - //public static Vector2 attackActionInput, protectActionInput; - //public static float rightRegistrationDeadZone = 0.3f; + #region Static fields - public static Action OnTouchDown, OnTouchUp; - /* public static Action OnDefendTouchDown, OnDefendTouchUp; - public static Action OnAttackTouchDown, OnAttackTouchUp;*/ + public static Vector2 leftInput; + public static Vector2 rightInput; + public static Action OnTouchDown; + public static Action OnTouchUp; - [Header("Character Control Parameters")] - public CharControlType controlType = CharControlType.UI_Joysticks; - [SerializeField] - private DynamicJoystick leftJoystick; - [SerializeField] - private FloatingJoystick rightJoystick; - [SerializeField] - private FixedJoystick attackJoystick, defendJoystick; + #endregion + + [Header("Character Control Parameters")] + + [SerializeField] private DynamicJoystick _leftJoystick; + [SerializeField] private FloatingJoystick _rightJoystick; + [SerializeField] private FixedJoystick _attackJoystick; + [SerializeField] private FixedJoystick _defendJoystick; private Joystick _currentRightJoystick; private void Awake() { - SetupDeafultControls(); + SetupDefaultControls(); - rightJoystick.OnTouchDown += InvokeTouchDown; - rightJoystick.OnTouchUp += InvokeTouchUp; + _rightJoystick.OnTouchDown += InvokeTouchDown; + _rightJoystick.OnTouchUp += InvokeTouchUp; - attackJoystick.OnTouchDown += InvokeTouchDown; - attackJoystick.OnTouchUp += InvokeTouchUp; + _attackJoystick.OnTouchDown += InvokeTouchDown; + _attackJoystick.OnTouchUp += InvokeTouchUp; - defendJoystick.OnTouchDown += InvokeTouchDown; - defendJoystick.OnTouchUp += InvokeTouchUp; + _defendJoystick.OnTouchDown += InvokeTouchDown; + _defendJoystick.OnTouchUp += InvokeTouchUp; + } + + private void Start() + { + ResetInput(); } - public void SetupDeafultControls() + private void Update() { - rightJoystick.gameObject.SetActive(true); - defendJoystick.gameObject.SetActive(false); - attackJoystick.gameObject.SetActive(false); - _currentRightJoystick = rightJoystick; + leftInput.x = _leftJoystick.Horizontal; + leftInput.y = _leftJoystick.Vertical; + + rightInput.x = _currentRightJoystick.Horizontal; + rightInput.y = _currentRightJoystick.Vertical; + } + + public void SetupDefaultControls() + { + _rightJoystick.gameObject.SetActive(true); + _defendJoystick.gameObject.SetActive(false); + _attackJoystick.gameObject.SetActive(false); + _currentRightJoystick = _rightJoystick; } public void SetupActiveJoystick(BonusType bonusType) @@ -53,15 +63,16 @@ public class CustomInput : MonoBehaviour Joystick newActiveJoystick; if (bonusType == BonusType.Attack) { - newActiveJoystick = attackJoystick; + newActiveJoystick = _attackJoystick; } else { - newActiveJoystick = defendJoystick; + newActiveJoystick = _defendJoystick; } - rightJoystick.gameObject.SetActive(false); - defendJoystick.gameObject.SetActive(false); - attackJoystick.gameObject.SetActive(false); + + _rightJoystick.gameObject.SetActive(false); + _defendJoystick.gameObject.SetActive(false); + _attackJoystick.gameObject.SetActive(false); newActiveJoystick.gameObject.SetActive(true); _currentRightJoystick = newActiveJoystick; @@ -71,15 +82,10 @@ public class CustomInput : MonoBehaviour { OnTouchDown?.Invoke(); } + private void InvokeTouchUp() { OnTouchUp?.Invoke(); - } - - - private void Start() - { - ResetInput(); } private void ResetInput() @@ -87,21 +93,4 @@ public class CustomInput : MonoBehaviour leftInput = Vector2.zero; } - private void Update() - { - leftInput.x = leftJoystick.Horizontal; - leftInput.y = leftJoystick.Vertical; - - rightInput.x = _currentRightJoystick.Horizontal; - rightInput.y = _currentRightJoystick.Vertical; - - } -} - - - -public enum CharControlType -{ - UI_Joysticks, - //Else //test purp for now -} +} \ No newline at end of file diff --git a/Assets/Scripts/Global/InputManagment.cs b/Assets/Scripts/Global/InputManagment.cs index b8a3df43..d63c29ff 100644 --- a/Assets/Scripts/Global/InputManagment.cs +++ b/Assets/Scripts/Global/InputManagment.cs @@ -1,15 +1,9 @@ -using System; -using System.Collections; -using System.Collections.Generic; using UnityEngine; public class InputManagment : MonoBehaviour { - [SerializeField] - private PlayerState _controllablePlayer; - - [SerializeField] - private CustomInput _customInput; + [SerializeField] private PlayerState _controllablePlayer; + [SerializeField] private CustomInput _customInput; private BonusUI _bonusUIManager; @@ -24,12 +18,11 @@ public class InputManagment : MonoBehaviour private void SetupDefault() { - _customInput.SetupDeafultControls(); + _customInput.SetupDefaultControls(); } private void SetupBonusJoysticks(Bonus selectedBonus) { _customInput.SetupActiveJoystick(selectedBonus.bonusType); } - -} +} \ No newline at end of file