Project structure, add docs update unity version

This commit is contained in:
2026-06-05 12:19:36 +03:00
parent fc24653f9a
commit 39294ec527
87 changed files with 5910 additions and 371 deletions
+5 -5
View File
@@ -87,15 +87,15 @@ public abstract class Character : MonoBehaviour
if (isAllowVertical)
{
SetClimbingAnimation(v_movement != 0);
_body.velocity = new Vector2(h_movement * _movementSpeed, v_movement * _movementSpeed);
_body.linearVelocity = new Vector2(h_movement * _movementSpeed, v_movement * _movementSpeed);
}
else{
_body.velocity = new Vector2(h_movement * _movementSpeed, _body.velocity.y);
_body.linearVelocity = new Vector2(h_movement * _movementSpeed, _body.linearVelocity.y);
}
}
else
{
_body.velocity = new Vector2(h_movement * _movementSpeed, _body.velocity.y);
_body.linearVelocity = new Vector2(h_movement * _movementSpeed, _body.linearVelocity.y);
}
}
else
@@ -115,12 +115,12 @@ public abstract class Character : MonoBehaviour
}
if (_isFalling)
{
_body.velocity = new Vector2(0, _body.velocity.y);
_body.linearVelocity = new Vector2(0, _body.linearVelocity.y);
SetWalkingAnimation(false);
if (block?.ElementSO.ElementType == MapElementType.Ladder)
{
_body.velocity = Vector2.zero;
_body.linearVelocity = Vector2.zero;
_isOnLadder = true;
}
}
@@ -1,7 +1,7 @@
using System;
using UnityEngine;
public class Player : Character
public class PlayerController : Character
{
[SerializeField]
private Transform _hammerSpawnPoint;
@@ -13,15 +13,6 @@ public class Player : Character
[SerializeField]
private Sprite _noHammerSprite;
public int Lives=3;
private int _hammerSpeed = 5;
private int _totalCoins = 0;
private bool _hasKey = false;
public int TotalCoins => _totalCoins;
public static Player Instance { get; private set; }
private GameObject _hammer;
@@ -30,7 +21,8 @@ public class Player : Character
public event EventHandler<TreasureType> OnPlayerTakeItem;
private InputActions _inputActions;
private InputManager _inputManager;
private PlayerState _playerState;
private void Awake()
{
@@ -40,44 +32,23 @@ public class Player : Character
Debug.Log("There's more than one player instance");
return;
}
PlayerPrefs.SetString("lastExitName", string.Empty);
Instance = this;
DontDestroyOnLoad(gameObject);
_inputActions = new InputActions();
_inputManager = new InputManager();
_playerState = GetComponent<PlayerState>();
_inputManager.OnMovementInput += OnMovementInput;
_inputManager.OnFireButtonPressed += OnFireButtonPressed;
}
private void OnEnable()
{
_inputActions.Enable();
_inputManager.Enable();
}
private void OnDisable()
{
_inputActions.Disable();
}
public void AddCoin()
{
_totalCoins++;
OnPlayerTakeItem?.Invoke(this,TreasureType.Coin);
print($"player have {_totalCoins} coins");
}
public void SetKey()
{
OnPlayerTakeItem?.Invoke(this, TreasureType.Key);
print($"player have key");
_hasKey = true;
}
public void RemoveKey()
{
_hasKey = false;
}
public bool IsHasKey()
{
return _hasKey;
_inputManager.Disable();
}
private void Update()
@@ -88,20 +59,16 @@ public class Player : Character
_isHoldingHammer = true;
}
if (FireButtonPressed() && !_isFalling)
{
if (_hammer == null)
{
_animator.SetTrigger("Body_ThrowHammer");
}
}
var move = _inputActions.Player.Movement.ReadValue<Vector2>();
var move = _inputManager.OnMovementInput.ReadValue<Vector2>();
base.MoveTo(move.x, isAllowVertical ? move.y : 0);
}
private bool FireButtonPressed()
private void OnFireButtonPressed()
{
return _inputActions.Player.Fire.triggered && _inputActions.Player.Fire.ReadValue<float>() > 0;
if (_hammer == null)
{
_animator.SetTrigger("Body_ThrowHammer");
}
}
public void ThrowHammerObject()
@@ -110,14 +77,14 @@ public class Player : Character
_spriteRenderer.sprite = _noHammerSprite;
_hammer = Instantiate(_hammerPrefab, _hammerSpawnPoint.position, _hammerSpawnPoint.rotation);
_hammer.transform.localScale = new Vector2(_hammer.transform.localScale.x * (_facingRight ? 1 : -1), _hammer.transform.localScale.y);
_hammer.GetComponent<Rigidbody2D>().velocity = new Vector2(gameObject.transform.localScale.x * _hammerSpeed, 0);
_hammer.GetComponent<Rigidbody2D>().linearVelocity = new Vector2(gameObject.transform.localScale.x * _hammerSpeed, 0);
}
protected override void SetWalkingAnimation(bool isWalking)
{
_bonesBack.SetActive(false);
_bonesSide.SetActive(true);
_animator.SetBool("Legs_Walk",isWalking);
_animator.SetBool("Legs_Walk", isWalking);
_animator.SetBool("Body_Walk", isWalking);
}
@@ -133,11 +100,11 @@ public class Player : Character
protected void OnDeath()
{
Lives--;
if (Lives==0)
_playerState.Lives--;
if (_playerState.Lives == 0)
{
print("game over");
Debug.Log("Game over");
}
}
}
+6 -8
View File
@@ -21,14 +21,9 @@ public class EnemyAI : Character
float verticalDistance = Player.Instance.transform.position.y - transform.position.y;
if (verticalDistance > 0.1f && isCanClimbUp && isAllowVertical)
if (Mathf.Abs(verticalDistance) > 0.1f && (isCanClimbUp || isCanGoDown))
{
vertical = VerticalMove(verticalDistance);
}
else if (verticalDistance < 0f && isAllowVertical && isCanGoDown)
{
vertical = VerticalMove(verticalDistance);
vertical = Mathf.Sign(verticalDistance);
}
else
{
@@ -40,13 +35,16 @@ public class EnemyAI : Character
{ horizontal = -1; }
else if (directionToPlayer.x > 0)
{ horizontal = 1; }
}
if (Input.GetKey(KeyCode.T))
{ vertical = 1; }
if (Input.GetKey(KeyCode.G))
{ vertical = -1; }
Debug.Log($"Enemy Position: {transform.position}, Player Position: {Player.Instance.transform.position}");
Debug.Log($"Vertical Distance: {verticalDistance}, Vertical Movement: {vertical}");
base.MoveTo(horizontal, vertical);
}
+155 -1
View File
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator
// version 1.7.0
// version 1.19.0
// from Assets/Scripts/InputActions.inputactions
//
// Changes to this file may cause incorrect behavior and will be lost if
@@ -15,12 +15,77 @@ using System.Collections.Generic;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;
/// <summary>
/// Provides programmatic access to <see cref="InputActionAsset" />, <see cref="InputActionMap" />, <see cref="InputAction" /> and <see cref="InputControlScheme" /> instances defined in asset "Assets/Scripts/InputActions.inputactions".
/// </summary>
/// <remarks>
/// This class is source generated and any manual edits will be discarded if the associated asset is reimported or modified.
/// </remarks>
/// <example>
/// <code>
/// using namespace UnityEngine;
/// using UnityEngine.InputSystem;
///
/// // Example of using an InputActionMap named "Player" from a UnityEngine.MonoBehaviour implementing callback interface.
/// public class Example : MonoBehaviour, MyActions.IPlayerActions
/// {
/// private MyActions_Actions m_Actions; // Source code representation of asset.
/// private MyActions_Actions.PlayerActions m_Player; // Source code representation of action map.
///
/// void Awake()
/// {
/// m_Actions = new MyActions_Actions(); // Create asset object.
/// m_Player = m_Actions.Player; // Extract action map object.
/// m_Player.AddCallbacks(this); // Register callback interface IPlayerActions.
/// }
///
/// void OnDestroy()
/// {
/// m_Actions.Dispose(); // Destroy asset object.
/// }
///
/// void OnEnable()
/// {
/// m_Player.Enable(); // Enable all actions within map.
/// }
///
/// void OnDisable()
/// {
/// m_Player.Disable(); // Disable all actions within map.
/// }
///
/// #region Interface implementation of MyActions.IPlayerActions
///
/// // Invoked when "Move" action is either started, performed or canceled.
/// public void OnMove(InputAction.CallbackContext context)
/// {
/// Debug.Log($"OnMove: {context.ReadValue&lt;Vector2&gt;()}");
/// }
///
/// // Invoked when "Attack" action is either started, performed or canceled.
/// public void OnAttack(InputAction.CallbackContext context)
/// {
/// Debug.Log($"OnAttack: {context.ReadValue&lt;float&gt;()}");
/// }
///
/// #endregion
/// }
/// </code>
/// </example>
public partial class @InputActions: IInputActionCollection2, IDisposable
{
/// <summary>
/// Provides access to the underlying asset instance.
/// </summary>
public InputActionAsset asset { get; }
/// <summary>
/// Constructs a new instance.
/// </summary>
public @InputActions()
{
asset = InputActionAsset.FromJson(@"{
""version"": 1,
""name"": ""InputActions"",
""maps"": [
{
@@ -190,57 +255,76 @@ public partial class @InputActions: IInputActionCollection2, IDisposable
m_Player_Fire = m_Player.FindAction("Fire", throwIfNotFound: true);
}
~@InputActions()
{
UnityEngine.Debug.Assert(!m_Player.enabled, "This will cause a leak and performance issues, InputActions.Player.Disable() has not been called.");
}
/// <summary>
/// Destroys this asset and all associated <see cref="InputAction"/> instances.
/// </summary>
public void Dispose()
{
UnityEngine.Object.Destroy(asset);
}
/// <inheritdoc cref="UnityEngine.InputSystem.InputActionAsset.bindingMask" />
public InputBinding? bindingMask
{
get => asset.bindingMask;
set => asset.bindingMask = value;
}
/// <inheritdoc cref="UnityEngine.InputSystem.InputActionAsset.devices" />
public ReadOnlyArray<InputDevice>? devices
{
get => asset.devices;
set => asset.devices = value;
}
/// <inheritdoc cref="UnityEngine.InputSystem.InputActionAsset.controlSchemes" />
public ReadOnlyArray<InputControlScheme> controlSchemes => asset.controlSchemes;
/// <inheritdoc cref="UnityEngine.InputSystem.InputActionAsset.Contains(InputAction)" />
public bool Contains(InputAction action)
{
return asset.Contains(action);
}
/// <inheritdoc cref="UnityEngine.InputSystem.InputActionAsset.GetEnumerator()" />
public IEnumerator<InputAction> GetEnumerator()
{
return asset.GetEnumerator();
}
/// <inheritdoc cref="IEnumerable.GetEnumerator()" />
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
/// <inheritdoc cref="UnityEngine.InputSystem.InputActionAsset.Enable()" />
public void Enable()
{
asset.Enable();
}
/// <inheritdoc cref="UnityEngine.InputSystem.InputActionAsset.Disable()" />
public void Disable()
{
asset.Disable();
}
/// <inheritdoc cref="UnityEngine.InputSystem.InputActionAsset.bindings" />
public IEnumerable<InputBinding> bindings => asset.bindings;
/// <inheritdoc cref="UnityEngine.InputSystem.InputActionAsset.FindAction(string, bool)" />
public InputAction FindAction(string actionNameOrId, bool throwIfNotFound = false)
{
return asset.FindAction(actionNameOrId, throwIfNotFound);
}
/// <inheritdoc cref="UnityEngine.InputSystem.InputActionAsset.FindBinding(InputBinding, out InputAction)" />
public int FindBinding(InputBinding bindingMask, out InputAction action)
{
return asset.FindBinding(bindingMask, out action);
@@ -251,17 +335,47 @@ public partial class @InputActions: IInputActionCollection2, IDisposable
private List<IPlayerActions> m_PlayerActionsCallbackInterfaces = new List<IPlayerActions>();
private readonly InputAction m_Player_Movement;
private readonly InputAction m_Player_Fire;
/// <summary>
/// Provides access to input actions defined in input action map "Player".
/// </summary>
public struct PlayerActions
{
private @InputActions m_Wrapper;
/// <summary>
/// Construct a new instance of the input action map wrapper class.
/// </summary>
public PlayerActions(@InputActions wrapper) { m_Wrapper = wrapper; }
/// <summary>
/// Provides access to the underlying input action "Player/Movement".
/// </summary>
public InputAction @Movement => m_Wrapper.m_Player_Movement;
/// <summary>
/// Provides access to the underlying input action "Player/Fire".
/// </summary>
public InputAction @Fire => m_Wrapper.m_Player_Fire;
/// <summary>
/// Provides access to the underlying input action map instance.
/// </summary>
public InputActionMap Get() { return m_Wrapper.m_Player; }
/// <inheritdoc cref="UnityEngine.InputSystem.InputActionMap.Enable()" />
public void Enable() { Get().Enable(); }
/// <inheritdoc cref="UnityEngine.InputSystem.InputActionMap.Disable()" />
public void Disable() { Get().Disable(); }
/// <inheritdoc cref="UnityEngine.InputSystem.InputActionMap.enabled" />
public bool enabled => Get().enabled;
/// <summary>
/// Implicitly converts an <see ref="PlayerActions" /> to an <see ref="InputActionMap" /> instance.
/// </summary>
public static implicit operator InputActionMap(PlayerActions set) { return set.Get(); }
/// <summary>
/// Adds <see cref="InputAction.started"/>, <see cref="InputAction.performed"/> and <see cref="InputAction.canceled"/> callbacks provided via <param cref="instance" /> on all input actions contained in this map.
/// </summary>
/// <param name="instance">Callback instance.</param>
/// <remarks>
/// If <paramref name="instance" /> is <c>null</c> or <paramref name="instance"/> have already been added this method does nothing.
/// </remarks>
/// <seealso cref="PlayerActions" />
public void AddCallbacks(IPlayerActions instance)
{
if (instance == null || m_Wrapper.m_PlayerActionsCallbackInterfaces.Contains(instance)) return;
@@ -274,6 +388,13 @@ public partial class @InputActions: IInputActionCollection2, IDisposable
@Fire.canceled += instance.OnFire;
}
/// <summary>
/// Removes <see cref="InputAction.started"/>, <see cref="InputAction.performed"/> and <see cref="InputAction.canceled"/> callbacks provided via <param cref="instance" /> on all input actions contained in this map.
/// </summary>
/// <remarks>
/// Calling this method when <paramref name="instance" /> have not previously been registered has no side-effects.
/// </remarks>
/// <seealso cref="PlayerActions" />
private void UnregisterCallbacks(IPlayerActions instance)
{
@Movement.started -= instance.OnMovement;
@@ -284,12 +405,25 @@ public partial class @InputActions: IInputActionCollection2, IDisposable
@Fire.canceled -= instance.OnFire;
}
/// <summary>
/// Unregisters <param cref="instance" /> and unregisters all input action callbacks via <see cref="PlayerActions.UnregisterCallbacks(IPlayerActions)" />.
/// </summary>
/// <seealso cref="PlayerActions.UnregisterCallbacks(IPlayerActions)" />
public void RemoveCallbacks(IPlayerActions instance)
{
if (m_Wrapper.m_PlayerActionsCallbackInterfaces.Remove(instance))
UnregisterCallbacks(instance);
}
/// <summary>
/// Replaces all existing callback instances and previously registered input action callbacks associated with them with callbacks provided via <param cref="instance" />.
/// </summary>
/// <remarks>
/// If <paramref name="instance" /> is <c>null</c>, calling this method will only unregister all existing callbacks but not register any new callbacks.
/// </remarks>
/// <seealso cref="PlayerActions.AddCallbacks(IPlayerActions)" />
/// <seealso cref="PlayerActions.RemoveCallbacks(IPlayerActions)" />
/// <seealso cref="PlayerActions.UnregisterCallbacks(IPlayerActions)" />
public void SetCallbacks(IPlayerActions instance)
{
foreach (var item in m_Wrapper.m_PlayerActionsCallbackInterfaces)
@@ -298,10 +432,30 @@ public partial class @InputActions: IInputActionCollection2, IDisposable
AddCallbacks(instance);
}
}
/// <summary>
/// Provides a new <see cref="PlayerActions" /> instance referencing this action map.
/// </summary>
public PlayerActions @Player => new PlayerActions(this);
/// <summary>
/// Interface to implement callback methods for all input action callbacks associated with input actions defined by "Player" which allows adding and removing callbacks.
/// </summary>
/// <seealso cref="PlayerActions.AddCallbacks(IPlayerActions)" />
/// <seealso cref="PlayerActions.RemoveCallbacks(IPlayerActions)" />
public interface IPlayerActions
{
/// <summary>
/// Method invoked when associated input action "Movement" 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 OnMovement(InputAction.CallbackContext context);
/// <summary>
/// Method invoked when associated input action "Fire" 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 OnFire(InputAction.CallbackContext context);
}
}
+24
View File
@@ -0,0 +1,24 @@
public class InputManager : MonoBehaviour
{
private InputActions _inputActions;
public event EventHandler<Vector2> OnMovementInput;
public event EventHandler OnFireButtonPressed;
private void Awake()
{
_inputActions = new InputActions();
_inputActions.Player.Movement.performed += ctx => OnMovementInput?.Invoke(ctx.ReadValue<Vector2>());
_inputActions.Player.Fire.performed += ctx => OnFireButtonPressed?.Invoke();
}
private void OnEnable()
{
_inputActions.Enable();
}
private void OnDisable()
{
_inputActions.Disable();
}
}
+27
View File
@@ -0,0 +1,27 @@
public class PlayerState : MonoBehaviour
{
public int Lives = 3;
public int TotalCoins { get; private set; }
public bool HasKey { get; private set; }
public event EventHandler<TreasureType> OnPlayerTakeItem;
public void AddCoin()
{
TotalCoins++;
OnPlayerTakeItem?.Invoke(this, TreasureType.Coin);
Debug.Log($"Player has {TotalCoins} coins");
}
public void SetKey()
{
HasKey = true;
OnPlayerTakeItem?.Invoke(this, TreasureType.Key);
Debug.Log("Player has key");
}
public void RemoveKey()
{
HasKey = false;
}
}