diff --git a/Assets/PlayerInputActions.inputactions b/Assets/PlayerInputActions.inputactions new file mode 100644 index 00000000..0ebf3177 --- /dev/null +++ b/Assets/PlayerInputActions.inputactions @@ -0,0 +1,98 @@ +{ + "name": "PlayerInputActions", + "maps": [ + { + "name": "PlayerActions", + "id": "afe61549-bd16-4f1a-b99d-fae16d92f884", + "actions": [ + { + "name": "Move", + "type": "Value", + "id": "c3c9e3ae-85ad-4230-be38-96f7073a2512", + "expectedControlType": "Vector2", + "processors": "", + "interactions": "", + "initialStateCheck": true + }, + { + "name": "Jump", + "type": "Button", + "id": "2b8314f6-d960-4f3c-bf1b-c727cc33ac98", + "expectedControlType": "Button", + "processors": "", + "interactions": "", + "initialStateCheck": false + } + ], + "bindings": [ + { + "name": "WASD", + "id": "31e528da-91bd-4b16-8c28-1264c3fc2c63", + "path": "2DVector", + "interactions": "", + "processors": "", + "groups": "", + "action": "Move", + "isComposite": true, + "isPartOfComposite": false + }, + { + "name": "up", + "id": "51097edb-6ea7-427b-b247-f1b1bc54ecbf", + "path": "/w", + "interactions": "", + "processors": "", + "groups": "", + "action": "Move", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "down", + "id": "156ebf66-27fb-46e3-936f-1f243ea576cd", + "path": "/s", + "interactions": "", + "processors": "", + "groups": "", + "action": "Move", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "left", + "id": "3336a73b-a048-4562-a7e0-3d0a2f4ec2e3", + "path": "/a", + "interactions": "", + "processors": "", + "groups": "", + "action": "Move", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "right", + "id": "0c80177c-f0b5-4ee2-a01f-a1d1beaf9217", + "path": "/d", + "interactions": "", + "processors": "", + "groups": "", + "action": "Move", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "", + "id": "c6b9a9fe-e10e-4801-868d-55667ac3a0df", + "path": "/space", + "interactions": "", + "processors": "", + "groups": "", + "action": "Jump", + "isComposite": false, + "isPartOfComposite": false + } + ] + } + ], + "controlSchemes": [] +} \ No newline at end of file diff --git a/Assets/PlayerInputActions.inputactions.meta b/Assets/PlayerInputActions.inputactions.meta new file mode 100644 index 00000000..9e44d9da --- /dev/null +++ b/Assets/PlayerInputActions.inputactions.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 4b64756c455832a41b5cb3e6c08cbd83 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3} + generateWrapperCode: 1 + wrapperCodePath: + wrapperClassName: + wrapperCodeNamespace: diff --git a/Assets/SWPPT3/Scenes/Stage1Test.unity b/Assets/SWPPT3/Scenes/Stage1Test.unity index b7aa8fdd..36164c48 100644 --- a/Assets/SWPPT3/Scenes/Stage1Test.unity +++ b/Assets/SWPPT3/Scenes/Stage1Test.unity @@ -2868,6 +2868,199 @@ PrefabInstance: objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 4b437f1c2454a2c409b1b7f35e69d661, type: 3} +--- !u!1 &1027151879 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1027151886} + - component: {fileID: 1027151885} + - component: {fileID: 1027151884} + - component: {fileID: 1027151882} + - component: {fileID: 1027151881} + - component: {fileID: 1027151880} + - component: {fileID: 1027151887} + m_Layer: 0 + m_Name: TestPlayer + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1027151880 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1027151879} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3c834ef87520fa146a131b8e2e184ab9, type: 3} + m_Name: + m_EditorClassIdentifier: + _rb: {fileID: 0} + jumpForce: 5 +--- !u!114 &1027151881 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1027151879} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 62899f850307741f2a39c98a8b639597, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Actions: {fileID: -944628639613478452, guid: 4b64756c455832a41b5cb3e6c08cbd83, + type: 3} + m_NotificationBehavior: 2 + m_UIInputModule: {fileID: 0} + m_DeviceLostEvent: + m_PersistentCalls: + m_Calls: [] + m_DeviceRegainedEvent: + m_PersistentCalls: + m_Calls: [] + m_ControlsChangedEvent: + m_PersistentCalls: + m_Calls: [] + m_ActionEvents: + - m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 1027151880} + m_TargetAssemblyTypeName: SWPPT3.Main.Player.Player, Main + m_MethodName: OnMove + m_Mode: 0 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + m_ActionId: c3c9e3ae-85ad-4230-be38-96f7073a2512 + m_ActionName: PlayerActions/Move[/Keyboard/w,/Keyboard/s,/Keyboard/a,/Keyboard/d] + - m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 1027151880} + m_TargetAssemblyTypeName: SWPPT3.Main.Player.Player, Main + m_MethodName: OnJump + m_Mode: 0 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + m_ActionId: 2b8314f6-d960-4f3c-bf1b-c727cc33ac98 + m_ActionName: PlayerActions/Jump[/Keyboard/space] + m_NeverAutoSwitchControlSchemes: 0 + m_DefaultControlScheme: + m_DefaultActionMap: PlayerActions + m_SplitScreenIndex: -1 + m_Camera: {fileID: 0} +--- !u!65 &1027151882 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1027151879} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!23 &1027151884 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1027151879} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_AdditionalVertexStreams: {fileID: 0} +--- !u!33 &1027151885 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1027151879} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &1027151886 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1027151879} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0.22, y: 0.86, z: 4.3} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!54 &1027151887 +Rigidbody: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1027151879} + serializedVersion: 2 + m_Mass: 1 + m_Drag: 0 + m_AngularDrag: 0.05 + m_UseGravity: 1 + m_IsKinematic: 0 + m_Interpolate: 0 + m_Constraints: 0 + m_CollisionDetection: 0 --- !u!1001 &1033496322 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/SWPPT3/Scripts/Main/PlayerLogic/Player.cs b/Assets/SWPPT3/Scripts/Main/PlayerLogic/Player.cs index e8eecab0..9986c73e 100644 --- a/Assets/SWPPT3/Scripts/Main/PlayerLogic/Player.cs +++ b/Assets/SWPPT3/Scripts/Main/PlayerLogic/Player.cs @@ -1,16 +1,30 @@ +using System; using System.Collections.Generic; -using Unity; using UnityEngine; using SWPPT3.Main.Prop; +using UnityEngine.InputSystem; using SWPPT3.Main.PlayerLogic.State; -namespace SWPPT3.Main.PlayerLogic +namespace SWPPT3.Main.Player { public class Player : MonoBehaviour { + public static Player Instance { get; private set; } + private States _currentState = States.Slime; + private Vector2 _inputMovement; + private Vector3 _moveDirection; + private float _moveSpeed = 4f; + public States CurrentState => _currentState; + + [SerializeField] + private Rigidbody _rb; + public float jumpForce = 5f; + private PlayerState PlayerState => _playerStates[_currentState]; + private PlayerInputActions _inputActions; // New Input System 추가 + private readonly Dictionary _playerStates = new() { { States.Metal, new MetalState() }, @@ -18,9 +32,66 @@ public class Player : MonoBehaviour { States.Slime, new SlimeState() }, }; - public void PlayerMove() + private void Awake() + { + // 싱글톤 패턴 설정 + if (Instance == null) + { + Instance = this; + DontDestroyOnLoad(gameObject); + } + else + { + Destroy(gameObject); + return; + } + _rb = GetComponent(); + _inputActions = new PlayerInputActions(); + _inputActions.PlayerActions.Move.performed += OnMove; + _inputActions.PlayerActions.Move.canceled += OnMove; + _inputActions.PlayerActions.Jump.performed += OnJump; + } + + private void OnEnable() + { + _inputActions.Enable(); + } + + private void OnDisable() + { + _inputActions.Disable(); + } + + private void Update() + { + // 이동 방향이 있을 때만 이동 + if (_moveDirection != Vector3.zero) + { + transform.rotation = Quaternion.LookRotation(_moveDirection); + transform.Translate(Vector3.forward * (_moveSpeed * Time.deltaTime)); + } + } + + // 이동 입력 처리 + public void OnMove(InputAction.CallbackContext context) + { + Vector2 input = context.ReadValue(); + _moveDirection = input != Vector2.zero ? new Vector3(input.x, 0f, input.y) : Vector3.zero; + } + + public void OnJump(InputAction.CallbackContext context) { + if (IsGrounded()) // 바닥에 있을 때만 점프 + { + _rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse); + + } + } + private bool IsGrounded() + { + // 간단한 바닥 체크 예시 + return Physics.Raycast(transform.position, Vector3.down, 1.1f); } public void ChangeState(States state) @@ -33,12 +104,13 @@ public void InteractWithObject(PropBase prop) PlayerState.InteractWithProp(prop); } - void OnCollisionEnter(Collision collision) + private void OnCollisionEnter(Collision collision) { var obstacle = collision.gameObject.GetComponent(); - InteractWithObject(obstacle); + if (obstacle != null) + { + InteractWithObject(obstacle); + } } - - } } diff --git a/Assets/SWPPT3/Scripts/Main/PlayerLogic/PlayerInputActions.cs b/Assets/SWPPT3/Scripts/Main/PlayerLogic/PlayerInputActions.cs new file mode 100644 index 00000000..a3cc2fe8 --- /dev/null +++ b/Assets/SWPPT3/Scripts/Main/PlayerLogic/PlayerInputActions.cs @@ -0,0 +1,241 @@ +//------------------------------------------------------------------------------ +// +// This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator +// version 1.7.0 +// from Assets/PlayerInputActions.inputactions +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine.InputSystem; +using UnityEngine.InputSystem.Utilities; + +public partial class @PlayerInputActions: IInputActionCollection2, IDisposable +{ + public InputActionAsset asset { get; } + public @PlayerInputActions() + { + asset = InputActionAsset.FromJson(@"{ + ""name"": ""PlayerInputActions"", + ""maps"": [ + { + ""name"": ""PlayerActions"", + ""id"": ""afe61549-bd16-4f1a-b99d-fae16d92f884"", + ""actions"": [ + { + ""name"": ""Move"", + ""type"": ""Value"", + ""id"": ""c3c9e3ae-85ad-4230-be38-96f7073a2512"", + ""expectedControlType"": ""Vector2"", + ""processors"": """", + ""interactions"": """", + ""initialStateCheck"": true + }, + { + ""name"": ""Jump"", + ""type"": ""Button"", + ""id"": ""2b8314f6-d960-4f3c-bf1b-c727cc33ac98"", + ""expectedControlType"": ""Button"", + ""processors"": """", + ""interactions"": """", + ""initialStateCheck"": false + } + ], + ""bindings"": [ + { + ""name"": ""WASD"", + ""id"": ""31e528da-91bd-4b16-8c28-1264c3fc2c63"", + ""path"": ""2DVector"", + ""interactions"": """", + ""processors"": """", + ""groups"": """", + ""action"": ""Move"", + ""isComposite"": true, + ""isPartOfComposite"": false + }, + { + ""name"": ""up"", + ""id"": ""51097edb-6ea7-427b-b247-f1b1bc54ecbf"", + ""path"": ""/w"", + ""interactions"": """", + ""processors"": """", + ""groups"": """", + ""action"": ""Move"", + ""isComposite"": false, + ""isPartOfComposite"": true + }, + { + ""name"": ""down"", + ""id"": ""156ebf66-27fb-46e3-936f-1f243ea576cd"", + ""path"": ""/s"", + ""interactions"": """", + ""processors"": """", + ""groups"": """", + ""action"": ""Move"", + ""isComposite"": false, + ""isPartOfComposite"": true + }, + { + ""name"": ""left"", + ""id"": ""3336a73b-a048-4562-a7e0-3d0a2f4ec2e3"", + ""path"": ""/a"", + ""interactions"": """", + ""processors"": """", + ""groups"": """", + ""action"": ""Move"", + ""isComposite"": false, + ""isPartOfComposite"": true + }, + { + ""name"": ""right"", + ""id"": ""0c80177c-f0b5-4ee2-a01f-a1d1beaf9217"", + ""path"": ""/d"", + ""interactions"": """", + ""processors"": """", + ""groups"": """", + ""action"": ""Move"", + ""isComposite"": false, + ""isPartOfComposite"": true + }, + { + ""name"": """", + ""id"": ""c6b9a9fe-e10e-4801-868d-55667ac3a0df"", + ""path"": ""/space"", + ""interactions"": """", + ""processors"": """", + ""groups"": """", + ""action"": ""Jump"", + ""isComposite"": false, + ""isPartOfComposite"": false + } + ] + } + ], + ""controlSchemes"": [] +}"); + // PlayerActions + m_PlayerActions = asset.FindActionMap("PlayerActions", throwIfNotFound: true); + m_PlayerActions_Move = m_PlayerActions.FindAction("Move", throwIfNotFound: true); + m_PlayerActions_Jump = m_PlayerActions.FindAction("Jump", throwIfNotFound: true); + } + + public void Dispose() + { + UnityEngine.Object.Destroy(asset); + } + + public InputBinding? bindingMask + { + get => asset.bindingMask; + set => asset.bindingMask = value; + } + + public ReadOnlyArray? devices + { + get => asset.devices; + set => asset.devices = value; + } + + public ReadOnlyArray controlSchemes => asset.controlSchemes; + + public bool Contains(InputAction action) + { + return asset.Contains(action); + } + + public IEnumerator GetEnumerator() + { + return asset.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public void Enable() + { + asset.Enable(); + } + + public void Disable() + { + asset.Disable(); + } + + public IEnumerable bindings => asset.bindings; + + public InputAction FindAction(string actionNameOrId, bool throwIfNotFound = false) + { + return asset.FindAction(actionNameOrId, throwIfNotFound); + } + + public int FindBinding(InputBinding bindingMask, out InputAction action) + { + return asset.FindBinding(bindingMask, out action); + } + + // PlayerActions + private readonly InputActionMap m_PlayerActions; + private List m_PlayerActionsActionsCallbackInterfaces = new List(); + private readonly InputAction m_PlayerActions_Move; + private readonly InputAction m_PlayerActions_Jump; + public struct PlayerActionsActions + { + private @PlayerInputActions m_Wrapper; + public PlayerActionsActions(@PlayerInputActions wrapper) { m_Wrapper = wrapper; } + public InputAction @Move => m_Wrapper.m_PlayerActions_Move; + public InputAction @Jump => m_Wrapper.m_PlayerActions_Jump; + public InputActionMap Get() { return m_Wrapper.m_PlayerActions; } + public void Enable() { Get().Enable(); } + public void Disable() { Get().Disable(); } + public bool enabled => Get().enabled; + public static implicit operator InputActionMap(PlayerActionsActions set) { return set.Get(); } + public void AddCallbacks(IPlayerActionsActions instance) + { + if (instance == null || m_Wrapper.m_PlayerActionsActionsCallbackInterfaces.Contains(instance)) return; + m_Wrapper.m_PlayerActionsActionsCallbackInterfaces.Add(instance); + @Move.started += instance.OnMove; + @Move.performed += instance.OnMove; + @Move.canceled += instance.OnMove; + @Jump.started += instance.OnJump; + @Jump.performed += instance.OnJump; + @Jump.canceled += instance.OnJump; + } + + private void UnregisterCallbacks(IPlayerActionsActions instance) + { + @Move.started -= instance.OnMove; + @Move.performed -= instance.OnMove; + @Move.canceled -= instance.OnMove; + @Jump.started -= instance.OnJump; + @Jump.performed -= instance.OnJump; + @Jump.canceled -= instance.OnJump; + } + + public void RemoveCallbacks(IPlayerActionsActions instance) + { + if (m_Wrapper.m_PlayerActionsActionsCallbackInterfaces.Remove(instance)) + UnregisterCallbacks(instance); + } + + public void SetCallbacks(IPlayerActionsActions instance) + { + foreach (var item in m_Wrapper.m_PlayerActionsActionsCallbackInterfaces) + UnregisterCallbacks(item); + m_Wrapper.m_PlayerActionsActionsCallbackInterfaces.Clear(); + AddCallbacks(instance); + } + } + public PlayerActionsActions @PlayerActions => new PlayerActionsActions(this); + public interface IPlayerActionsActions + { + void OnMove(InputAction.CallbackContext context); + void OnJump(InputAction.CallbackContext context); + } +} diff --git a/Assets/SWPPT3/Scripts/Main/PlayerLogic/PlayerInputActions.cs.meta b/Assets/SWPPT3/Scripts/Main/PlayerLogic/PlayerInputActions.cs.meta new file mode 100644 index 00000000..779daf81 --- /dev/null +++ b/Assets/SWPPT3/Scripts/Main/PlayerLogic/PlayerInputActions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5dc246f4f0adcea4e96fe5ce96d5f172 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: