simple UI added
This commit is contained in:
@@ -100,6 +100,15 @@ public partial class @GameInput: IInputActionCollection2, IDisposable
|
||||
""processors"": """",
|
||||
""interactions"": """",
|
||||
""initialStateCheck"": true
|
||||
},
|
||||
{
|
||||
""name"": ""Click"",
|
||||
""type"": ""Button"",
|
||||
""id"": ""d08e73a2-d66c-4b94-8559-f0f33f595386"",
|
||||
""expectedControlType"": """",
|
||||
""processors"": """",
|
||||
""interactions"": """",
|
||||
""initialStateCheck"": false
|
||||
}
|
||||
],
|
||||
""bindings"": [
|
||||
@@ -124,6 +133,17 @@ public partial class @GameInput: IInputActionCollection2, IDisposable
|
||||
""action"": ""Drag"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
},
|
||||
{
|
||||
""name"": """",
|
||||
""id"": ""d96e7abe-3a25-4e29-8565-e9e53cbf261f"",
|
||||
""path"": ""<Mouse>/leftButton"",
|
||||
""interactions"": ""Hold"",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""Click"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -133,6 +153,7 @@ public partial class @GameInput: IInputActionCollection2, IDisposable
|
||||
// Player
|
||||
m_Player = asset.FindActionMap("Player", throwIfNotFound: true);
|
||||
m_Player_Drag = m_Player.FindAction("Drag", throwIfNotFound: true);
|
||||
m_Player_Click = m_Player.FindAction("Click", throwIfNotFound: true);
|
||||
}
|
||||
|
||||
~@GameInput()
|
||||
@@ -214,6 +235,7 @@ public partial class @GameInput: IInputActionCollection2, IDisposable
|
||||
private readonly InputActionMap m_Player;
|
||||
private List<IPlayerActions> m_PlayerActionsCallbackInterfaces = new List<IPlayerActions>();
|
||||
private readonly InputAction m_Player_Drag;
|
||||
private readonly InputAction m_Player_Click;
|
||||
/// <summary>
|
||||
/// Provides access to input actions defined in input action map "Player".
|
||||
/// </summary>
|
||||
@@ -230,6 +252,10 @@ public partial class @GameInput: IInputActionCollection2, IDisposable
|
||||
/// </summary>
|
||||
public InputAction @Drag => m_Wrapper.m_Player_Drag;
|
||||
/// <summary>
|
||||
/// Provides access to the underlying input action "Player/Click".
|
||||
/// </summary>
|
||||
public InputAction @Click => m_Wrapper.m_Player_Click;
|
||||
/// <summary>
|
||||
/// Provides access to the underlying input action map instance.
|
||||
/// </summary>
|
||||
public InputActionMap Get() { return m_Wrapper.m_Player; }
|
||||
@@ -258,6 +284,9 @@ public partial class @GameInput: IInputActionCollection2, IDisposable
|
||||
@Drag.started += instance.OnDrag;
|
||||
@Drag.performed += instance.OnDrag;
|
||||
@Drag.canceled += instance.OnDrag;
|
||||
@Click.started += instance.OnClick;
|
||||
@Click.performed += instance.OnClick;
|
||||
@Click.canceled += instance.OnClick;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -272,6 +301,9 @@ public partial class @GameInput: IInputActionCollection2, IDisposable
|
||||
@Drag.started -= instance.OnDrag;
|
||||
@Drag.performed -= instance.OnDrag;
|
||||
@Drag.canceled -= instance.OnDrag;
|
||||
@Click.started -= instance.OnClick;
|
||||
@Click.performed -= instance.OnClick;
|
||||
@Click.canceled -= instance.OnClick;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -319,5 +351,12 @@ public partial class @GameInput: IInputActionCollection2, IDisposable
|
||||
/// <seealso cref="UnityEngine.InputSystem.InputAction.performed" />
|
||||
/// <seealso cref="UnityEngine.InputSystem.InputAction.canceled" />
|
||||
void OnDrag(InputAction.CallbackContext context);
|
||||
/// <summary>
|
||||
/// Method invoked when associated input action "Click" is either <see cref="UnityEngine.InputSystem.InputAction.started" />, <see cref="UnityEngine.InputSystem.InputAction.performed" /> or <see cref="UnityEngine.InputSystem.InputAction.canceled" />.
|
||||
/// </summary>
|
||||
/// <seealso cref="UnityEngine.InputSystem.InputAction.started" />
|
||||
/// <seealso cref="UnityEngine.InputSystem.InputAction.performed" />
|
||||
/// <seealso cref="UnityEngine.InputSystem.InputAction.canceled" />
|
||||
void OnClick(InputAction.CallbackContext context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,15 @@
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": true
|
||||
},
|
||||
{
|
||||
"name": "Click",
|
||||
"type": "Button",
|
||||
"id": "d08e73a2-d66c-4b94-8559-f0f33f595386",
|
||||
"expectedControlType": "",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
}
|
||||
],
|
||||
"bindings": [
|
||||
@@ -38,6 +47,17 @@
|
||||
"action": "Drag",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "d96e7abe-3a25-4e29-8565-e9e53cbf261f",
|
||||
"path": "<Mouse>/leftButton",
|
||||
"interactions": "Hold",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Click",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -3,4 +3,6 @@ using UnityEngine;
|
||||
public interface IInputReader
|
||||
{
|
||||
Vector2 dragInput{get;}
|
||||
float clickInput { get;}
|
||||
bool isclicked { get;}
|
||||
}
|
||||
|
||||
@@ -6,16 +6,23 @@ using UnityEngine.InputSystem;
|
||||
public class InputReader : ScriptableObject, IInputReader, GameInput.IPlayerActions
|
||||
{
|
||||
public Action<Vector2> OnDragValueChanged;
|
||||
|
||||
public Vector2 _dragInput;
|
||||
public Vector2 dragInput
|
||||
{
|
||||
get=> _dragInput;
|
||||
private set
|
||||
{
|
||||
|
||||
_dragInput = value;
|
||||
OnDragValueChanged?.Invoke(_dragInput);
|
||||
}
|
||||
}
|
||||
|
||||
public float clickInput { get; private set; }
|
||||
|
||||
public bool isclicked {get; private set; }
|
||||
|
||||
private GameInput inputActions;
|
||||
|
||||
private void OnEnable()
|
||||
@@ -25,10 +32,11 @@ public class InputReader : ScriptableObject, IInputReader, GameInput.IPlayerActi
|
||||
inputActions = new GameInput();
|
||||
inputActions.Player.SetCallbacks(this);
|
||||
}
|
||||
|
||||
inputActions.Enable();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
public void OnDisable()
|
||||
{
|
||||
inputActions?.Player.Disable();
|
||||
}
|
||||
@@ -37,4 +45,11 @@ public class InputReader : ScriptableObject, IInputReader, GameInput.IPlayerActi
|
||||
{
|
||||
dragInput = context.ReadValue<Vector2>();
|
||||
}
|
||||
|
||||
public void OnClick(InputAction.CallbackContext context)
|
||||
{
|
||||
clickInput = context.ReadValue<float>();
|
||||
isclicked = clickInput == 1? true : false;
|
||||
Debug.Log(isclicked);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,13 @@ using VContainer.Unity;
|
||||
public class GameLifeTimeScope : LifetimeScope
|
||||
{
|
||||
[SerializeField] private InputReader _inputReader;
|
||||
[SerializeField] private DeathScreenView deathview;
|
||||
[SerializeField] private StartScreenView startView;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Debug.Log("startView is: " + startView);
|
||||
}
|
||||
protected override void Configure(IContainerBuilder builder)
|
||||
{
|
||||
|
||||
@@ -13,5 +20,9 @@ public class GameLifeTimeScope : LifetimeScope
|
||||
builder.RegisterComponentInHierarchy<Player>();
|
||||
builder.RegisterComponentInHierarchy<PlatformManager>();
|
||||
builder.RegisterInstance(_inputReader).As<IInputReader>();
|
||||
|
||||
builder.Register<ScoreService>(Lifetime.Singleton);
|
||||
builder.Register<DeathScreenController>(Lifetime.Singleton).WithParameter(deathview);
|
||||
builder.Register<StartScreenController>(Lifetime.Singleton).WithParameter(startView);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ public class Platform : MonoBehaviour
|
||||
[Inject] private PlatformPool pool;
|
||||
[Inject] private PlatformManager manager;
|
||||
[Inject] private Player player;
|
||||
//[Inject] private IInputReader inputReader;
|
||||
|
||||
|
||||
void Start()
|
||||
|
||||
@@ -7,6 +7,7 @@ public class PlatformManager : MonoBehaviour
|
||||
private GameObject currentPlatfrom;
|
||||
[Inject] private PlatformPool pool;
|
||||
[Inject] private InputReader inputReader;
|
||||
[Inject] private StartScreenController startScreenController;
|
||||
private int yPos=0;
|
||||
|
||||
public int rotspeed = 1;
|
||||
@@ -24,13 +25,6 @@ public class PlatformManager : MonoBehaviour
|
||||
{
|
||||
inputReader.OnDragValueChanged -= DragPerformed;
|
||||
}
|
||||
|
||||
private void DragPerformed(Vector2 drag)
|
||||
{
|
||||
float rotAmount = -drag.normalized.x * rotspeed;
|
||||
transform.Rotate(0, rotAmount, 0);
|
||||
}
|
||||
|
||||
public void ShowInitialPlatforms()
|
||||
{
|
||||
|
||||
@@ -52,5 +46,22 @@ public class PlatformManager : MonoBehaviour
|
||||
}
|
||||
|
||||
}
|
||||
private void DragPerformed(Vector2 drag)
|
||||
{
|
||||
if(startScreenController.hasGameStarted)
|
||||
{
|
||||
float rotAmount = -drag.normalized.x * rotspeed;
|
||||
|
||||
#if UNITY_EDITOR || UNITY_STANDALONE
|
||||
if (inputReader.isclicked)
|
||||
{
|
||||
transform.Rotate(0, rotAmount, 0);
|
||||
}
|
||||
#else
|
||||
transform.Rotate(0, rotAmount, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
public class Player : MonoBehaviour, IPlayer
|
||||
{
|
||||
@@ -6,6 +7,10 @@ public class Player : MonoBehaviour, IPlayer
|
||||
public Rigidbody BallRb;
|
||||
public bool isDead { get; private set; }
|
||||
|
||||
[Inject] ScoreService scoreService;
|
||||
[Inject] InputReader inputReader;
|
||||
[Inject] DeathScreenController deathScreenController;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (BallRb == null)
|
||||
@@ -16,7 +21,7 @@ public class Player : MonoBehaviour, IPlayer
|
||||
|
||||
void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if (collision.collider.CompareTag("Platform"))
|
||||
if (collision.collider.CompareTag("Platform") && !isDead)
|
||||
{
|
||||
BallRb.linearVelocity = new Vector3(0, jumpforce, 0);
|
||||
}
|
||||
@@ -30,5 +35,15 @@ public class Player : MonoBehaviour, IPlayer
|
||||
{
|
||||
Debug.Log("Player is Dead");
|
||||
isDead = true;
|
||||
deathScreenController.ShowDeathScreen(scoreService.score,scoreService.GetHighscore());
|
||||
}
|
||||
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if(other.CompareTag("ScoreTrigger"))
|
||||
{
|
||||
scoreService.AddScore();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
8
Assets/Scripts/Score.meta
Normal file
8
Assets/Scripts/Score.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53296fef6f75bf24b8d98731aafb3bb5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Assets/Scripts/Score/ScoreService.cs
Normal file
35
Assets/Scripts/Score/ScoreService.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
public class ScoreService
|
||||
{
|
||||
public Action<int> onScoreUpdate;
|
||||
|
||||
public int score { get; private set; }
|
||||
public int HighScore = PlayerPrefs.GetInt("HighScore", 0);
|
||||
|
||||
public void AddScore()
|
||||
{
|
||||
score += 5;
|
||||
onScoreUpdate?.Invoke(score);
|
||||
if(score>HighScore)
|
||||
{
|
||||
SetHighScore();
|
||||
}
|
||||
Debug.Log(score);
|
||||
}
|
||||
|
||||
private void SetHighScore()
|
||||
{
|
||||
HighScore = score;
|
||||
PlayerPrefs.SetInt("HighScore",HighScore);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
public int GetHighscore()
|
||||
{
|
||||
return PlayerPrefs.GetInt("HighScore",0);
|
||||
}
|
||||
|
||||
}
|
||||
2
Assets/Scripts/Score/ScoreService.cs.meta
Normal file
2
Assets/Scripts/Score/ScoreService.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13c4b70629aaf8747870390d15c9aff4
|
||||
8
Assets/Scripts/UI.meta
Normal file
8
Assets/Scripts/UI.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee040abc6e7dc0840989b6d375f80f61
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
39
Assets/Scripts/UI/DeathScreenController.cs
Normal file
39
Assets/Scripts/UI/DeathScreenController.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using VContainer;
|
||||
|
||||
public class DeathScreenController
|
||||
{
|
||||
private DeathScreenView _view;
|
||||
|
||||
[Inject] private StartScreenController startScreenController;
|
||||
public DeathScreenController(DeathScreenView view)
|
||||
{
|
||||
_view = view;
|
||||
_view.backButton.onClick.AddListener(OnBackBtnClicked);
|
||||
_view.rePlayButton.onClick.AddListener(OnReplayBtnClicked);
|
||||
}
|
||||
public void HideDeathScreen()
|
||||
{
|
||||
_view.Hide();
|
||||
}
|
||||
|
||||
private void OnReplayBtnClicked()
|
||||
{
|
||||
HideDeathScreen();
|
||||
SceneManager.LoadScene(0);
|
||||
Debug.Log("Game Replayed");
|
||||
}
|
||||
|
||||
private void OnBackBtnClicked()
|
||||
{
|
||||
HideDeathScreen();
|
||||
SceneManager.LoadScene(0);
|
||||
}
|
||||
|
||||
public void ShowDeathScreen(int score, int highscore)
|
||||
{
|
||||
_view.Show(score,highscore);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UI/DeathScreenController.cs.meta
Normal file
2
Assets/Scripts/UI/DeathScreenController.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6c7a99a1277b874084999ad0cdce5aa
|
||||
28
Assets/Scripts/UI/DeathScreenView.cs
Normal file
28
Assets/Scripts/UI/DeathScreenView.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class DeathScreenView : MonoBehaviour
|
||||
{
|
||||
public GameObject deathScreen;
|
||||
public Button rePlayButton;
|
||||
public Button backButton;
|
||||
public TextMeshProUGUI highScoreText;
|
||||
public TextMeshProUGUI currentScoreText;
|
||||
private void Start()
|
||||
{
|
||||
deathScreen.SetActive(false);
|
||||
}
|
||||
|
||||
public void Show(int score, int highscore)
|
||||
{
|
||||
highScoreText.text = highscore.ToString();
|
||||
currentScoreText.text = score.ToString();
|
||||
deathScreen.SetActive(true);
|
||||
|
||||
}
|
||||
public void Hide()
|
||||
{
|
||||
deathScreen.SetActive(false);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UI/DeathScreenView.cs.meta
Normal file
2
Assets/Scripts/UI/DeathScreenView.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89974c575158e4d4fb7be55470dc5150
|
||||
37
Assets/Scripts/UI/StartScreenController.cs
Normal file
37
Assets/Scripts/UI/StartScreenController.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
public class StartScreenController
|
||||
{
|
||||
private StartScreenView _view;
|
||||
public bool hasGameStarted = false;
|
||||
|
||||
public StartScreenController(StartScreenView view)
|
||||
{
|
||||
_view = view;
|
||||
_view.playBtn.onClick.AddListener(OnPlayBtnClicked);
|
||||
Debug.Log("Instance");
|
||||
}
|
||||
|
||||
|
||||
public void OnPlayBtnClicked()
|
||||
{
|
||||
_view.Hide();
|
||||
hasGameStarted = true;
|
||||
}
|
||||
|
||||
public void ShowStartScreen()
|
||||
{
|
||||
|
||||
_view.Show();
|
||||
hasGameStarted = false;
|
||||
|
||||
}
|
||||
|
||||
public void HideStartScreen()
|
||||
{
|
||||
_view.Hide();
|
||||
hasGameStarted = true;
|
||||
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UI/StartScreenController.cs.meta
Normal file
2
Assets/Scripts/UI/StartScreenController.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2f5bbd1e47302e45a2c3d3c60fedfcf
|
||||
19
Assets/Scripts/UI/StartScreenView.cs
Normal file
19
Assets/Scripts/UI/StartScreenView.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using VContainer;
|
||||
|
||||
public class StartScreenView : MonoBehaviour
|
||||
{
|
||||
public GameObject startScreen;
|
||||
public Button playBtn;
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
startScreen.SetActive(false);
|
||||
}
|
||||
|
||||
public void Show()
|
||||
{
|
||||
startScreen.SetActive(true);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UI/StartScreenView.cs.meta
Normal file
2
Assets/Scripts/UI/StartScreenView.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7614619c0714a4e47804c3234d3398dc
|
||||
Reference in New Issue
Block a user