플레이어 MVP 로직 분할

This commit is contained in:
NTG_Lenovo 2025-07-04 18:21:40 +09:00
parent 3f9fd4227a
commit 689a510d71
26 changed files with 225 additions and 148 deletions

View File

@ -105,6 +105,7 @@ MonoBehaviour:
- Prefab
- Atlas
- Sprite
- So
m_SchemaTemplates: []
m_GroupTemplateObjects:
- {fileID: 11400000, guid: f804fe78e7005554f9ba60273aade35b, type: 2}

View File

@ -27,6 +27,12 @@ MonoBehaviour:
m_SerializedLabels:
- Prefab
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: ddb0db863be8f254bb8a8f07d39a960e
m_Address: RestaurantPlayerDataSo
m_ReadOnly: 0
m_SerializedLabels:
- So
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: e15933f76da90e742866563b5cd9e45f
m_Address: Gold
m_ReadOnly: 0

View File

@ -48,3 +48,14 @@ MonoBehaviour:
LabelMode: 1
simplified: 0
addressReplacement: ${asset}
- path: Assets/_Datas/Addressables/(?<category>[^/]+)/(?<asset>.*)\.asset
matchType: 1
groupName:
groupTemplate: {fileID: 11400000, guid: f804fe78e7005554f9ba60273aade35b, type: 2}
groupTemplateApplicationMode: 0
labelRefs: []
dynamicLabels:
- So
LabelMode: 1
simplified: 0
addressReplacement: ${asset}

View File

@ -49,7 +49,7 @@ MonoBehaviour:
m_AdditionalLightShadowsSupported: 1
m_AdditionalLightsShadowmapResolution: 4096
m_AdditionalLightsShadowResolutionTierLow: 256
m_AdditionalLightsShadowResolutionTierMedium: 256
m_AdditionalLightsShadowResolutionTierMedium: 512
m_AdditionalLightsShadowResolutionTierHigh: 1024
m_ReflectionProbeBlending: 1
m_ReflectionProbeBoxProjection: 1

View File

@ -929,7 +929,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 850a1aa7f7d1eb94a894d47d98a02d8f, type: 3}
m_Name:
m_EditorClassIdentifier:
nameText: {fileID: 1640982677}
--- !u!114 &300359722
MonoBehaviour:
m_ObjectHideFlags: 0
@ -2540,6 +2539,7 @@ GameObject:
- component: {fileID: 968554883}
- component: {fileID: 968554882}
- component: {fileID: 968554884}
- component: {fileID: 968554885}
m_Layer: 0
m_Name: RestaurantPlayer
m_TagString: Untagged
@ -2625,15 +2625,21 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 620909d88f805ee4898b9af964a7f0e8, type: 3}
m_Name:
m_EditorClassIdentifier:
_moveSpeed: 7
_moveSpeedMultiplier: 1
_dashSpeed: 20
_dashTime: 0.2
_dashCooldown: 0.5
_dashParticle: {fileID: 0}
_walkingSfxName: TycoonPlayerWalking
_dashSfxName: TycoonPlayerDashing
cellManager: {fileID: 1015166837}
--- !u!114 &968554885
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 968554876}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c665f9c268555a74a8a805d67d09c80e, type: 3}
m_Name:
m_EditorClassIdentifier:
_rigidbody: {fileID: 0}
_visualLook: {fileID: 0}
--- !u!114 &985479691
MonoBehaviour:
m_ObjectHideFlags: 0

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: f9d8444159027d447816c0ee19de105f
guid: a551bfcf9a2e675418ebe5dd8bd6c60d
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@ -0,0 +1,9 @@
namespace DDD
{
public interface IPlayerState
{
void Enter();
void Update();
void Exit();
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c111bfa40d649ac4c9d401efa650734d

View File

@ -0,0 +1,19 @@
namespace DDD
{
public class PlayerStateMachine
{
private IPlayerState _currentState;
public void ChangeState(IPlayerState newState)
{
_currentState?.Exit();
_currentState = newState;
_currentState.Enter();
}
public void Update()
{
_currentState?.Update();
}
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 2887dac388e7a244585d84329954e38f

View File

@ -1,6 +1,6 @@
using System.Collections;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.InputSystem;
namespace DDD
@ -8,53 +8,20 @@ namespace DDD
public class RestaurantPlayer : MonoBehaviour
{
#region Variables
private Rigidbody _rigidbody;
private Transform _visualLook;
// Move
[SerializeField, Range(1f, 20f), Tooltip("이동 속도")]
private float _moveSpeed = 7f;
[SerializeField]
private float _moveSpeedMultiplier = 1f;
private bool _isMoveEnabled = true;
private bool _isMoving;
// Dash
[Title("대쉬")]
[SerializeField, Range(1f, 50f), Tooltip("대쉬 속도")]
private float _dashSpeed = 20f;
[SerializeField, Range(0.1f, 1f), Tooltip("대쉬 시간")]
private float _dashTime = 0.2f;
[SerializeField, Range(0f, 5f), Tooltip("대쉬 쿨타임")]
private float _dashCooldown = 0.5f;
[SerializeField]
private ParticleSystem _dashParticle;
[Title("사운드")]
[SerializeField]
private string _walkingSfxName = "TycoonPlayerWalking";
[SerializeField]
private string _dashSfxName = "TycoonPlayerDashing";
private bool _isDashEnabled = true;
private bool _isDashing;
private bool _isDashCoolDownActive;
private Vector3 _inputDirection;
private Vector3 _currentDirection = Vector3.back;
private RestaurantPlayerDataSo _playerData;
private RestaurantPlayerView _playerView;
private InputAction _moveAction;
private InputAction _dashAction;
private Coroutine _dashInstance;
private Vector3 _inputDirection;
private Vector3 _currentDirection = Vector3.back;
private bool _isMoving;
private bool _isDashing;
private bool _isDashCoolDownActive;
private float _finalSpeed;
#endregion
@ -65,7 +32,8 @@ public class RestaurantPlayer : MonoBehaviour
private void Awake()
{
InitializeComponents();
_playerData = Addressables.LoadAssetAsync<RestaurantPlayerDataSo>("RestaurantPlayerDataSo").WaitForCompletion();
_playerView = GetComponent<RestaurantPlayerView>();
}
private void Start()
@ -78,13 +46,13 @@ private void Start()
_dashAction.performed += OnDash;
}
public CellManager cellManager;
//public CellManager cellManager;
private void Update()
{
FlipVisualLook();
//UpdateCell
cellManager.SetupCell(transform.position);
//cellManager.SetupCell(transform.position);
}
private void FixedUpdate()
@ -98,49 +66,33 @@ private void OnDestroy()
{
_moveAction.performed -= OnMove;
_moveAction.canceled -= OnMove;
// _dashAction.performed -= OnDash;
}
#endregion
// Initialize Methods
#region Initialize Methods
private void InitializeComponents()
{
_rigidbody = GetComponent<Rigidbody>();
_visualLook = transform.Find("VisualLook");
_dashAction.performed -= OnDash;
}
#endregion
// Methods
#region Methods
// Event methods
public void SetCurrentDirection(Vector3 normalDirection)
{
if (normalDirection == Vector3.zero) return;
_currentDirection = normalDirection;
}
// Methods
private void FlipVisualLook()
{
var localScale = _visualLook.localScale;
Vector3 localScale = _playerView.GetLocalScale();
localScale.x = _currentDirection.x switch
{
> 0.01f => -Mathf.Abs(localScale.x),
< -0.01f => Mathf.Abs(localScale.x),
_ => localScale.x
};
_visualLook.localScale = localScale;
_playerView.SetLocalScale(localScale);
}
// Move
public void OnMove(InputAction.CallbackContext context)
{
var movementInput = _moveAction.ReadValue<Vector2>();
@ -149,7 +101,7 @@ public void OnMove(InputAction.CallbackContext context)
public bool CanMove()
{
return _isMoveEnabled && !_isDashing;
return _playerData.IsMoveEnabled && !_isDashing;
}
public void Move()
@ -157,14 +109,10 @@ public void Move()
SetCurrentDirection(_inputDirection);
_isMoving = _inputDirection != Vector3.zero;
var finalVelocity = _inputDirection * (_moveSpeed * _moveSpeedMultiplier);
if (!_rigidbody.isKinematic)
{
_rigidbody.linearVelocity = finalVelocity;
}
var finalVelocity = _inputDirection * _playerData.MoveSpeed;
_playerView.SetVelocity(finalVelocity);
}
// Dash
public void OnDash(InputAction.CallbackContext context)
{
if (!CanDash()) return;
@ -174,7 +122,7 @@ public void OnDash(InputAction.CallbackContext context)
public bool CanDash()
{
return _isDashEnabled && !_isDashing && !_isDashCoolDownActive;
return _playerData.IsDashEnabled && !_isDashing && !_isDashCoolDownActive;
}
public void Dash()
@ -186,12 +134,9 @@ private IEnumerator DashCoroutine()
{
_isDashing = true;
_isDashCoolDownActive = true;
if (_dashParticle)
{
_dashParticle.Play();
}
_playerView.PlayDashParticle();
AudioManager.Instance.PlaySfx(_dashSfxName);
AudioManager.Instance.PlaySfx(_playerData.DashSfxName);
var dashDirection = _inputDirection;
if (dashDirection == Vector3.zero)
@ -200,32 +145,30 @@ private IEnumerator DashCoroutine()
}
var elapsedTime = 0f;
while (elapsedTime <= _dashTime)
while (elapsedTime <= _playerData.DashTime)
{
var finalVelocity = dashDirection * _dashSpeed;
_rigidbody.linearVelocity = finalVelocity;
var finalVelocity = dashDirection * _playerData.DashSpeed;
_playerView.SetVelocity(finalVelocity);
elapsedTime += Time.fixedDeltaTime;
yield return new WaitForFixedUpdate();
}
//var newDashCooldown = DashCooldown - TycoonManager.Instance.TycoonStatus.PlayerDashCooldownReduction;
EndDash(_dashCooldown);
EndDash(_playerData.DashCooldown);
}
public void EndDash(float dashCooldown = float.PositiveInfinity)
{
Utils.EndUniqueCoroutine(this, ref _dashInstance);
_rigidbody.linearVelocity = Vector3.zero;
_playerView.SetVelocity(Vector3.zero);
_isDashing = false;
if (float.IsPositiveInfinity(dashCooldown))
{
dashCooldown = _dashCooldown;
dashCooldown = _playerData.DashCooldown;
}
// TODO : ui 연동
//EventManager.InvokeDashCooldown(dashCooldown);
StartCoroutine(Utils.CoolDownCoroutine(dashCooldown, () => _isDashCoolDownActive = false));
}

View File

@ -0,0 +1,20 @@
using UnityEngine;
using UnityEngine.Serialization;
namespace DDD
{
[CreateAssetMenu(fileName = "RestaurantPlayerDataSo", menuName = "ScriptableObjects/RestaurantPlayerDataSo")]
public class RestaurantPlayerDataSo : ScriptableObject
{
public bool IsMoveEnabled = true;
public float MoveSpeed = 7f;
public bool IsDashEnabled = true;
public float DashSpeed = 20f;
public float DashTime = 0.2f;
public float DashCooldown = 0.5f;
public string WalkingSfxName;
public string DashSfxName;
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5583898a24cc9c7419aec8b01ee0fde4

View File

@ -0,0 +1,29 @@
using UnityEngine;
namespace DDD
{
public class RestaurantPlayerView : MonoBehaviour
{
private Rigidbody _rigidbody;
private Transform _visualLook;
private ParticleSystem _dashParticle;
private void Awake()
{
_rigidbody = GetComponent<Rigidbody>();
_visualLook = transform.Find("VisualLook");
}
public void SetVelocity(Vector3 velocity) => _rigidbody.linearVelocity = velocity;
public Vector3 GetLocalScale() => _visualLook.localScale;
public void SetLocalScale(Vector3 localScale) => _visualLook.localScale = localScale;
public void PlayDashParticle()
{
if (_dashParticle)
{
_dashParticle.Play();
}
}
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c665f9c268555a74a8a805d67d09c80e

View File

@ -21,7 +21,7 @@ TextureImporter:
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
isReadable: 1
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
@ -39,13 +39,13 @@ TextureImporter:
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 0
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
spriteExtrude: 2
spriteMeshType: 0
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 512
@ -72,7 +72,7 @@ TextureImporter:
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
@ -133,6 +133,8 @@ TextureImporter:
edges: []
weights: []
secondaryTextures: []
spriteCustomMetadata:
entries: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0

View File

@ -21,7 +21,7 @@ TextureImporter:
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
isReadable: 1
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
@ -39,15 +39,15 @@ TextureImporter:
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 0
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteExtrude: 2
spriteMeshType: 0
alignment: 9
spritePivot: {x: 0.5, y: 0.115234375}
spritePixelsToUnits: 512
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
@ -72,7 +72,7 @@ TextureImporter:
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0

View File

@ -1,6 +1,6 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &5799723711254518527
--- !u!1 &607766449014220492
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
@ -8,7 +8,7 @@ GameObject:
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5765335169201649049}
- component: {fileID: 5111549818748911864}
m_Layer: 0
m_Name: Barrel
m_TagString: Untagged
@ -16,23 +16,23 @@ GameObject:
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5765335169201649049
--- !u!4 &5111549818748911864
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5799723711254518527}
m_GameObject: {fileID: 607766449014220492}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 1
m_Children:
- {fileID: 8594072857435888823}
- {fileID: 3583085206966600140}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &7282862855117613265
--- !u!1 &3450239667471230788
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
@ -40,8 +40,8 @@ GameObject:
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8594072857435888823}
- component: {fileID: 7771024025582628391}
- component: {fileID: 3583085206966600140}
- component: {fileID: 2541705287342940117}
m_Layer: 0
m_Name: VisualLook
m_TagString: Untagged
@ -49,28 +49,28 @@ GameObject:
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8594072857435888823
--- !u!4 &3583085206966600140
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7282862855117613265}
m_GameObject: {fileID: 3450239667471230788}
serializedVersion: 2
m_LocalRotation: {x: 0.34202015, y: 0, z: 0, w: 0.9396927}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 1
m_Children: []
m_Father: {fileID: 5765335169201649049}
m_Father: {fileID: 5111549818748911864}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &7771024025582628391
--- !u!212 &2541705287342940117
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7282862855117613265}
m_GameObject: {fileID: 3450239667471230788}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a3aca99aba821894ca9ce54a3647cca6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,20 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5583898a24cc9c7419aec8b01ee0fde4, type: 3}
m_Name: RestaurantPlayerDataSo
m_EditorClassIdentifier:
IsMoveEnabled: 1
MoveSpeed: 7
IsDashEnabled: 1
DashSpeed: 20
DashTime: 0.2
DashCooldown: 0.5

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ddb0db863be8f254bb8a8f07d39a960e
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -4,9 +4,9 @@ SpriteAtlasImporter:
externalObjects: {}
textureSettings:
serializedVersion: 2
anisoLevel: 0
compressionQuality: 0
maxTextureSize: 0
anisoLevel: 1
compressionQuality: 50
maxTextureSize: 2048
textureCompression: 0
filterMode: 1
generateMipMaps: 0
@ -17,10 +17,10 @@ SpriteAtlasImporter:
packingSettings:
serializedVersion: 2
padding: 4
blockOffset: 0
blockOffset: 1
allowAlphaSplitting: 0
enableRotation: 0
enableTightPacking: 0
enableRotation: 1
enableTightPacking: 1
enableAlphaDilation: 0
secondaryTextureSettings: {}
variantMultiplier: 1

View File

@ -21,7 +21,7 @@ TextureImporter:
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
isReadable: 1
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
@ -46,8 +46,8 @@ TextureImporter:
spriteMode: 1
spriteExtrude: 2
spriteMeshType: 0
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
alignment: 9
spritePivot: {x: 0.5, y: 0}
spritePixelsToUnits: 512
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
@ -119,19 +119,6 @@ TextureImporter:
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: iOS
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []