Add player controller, state management, and input handling
- Implemented PlayerController.cs to manage player movement and actions. - Created PlayerState.cs to track player lives, coins, and key status. - Added CameraFollow.cs for smooth camera movement following the player. - Developed Character.cs as an abstract class for character behavior. - Introduced Enums.cs for defining TreasureType and MapElementType. - Added IDoor interface for door interactions. - Created InputActions.cs for handling player input actions. - Implemented MainMenu.cs for basic menu functionality including play and exit options.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraFollow : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform _followTarget;
|
||||
[SerializeField]
|
||||
private float _smoothTime = 0.15f;
|
||||
[SerializeField]
|
||||
private bool _stopAtXedges=false;
|
||||
[SerializeField]
|
||||
private float _maxXValue = 0f;
|
||||
[SerializeField]
|
||||
private float _minXValue = 0f;
|
||||
|
||||
|
||||
|
||||
Vector3 _velocity= Vector3.zero;
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
var targetPosition=_followTarget.position;
|
||||
targetPosition.z = transform.position.z;
|
||||
targetPosition.y = transform.position.y;
|
||||
|
||||
if (_stopAtXedges)
|
||||
{
|
||||
targetPosition.x = Mathf.Clamp(targetPosition.x, _minXValue, _maxXValue);
|
||||
}
|
||||
|
||||
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref _velocity,_smoothTime);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1734c77596ffe1742882362d0b2fe3e2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,252 @@
|
||||
using System.Linq;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class Character : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
protected Animator _animator;
|
||||
[SerializeField]
|
||||
private float _movementSpeed = 1.5f;
|
||||
[SerializeField]
|
||||
protected GameObject _bonesSide;
|
||||
[SerializeField]
|
||||
protected GameObject _bonesBack;
|
||||
|
||||
|
||||
[SerializeField]
|
||||
private LayerMask _mapLayer;
|
||||
|
||||
protected SpriteRenderer _spriteRenderer;
|
||||
|
||||
|
||||
private Rigidbody2D _body;
|
||||
private CapsuleCollider2D _capsuleCollider;
|
||||
protected bool _isOnBridge;
|
||||
private bool _isOnLadder = false;
|
||||
|
||||
protected bool _isFalling;
|
||||
protected bool _facingRight = true;
|
||||
|
||||
protected bool isCanGoDown = false;
|
||||
protected bool isCanClimbUp=false;
|
||||
protected bool isAllowVertical = true;
|
||||
protected bool isAllowRight = true;
|
||||
protected bool isAllowLeft = true;
|
||||
private Vector2 _cellSize;
|
||||
|
||||
public event EventHandler OnCharacterDeath;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_body = GetComponent<Rigidbody2D>();
|
||||
_capsuleCollider = GetComponent<CapsuleCollider2D>();
|
||||
_spriteRenderer = GetComponentInChildren<SpriteRenderer>();
|
||||
_cellSize = new Vector2(0.6f, 1f);
|
||||
}
|
||||
|
||||
protected void MoveTo(float inputHorizontal, float inputVertical)
|
||||
{
|
||||
var block = GetMapElement();
|
||||
|
||||
if (block?.ElementSO.ElementType == MapElementType.Water)
|
||||
{
|
||||
Death();
|
||||
}
|
||||
|
||||
_isOnBridge = block?.ElementSO.ElementType == MapElementType.Bridge && !_isFalling;
|
||||
|
||||
if (block)
|
||||
{
|
||||
isAllowVertical = false;
|
||||
_isFalling = false;
|
||||
float h_movement = inputHorizontal;
|
||||
|
||||
if (h_movement > 0 && !_facingRight || h_movement < 0 && _facingRight)
|
||||
{
|
||||
FlipCharacter();
|
||||
}
|
||||
|
||||
SetWalkingAnimation(h_movement != 0);
|
||||
|
||||
_isOnLadder = block.ElementSO.ElementType == MapElementType.Ladder;
|
||||
|
||||
if (_isOnLadder)
|
||||
{
|
||||
isCanClimbUp=CanClimbUp();
|
||||
isCanGoDown = CanGoDown();
|
||||
float ladderXCenterDistance = Mathf.Abs(transform.position.x - block.transform.position.x);
|
||||
|
||||
float v_movement = inputVertical;
|
||||
isAllowVertical = (ladderXCenterDistance < 0.3f);
|
||||
if(!isCanClimbUp&& v_movement>0)
|
||||
{
|
||||
v_movement=0;
|
||||
}
|
||||
|
||||
if (isAllowVertical)
|
||||
{
|
||||
SetClimbingAnimation(v_movement != 0);
|
||||
_body.linearVelocity = new Vector2(h_movement * _movementSpeed, v_movement * _movementSpeed);
|
||||
}
|
||||
else{
|
||||
_body.linearVelocity = new Vector2(h_movement * _movementSpeed, _body.linearVelocity.y);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_body.linearVelocity = new Vector2(h_movement * _movementSpeed, _body.linearVelocity.y);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_isFalling = true;
|
||||
_isOnLadder = false;
|
||||
}
|
||||
|
||||
|
||||
if (_isOnLadder || _isOnBridge)
|
||||
{
|
||||
_body.gravityScale = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_body.gravityScale = 1;
|
||||
}
|
||||
if (_isFalling)
|
||||
{
|
||||
_body.linearVelocity = new Vector2(0, _body.linearVelocity.y);
|
||||
SetWalkingAnimation(false);
|
||||
|
||||
if (block?.ElementSO.ElementType == MapElementType.Ladder)
|
||||
{
|
||||
_body.linearVelocity = Vector2.zero;
|
||||
_isOnLadder = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void Death()
|
||||
{
|
||||
OnCharacterDeath?.Invoke(this,EventArgs.Empty);
|
||||
}
|
||||
|
||||
private bool CanClimbUp()
|
||||
{
|
||||
var rayCastHit = Physics2D.Raycast(_capsuleCollider.bounds.center, Vector2.down, _capsuleCollider.size.y / 2,_mapLayer);
|
||||
if(rayCastHit)
|
||||
if(rayCastHit.collider.transform.GetComponent<MapElement>().ElementSO.ElementType==MapElementType.Ladder)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool CanGoDown()
|
||||
{
|
||||
var rayCastHit = Physics2D.RaycastAll(_capsuleCollider.bounds.center, Vector2.down, 0.5f, _mapLayer);
|
||||
var isNoladder = rayCastHit.Any(x => x.collider.transform.GetComponent<MapElement>().ElementSO.ElementType != MapElementType.Ladder);
|
||||
foreach (var hit in rayCastHit)
|
||||
{
|
||||
Debug.DrawLine(hit.point, hit.point + hit.normal.normalized * 0.2f, isNoladder? Color.blue: Color.red);
|
||||
}
|
||||
|
||||
if (isNoladder)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private MapElement GetMapElement()
|
||||
{
|
||||
var collider = BoxCast(_capsuleCollider.bounds.center, _cellSize, 0f, Vector3.forward, .01f, _mapLayer);
|
||||
Color color = Color.red;
|
||||
MapElement mapElement = null;
|
||||
if (collider.Length > 0)
|
||||
{
|
||||
var elements=collider.Select(x=>x.transform.GetComponent<MapElement>());
|
||||
mapElement = elements.Where(x => x.ElementSO.ElementType == MapElementType.Ladder).FirstOrDefault();
|
||||
if(mapElement == null)
|
||||
{
|
||||
mapElement = elements.First();
|
||||
}
|
||||
}
|
||||
|
||||
return mapElement;
|
||||
}
|
||||
|
||||
protected abstract void SetWalkingAnimation(bool isWalking);
|
||||
protected abstract void SetClimbingAnimation(bool isClimbing);
|
||||
|
||||
|
||||
|
||||
private void FlipCharacter()
|
||||
{
|
||||
Vector3 currentScale = gameObject.transform.localScale;
|
||||
currentScale.x *= -1;
|
||||
gameObject.transform.localScale = currentScale;
|
||||
|
||||
_facingRight = !_facingRight;
|
||||
}
|
||||
|
||||
static public Collider2D[] BoxCast(Vector2 origin, Vector2 size, float angle, Vector2 direction, float distance, int mask)
|
||||
{
|
||||
//RaycastHit2D hit = Physics2D.BoxCast(origin, size, angle, direction, distance, mask);
|
||||
var collider = Physics2D.OverlapBoxAll(origin, size, angle, mask);
|
||||
//Setting up the points to draw the cast
|
||||
Vector2 p1, p2, p3, p4, p5, p6, p7, p8;
|
||||
float w = size.x * 0.5f;
|
||||
float h = size.y * 0.5f;
|
||||
p1 = new Vector2(-w, h);
|
||||
p2 = new Vector2(w, h);
|
||||
p3 = new Vector2(w, -h);
|
||||
p4 = new Vector2(-w, -h);
|
||||
|
||||
Quaternion q = Quaternion.AngleAxis(angle, new Vector3(0, 0, 1));
|
||||
p1 = q * p1;
|
||||
p2 = q * p2;
|
||||
p3 = q * p3;
|
||||
p4 = q * p4;
|
||||
|
||||
p1 += origin;
|
||||
p2 += origin;
|
||||
p3 += origin;
|
||||
p4 += origin;
|
||||
|
||||
Vector2 realDistance = direction.normalized * distance;
|
||||
p5 = p1 + realDistance;
|
||||
p6 = p2 + realDistance;
|
||||
p7 = p3 + realDistance;
|
||||
p8 = p4 + realDistance;
|
||||
|
||||
|
||||
//Drawing the cast
|
||||
Color castColor = collider.Length > 0 ? Color.red : Color.green;
|
||||
Debug.DrawLine(p1, p2, castColor);
|
||||
Debug.DrawLine(p2, p3, castColor);
|
||||
Debug.DrawLine(p3, p4, castColor);
|
||||
Debug.DrawLine(p4, p1, castColor);
|
||||
|
||||
Debug.DrawLine(p5, p6, castColor);
|
||||
Debug.DrawLine(p6, p7, castColor);
|
||||
Debug.DrawLine(p7, p8, castColor);
|
||||
Debug.DrawLine(p8, p5, castColor);
|
||||
|
||||
Debug.DrawLine(p1, p5, Color.grey);
|
||||
Debug.DrawLine(p2, p6, Color.grey);
|
||||
Debug.DrawLine(p3, p7, Color.grey);
|
||||
Debug.DrawLine(p4, p8, Color.grey);
|
||||
|
||||
//collider
|
||||
//if (hit)
|
||||
//{
|
||||
// var color = hit.point.x > origin.x ? Color.yellow : Color.cyan;
|
||||
// Debug.DrawLine(hit.point, hit.point + hit.normal.normalized * 0.2f, color);
|
||||
//}
|
||||
|
||||
return collider;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02b165448a794b74992cf202965d79e4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,2 @@
|
||||
public enum TreasureType { Coin, Key }
|
||||
public enum MapElementType {Empty,Wall,Ladder,Bridge,BreakableWall,Water,BreakableWall_disabled }
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe09d7f62ac556c479103171cd371446
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Assets.Scripts
|
||||
{
|
||||
public interface IDoor
|
||||
{
|
||||
void OpenDoor();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62a1e4daba023c94f9fe4c576570cbf4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,461 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator
|
||||
// version 1.19.0
|
||||
// from Assets/Scripts/InputActions.inputactions
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
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<Vector2>()}");
|
||||
/// }
|
||||
///
|
||||
/// // Invoked when "Attack" action is either started, performed or canceled.
|
||||
/// public void OnAttack(InputAction.CallbackContext context)
|
||||
/// {
|
||||
/// Debug.Log($"OnAttack: {context.ReadValue<float>()}");
|
||||
/// }
|
||||
///
|
||||
/// #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"": [
|
||||
{
|
||||
""name"": ""Player"",
|
||||
""id"": ""a9631db6-afdf-47e4-a8a3-d63ab06f361c"",
|
||||
""actions"": [
|
||||
{
|
||||
""name"": ""Movement"",
|
||||
""type"": ""Value"",
|
||||
""id"": ""bc1a3c6a-5454-4e22-a4c4-e507bd5ef719"",
|
||||
""expectedControlType"": ""Vector2"",
|
||||
""processors"": """",
|
||||
""interactions"": """",
|
||||
""initialStateCheck"": true
|
||||
},
|
||||
{
|
||||
""name"": ""Fire"",
|
||||
""type"": ""Button"",
|
||||
""id"": ""15426cef-f42f-45e2-96a3-be5ccf4f7c77"",
|
||||
""expectedControlType"": ""Button"",
|
||||
""processors"": """",
|
||||
""interactions"": """",
|
||||
""initialStateCheck"": false
|
||||
}
|
||||
],
|
||||
""bindings"": [
|
||||
{
|
||||
""name"": ""2D Vector"",
|
||||
""id"": ""ec20865d-29b5-4923-a398-026e3b6a452a"",
|
||||
""path"": ""2DVector"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""Movement"",
|
||||
""isComposite"": true,
|
||||
""isPartOfComposite"": false
|
||||
},
|
||||
{
|
||||
""name"": ""up"",
|
||||
""id"": ""ec9e58f5-3e87-4b8e-98a0-d6f57dee5a62"",
|
||||
""path"": ""<Keyboard>/upArrow"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""Movement"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": true
|
||||
},
|
||||
{
|
||||
""name"": ""down"",
|
||||
""id"": ""6833e932-d60c-49ad-84eb-2f63e3847d53"",
|
||||
""path"": ""<Keyboard>/downArrow"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""Movement"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": true
|
||||
},
|
||||
{
|
||||
""name"": ""left"",
|
||||
""id"": ""aee692a9-6d5f-4fea-b555-8dc6c147efbd"",
|
||||
""path"": ""<Keyboard>/leftArrow"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""Movement"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": true
|
||||
},
|
||||
{
|
||||
""name"": ""right"",
|
||||
""id"": ""ba2ffdd7-4da3-4b20-9b49-14448c0a8a15"",
|
||||
""path"": ""<Keyboard>/rightArrow"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""Movement"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": true
|
||||
},
|
||||
{
|
||||
""name"": ""2D Vector"",
|
||||
""id"": ""2bc3f525-a5a8-4d0f-a679-5b0d8dcff168"",
|
||||
""path"": ""2DVector"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""Movement"",
|
||||
""isComposite"": true,
|
||||
""isPartOfComposite"": false
|
||||
},
|
||||
{
|
||||
""name"": ""up"",
|
||||
""id"": ""a7ed1fe9-4819-4055-840d-284172ef0cba"",
|
||||
""path"": ""<Gamepad>/leftStick/up"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""Movement"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": true
|
||||
},
|
||||
{
|
||||
""name"": ""down"",
|
||||
""id"": ""f1b7a29e-55b7-4a22-b2db-fceee993e456"",
|
||||
""path"": ""<Gamepad>/leftStick/down"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""Movement"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": true
|
||||
},
|
||||
{
|
||||
""name"": ""left"",
|
||||
""id"": ""e1be144e-9344-47d0-ad6a-4160bb893bcb"",
|
||||
""path"": ""<Gamepad>/leftStick/left"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""Movement"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": true
|
||||
},
|
||||
{
|
||||
""name"": ""right"",
|
||||
""id"": ""150c31e4-d3d8-4d14-9f07-3185561a86ba"",
|
||||
""path"": ""<Gamepad>/leftStick/right"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""Movement"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": true
|
||||
},
|
||||
{
|
||||
""name"": """",
|
||||
""id"": ""0b8928e8-bac0-49e9-b1bf-c272e35f6f52"",
|
||||
""path"": ""<Keyboard>/space"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""Fire"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
},
|
||||
{
|
||||
""name"": """",
|
||||
""id"": ""14e658e7-227f-47f6-94ad-fc988b635cb1"",
|
||||
""path"": ""<Gamepad>/buttonSouth"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""Fire"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
""controlSchemes"": []
|
||||
}");
|
||||
// Player
|
||||
m_Player = asset.FindActionMap("Player", throwIfNotFound: true);
|
||||
m_Player_Movement = m_Player.FindAction("Movement", throwIfNotFound: true);
|
||||
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);
|
||||
}
|
||||
|
||||
// Player
|
||||
private readonly InputActionMap m_Player;
|
||||
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;
|
||||
m_Wrapper.m_PlayerActionsCallbackInterfaces.Add(instance);
|
||||
@Movement.started += instance.OnMovement;
|
||||
@Movement.performed += instance.OnMovement;
|
||||
@Movement.canceled += instance.OnMovement;
|
||||
@Fire.started += instance.OnFire;
|
||||
@Fire.performed += instance.OnFire;
|
||||
@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;
|
||||
@Movement.performed -= instance.OnMovement;
|
||||
@Movement.canceled -= instance.OnMovement;
|
||||
@Fire.started -= instance.OnFire;
|
||||
@Fire.performed -= instance.OnFire;
|
||||
@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)
|
||||
UnregisterCallbacks(item);
|
||||
m_Wrapper.m_PlayerActionsCallbackInterfaces.Clear();
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 18dbff63b01a846438c203369e377e9a
|
||||
@@ -0,0 +1,164 @@
|
||||
{
|
||||
"name": "InputActions",
|
||||
"maps": [
|
||||
{
|
||||
"name": "Player",
|
||||
"id": "a9631db6-afdf-47e4-a8a3-d63ab06f361c",
|
||||
"actions": [
|
||||
{
|
||||
"name": "Movement",
|
||||
"type": "Value",
|
||||
"id": "bc1a3c6a-5454-4e22-a4c4-e507bd5ef719",
|
||||
"expectedControlType": "Vector2",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": true
|
||||
},
|
||||
{
|
||||
"name": "Fire",
|
||||
"type": "Button",
|
||||
"id": "15426cef-f42f-45e2-96a3-be5ccf4f7c77",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
}
|
||||
],
|
||||
"bindings": [
|
||||
{
|
||||
"name": "2D Vector",
|
||||
"id": "ec20865d-29b5-4923-a398-026e3b6a452a",
|
||||
"path": "2DVector",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Movement",
|
||||
"isComposite": true,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "up",
|
||||
"id": "ec9e58f5-3e87-4b8e-98a0-d6f57dee5a62",
|
||||
"path": "<Keyboard>/upArrow",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Movement",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "down",
|
||||
"id": "6833e932-d60c-49ad-84eb-2f63e3847d53",
|
||||
"path": "<Keyboard>/downArrow",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Movement",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "left",
|
||||
"id": "aee692a9-6d5f-4fea-b555-8dc6c147efbd",
|
||||
"path": "<Keyboard>/leftArrow",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Movement",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "right",
|
||||
"id": "ba2ffdd7-4da3-4b20-9b49-14448c0a8a15",
|
||||
"path": "<Keyboard>/rightArrow",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Movement",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "2D Vector",
|
||||
"id": "2bc3f525-a5a8-4d0f-a679-5b0d8dcff168",
|
||||
"path": "2DVector",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Movement",
|
||||
"isComposite": true,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "up",
|
||||
"id": "a7ed1fe9-4819-4055-840d-284172ef0cba",
|
||||
"path": "<Gamepad>/leftStick/up",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Movement",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "down",
|
||||
"id": "f1b7a29e-55b7-4a22-b2db-fceee993e456",
|
||||
"path": "<Gamepad>/leftStick/down",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Movement",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "left",
|
||||
"id": "e1be144e-9344-47d0-ad6a-4160bb893bcb",
|
||||
"path": "<Gamepad>/leftStick/left",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Movement",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "right",
|
||||
"id": "150c31e4-d3d8-4d14-9f07-3185561a86ba",
|
||||
"path": "<Gamepad>/leftStick/right",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Movement",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "0b8928e8-bac0-49e9-b1bf-c272e35f6f52",
|
||||
"path": "<Keyboard>/space",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Fire",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "14e658e7-227f-47f6-94ad-fc988b635cb1",
|
||||
"path": "<Gamepad>/buttonSouth",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Fire",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"controlSchemes": []
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3854f4534c5b594d903c0d62c0a4bbc
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
|
||||
generateWrapperCode: 1
|
||||
wrapperCodePath:
|
||||
wrapperClassName:
|
||||
wrapperCodeNamespace:
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class MainMenu : MonoBehaviour
|
||||
{
|
||||
public void Play()
|
||||
{
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex+1);
|
||||
}
|
||||
|
||||
public void Exit()
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f05380218a41df4e9cfb0cf40bd57f1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user