final commit
This commit is contained in:
1 parent
8a9fe611e0
commit
316ed56a7d
47 files changed
+1667
-364
No files matched your search
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e07d5cd999fb4d77975cb298c69dc88e
|
||||
timeCreated: 1772204161
|
||||
@@ -1,18 +0,0 @@
|
||||
using Code.Input;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Code.DI
|
||||
{
|
||||
public class Bootstrapper : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private InputActionAsset inputActionAsset;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
var container = new GameObject("DIContainer").AddComponent<DIContainer>();
|
||||
|
||||
container.Register<IInputService>(new InputService(inputActionAsset));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a121b287cff04fab80cde7f9f7e1f982
|
||||
timeCreated: 1772204190
|
||||
@@ -1,35 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.DI
|
||||
{
|
||||
public class DIContainer : MonoBehaviour
|
||||
{
|
||||
private readonly Dictionary<Type, object> _services = new();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
||||
public void Register<T>(T service)
|
||||
{
|
||||
var type = typeof(T);
|
||||
if (!_services.TryAdd(type, service))
|
||||
{
|
||||
Debug.LogWarning($"Service {type} is already registered.");
|
||||
}
|
||||
}
|
||||
|
||||
public T Resolve<T>()
|
||||
{
|
||||
var type = typeof(T);
|
||||
if (_services.TryGetValue(type, out var service))
|
||||
{
|
||||
return (T)service;
|
||||
}
|
||||
throw new Exception($"Service {type} not found.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 660a533686c44961ace8a87cfbb6d7c4
|
||||
timeCreated: 1772204169
|
||||
@@ -11,6 +11,10 @@ namespace Code.Gameplay.Player
|
||||
[SerializeField] private float laneDistance = 5f;
|
||||
[SerializeField] private float jumpForce = 11f;
|
||||
[SerializeField] private float gravity = 20f;
|
||||
|
||||
[SerializeField] private Animator animator;
|
||||
[SerializeField] private RuntimeAnimatorController runController;
|
||||
[SerializeField] private RuntimeAnimatorController jumpController;
|
||||
|
||||
private int _targetLane = 1;
|
||||
|
||||
@@ -32,11 +36,11 @@ namespace Code.Gameplay.Player
|
||||
{
|
||||
if (_isDead) return;
|
||||
|
||||
if (UnityEngine.Input.GetKeyDown(KeyCode.RightArrow) || UnityEngine.Input.GetKeyDown(KeyCode.D))
|
||||
if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.D))
|
||||
{
|
||||
_targetLane = Mathf.Min(_targetLane + 1, 2);
|
||||
}
|
||||
else if (UnityEngine.Input.GetKeyDown(KeyCode.LeftArrow) || UnityEngine.Input.GetKeyDown(KeyCode.A))
|
||||
else if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A))
|
||||
{
|
||||
_targetLane = Mathf.Max(_targetLane - 1, 0);
|
||||
}
|
||||
@@ -57,10 +61,15 @@ namespace Code.Gameplay.Player
|
||||
{
|
||||
_direction.y = -1f;
|
||||
|
||||
if (UnityEngine.Input.GetKeyDown(KeyCode.Space))
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
animator.runtimeAnimatorController = jumpController;
|
||||
_direction.y = jumpForce;
|
||||
}
|
||||
else
|
||||
{
|
||||
animator.runtimeAnimatorController = runController;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 561d87a075df49809ed39eee110a8060
|
||||
timeCreated: 1772996609
|
||||
@@ -0,0 +1,56 @@
|
||||
using UnityEngine;
|
||||
using Code.Saves;
|
||||
|
||||
namespace Code.Gameplay.Visuals
|
||||
{
|
||||
public class VisualApplyer : MonoBehaviour
|
||||
{
|
||||
public enum ObjectType { Player, Platform, Bonus }
|
||||
[SerializeField] private ObjectType type;
|
||||
|
||||
[SerializeField] private SkinnedMeshRenderer characterRenderer;
|
||||
[SerializeField] private Transform hatContainer;
|
||||
|
||||
private static readonly int ColorId = Shader.PropertyToID("_BaseColor");
|
||||
|
||||
private void Start() => Apply();
|
||||
|
||||
public void Apply()
|
||||
{
|
||||
var data = SaveManager.Load();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ObjectType.Player:
|
||||
ApplyPlayer(data);
|
||||
break;
|
||||
case ObjectType.Platform:
|
||||
GetComponent<Renderer>().material.SetColor(ColorId, data.platformColor);
|
||||
break;
|
||||
case ObjectType.Bonus:
|
||||
GetComponent<Renderer>().material.SetColor(ColorId, data.bonusColor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyPlayer(GameData data)
|
||||
{
|
||||
if (characterRenderer == null) return;
|
||||
|
||||
var bodymats = Resources.LoadAll<Material>("MaterialsCharacter/Body");
|
||||
var facemats = Resources.LoadAll<Material>("MaterialsCharacter/Face");
|
||||
|
||||
var currentMats = characterRenderer.sharedMaterials;
|
||||
currentMats[0] = bodymats[data.bodyMaterialIndex];
|
||||
currentMats[1] = facemats[data.faceMaterialIndex];
|
||||
characterRenderer.sharedMaterials = currentMats;
|
||||
|
||||
foreach (Transform child in hatContainer) Destroy(child.gameObject);
|
||||
var hats = Resources.LoadAll<GameObject>("Prefabs/Character/Hats");
|
||||
if (data.hatIndex > 0 && data.hatIndex <= hats.Length)
|
||||
{
|
||||
Instantiate(hats[data.hatIndex - 1], hatContainer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 077f289d09ed40caac4f48f033bea8c8
|
||||
timeCreated: 1772996620
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8722d8a19b4344229829f7454f01d707
|
||||
timeCreated: 1772203877
|
||||
@@ -1,9 +0,0 @@
|
||||
namespace Code.Input
|
||||
{
|
||||
public enum ActionMapping
|
||||
{
|
||||
MainMenu,
|
||||
Gameplay,
|
||||
UI
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ebc8b8e5edcc44d6b0c67a7a43ee4458
|
||||
timeCreated: 1772203887
|
||||
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Code.Input
|
||||
{
|
||||
public interface IInputService
|
||||
{
|
||||
void EnableMap(ActionMapping actionMap);
|
||||
void DisableMap(ActionMapping actionMap);
|
||||
|
||||
Vector2 MainMenuParallax { get; }
|
||||
|
||||
float MoveInput { get; }
|
||||
bool JumpPressed { get; }
|
||||
|
||||
|
||||
void DebugBindAction(int mapId, int actionId, Action<InputAction.CallbackContext> action);
|
||||
void DebugUnbindAction(int mapId, int actionId, Action<InputAction.CallbackContext> action);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c1a81b165e14b619a8ed42b4ab4f775
|
||||
timeCreated: 1772203895
|
||||
@@ -1,89 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Code.Input
|
||||
{
|
||||
public class InputService : IInputService
|
||||
{
|
||||
private readonly InputActionAsset _inputActionAsset;
|
||||
|
||||
public Vector2 MainMenuParallax { get; private set; }
|
||||
|
||||
public float MoveInput { get; private set; }
|
||||
public bool JumpPressed { get; private set; }
|
||||
|
||||
public InputService(InputActionAsset inputActionAsset)
|
||||
{
|
||||
_inputActionAsset = inputActionAsset;
|
||||
SetupInputCallbacks();
|
||||
}
|
||||
|
||||
private void SetupInputCallbacks()
|
||||
{
|
||||
SetupMainMenuInputCallbacks();
|
||||
SetupGameplayInputCallbacks();
|
||||
}
|
||||
|
||||
private void SetupGameplayInputCallbacks()
|
||||
{
|
||||
var map = _inputActionAsset.actionMaps[(int)ActionMapping.Gameplay];
|
||||
BindAxis(map, "Move", v => MoveInput = v);
|
||||
BindButton(map, "Jump", v => JumpPressed = v);
|
||||
}
|
||||
|
||||
private void SetupMainMenuInputCallbacks()
|
||||
{
|
||||
var map = _inputActionAsset.actionMaps[(int)ActionMapping.MainMenu];
|
||||
BindVector2(map, "Parallax", v => MainMenuParallax = v);
|
||||
}
|
||||
|
||||
private void BindButton(InputActionMap map, string actionName, System.Action<bool> setter)
|
||||
{
|
||||
var action = map.FindAction(actionName);
|
||||
|
||||
if (action == null)
|
||||
return;
|
||||
|
||||
action.performed += _ => setter(true);
|
||||
action.canceled += _ => setter(false);
|
||||
}
|
||||
|
||||
private void BindVector2(InputActionMap map, string actionName, System.Action<Vector2> setter)
|
||||
{
|
||||
var action = map.FindAction(actionName);
|
||||
|
||||
if (action == null)
|
||||
return;
|
||||
|
||||
action.performed += ctx => setter(ctx.ReadValue<Vector2>());
|
||||
action.canceled += _ => setter(Vector2.zero);
|
||||
}
|
||||
|
||||
private void BindAxis(InputActionMap map, string actionName, System.Action<float> setter)
|
||||
{
|
||||
var action = map.FindAction(actionName);
|
||||
|
||||
if (action == null)
|
||||
return;
|
||||
|
||||
action.performed += ctx => setter(ctx.ReadValue<float>());
|
||||
action.canceled += _ => setter(0f);
|
||||
}
|
||||
|
||||
public void EnableMap(ActionMapping actionMap)
|
||||
{
|
||||
_inputActionAsset.actionMaps[(int)actionMap].Enable();
|
||||
}
|
||||
|
||||
public void DisableMap(ActionMapping actionMap)
|
||||
{
|
||||
_inputActionAsset.actionMaps[(int)actionMap].Disable();
|
||||
}
|
||||
|
||||
public void DebugBindAction(int mapId, int actionId, System.Action<InputAction.CallbackContext> action) =>
|
||||
_inputActionAsset.actionMaps[mapId].actions[actionId].performed += action;
|
||||
|
||||
public void DebugUnbindAction(int mapId, int actionId, System.Action<InputAction.CallbackContext> action) =>
|
||||
_inputActionAsset.actionMaps[mapId].actions[actionId].performed -= action;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7087241a4e642d18a79b43896f1dab6
|
||||
timeCreated: 1772203909
|
||||
@@ -18,6 +18,10 @@ namespace Code.UI
|
||||
[SerializeField] private TMP_InputField nameInputField;
|
||||
[SerializeField] private Button restartButton;
|
||||
[SerializeField] private Button exitButton;
|
||||
|
||||
[SerializeField] private AudioSource audioSource;
|
||||
[SerializeField] private AudioClip coinClip;
|
||||
[SerializeField] private AudioClip deathClip;
|
||||
|
||||
private int _coins;
|
||||
|
||||
@@ -44,20 +48,25 @@ namespace Code.UI
|
||||
{
|
||||
_coins++;
|
||||
coinsText.text = $"{_coins} Coins";
|
||||
|
||||
Tween.PunchScale(coinsText.transform, strength: new Vector3(0.2f, 0.2f, 0.2f), duration: 0.2f);
|
||||
|
||||
if (audioSource && coinClip)
|
||||
audioSource.PlayOneShot(coinClip);
|
||||
}
|
||||
|
||||
private void ShowDeathScreen()
|
||||
{
|
||||
if (audioSource && deathClip)
|
||||
audioSource.PlayOneShot(deathClip);
|
||||
|
||||
deathPanelCanvasGroup.gameObject.SetActive(true);
|
||||
|
||||
Tween.Alpha(deathPanelCanvasGroup, startValue: 0f, endValue: 1f, duration: 0.5f, ease: Ease.OutSine, useUnscaledTime: true);
|
||||
|
||||
deathPanelWindow.localScale = Vector3.zero;
|
||||
Tween.Scale(deathPanelWindow, endValue: 1f, duration: 0.6f, ease: Ease.OutBack, useUnscaledTime: true)
|
||||
.OnComplete(() => {
|
||||
Time.timeScale = 0;
|
||||
});
|
||||
|
||||
Sequence.Create(useUnscaledTime: true)
|
||||
.Group(Tween.Alpha(deathPanelCanvasGroup, 1f, 0.4f))
|
||||
.Group(Tween.Scale(deathPanelWindow, startValue: 0.8f, endValue: 1f, duration: 0.5f, ease: Ease.OutBack))
|
||||
.OnComplete(() => Time.timeScale = 0);
|
||||
|
||||
finalResultText.text = $"You collected: {_coins} coins";
|
||||
}
|
||||
|
||||
@@ -82,13 +91,13 @@ namespace Code.UI
|
||||
|
||||
data.playerName = currentName;
|
||||
|
||||
data.leaderboard.Add(new Saves.LeaderboardEntry(currentName, _coins));
|
||||
data.leaderboard.Add(new LeaderboardEntry(currentName, _coins));
|
||||
|
||||
data.leaderboard.Sort((a, b) => b.score.CompareTo(a.score));
|
||||
|
||||
if (data.leaderboard.Count > 10)
|
||||
if (data.leaderboard.Count > 7)
|
||||
{
|
||||
data.leaderboard.RemoveRange(10, data.leaderboard.Count - 10);
|
||||
data.leaderboard.RemoveRange(7, data.leaderboard.Count - 7);
|
||||
}
|
||||
|
||||
SaveManager.Save(data);
|
||||
|
||||
@@ -30,7 +30,8 @@ namespace Code.UI
|
||||
playButton.onClick.AddListener(() => LoadScene("Gameplay"));
|
||||
customizeButton.onClick.AddListener(() => LoadScene("Customization"));
|
||||
leaderboardButton.onClick.AddListener(() => LoadScene("Leaderboard"));
|
||||
exitButton.onClick.AddListener(Application.Quit);
|
||||
|
||||
exitButton.onClick.AddListener(ExitGame);
|
||||
|
||||
AnimateMenu();
|
||||
}
|
||||
@@ -67,6 +68,20 @@ namespace Code.UI
|
||||
});
|
||||
}
|
||||
|
||||
private void ExitGame()
|
||||
{
|
||||
Tween.Alpha(buttonsContainer, 0f, 0.3f).OnComplete(() =>
|
||||
{
|
||||
Debug.Log("Application Closing...");
|
||||
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.isPlaying = false;
|
||||
#else
|
||||
Application.Quit();
|
||||
#endif
|
||||
});
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
playButton.onClick.RemoveAllListeners();
|
||||
|
||||
Reference in new issue
Block a user