Skip to content

Commit

Permalink
Merge pull request #54 from Joseph-Cha/PlayerMoveImplement
Browse files Browse the repository at this point in the history
Player InputController에서 Input EventCallback 구현
  • Loading branch information
Joseph-Cha authored Jul 15, 2021
2 parents 1fe033d + 59c41ec commit 1382ab4
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 11 deletions.
17 changes: 16 additions & 1 deletion Assets/Prefabs/Player.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ MonoBehaviour:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
Expand Down Expand Up @@ -143,6 +144,7 @@ GameObject:
m_Component:
- component: {fileID: 1088201759388368952}
- component: {fileID: -4918777028982639273}
- component: {fileID: 982126869446169702}
m_Layer: 0
m_Name: Player
m_TagString: Untagged
Expand Down Expand Up @@ -177,7 +179,19 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1104f1531ceb2764f8abe95a4d8a31d4, type: 3}
m_Name:
m_EditorClassIdentifier:
PlayerNameText: {fileID: 4456301776422149752}
--- !u!114 &982126869446169702
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6148194559994387846}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e2a5cc2b780cbcb46a30839c914574f3, type: 3}
m_Name:
m_EditorClassIdentifier:
PlayerNameText: {fileID: 0}
--- !u!1 &7585238226375558454
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -260,6 +274,7 @@ MonoBehaviour:
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
m_PresetInfoIsWorld: 0
--- !u!114 &8469893116707368420
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
2 changes: 1 addition & 1 deletion Assets/Script/Data/StartData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public class StartData : MonoBehaviour
public TMP_InputField PlayerName;
public void SavePlayerData()
{
PlayerPrefs.SetString("Name", PlayerName.text);
PlayerPrefs.SetString(nameof(Player.playerName), PlayerName.text);
}
}
2 changes: 1 addition & 1 deletion Assets/Script/Manager/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class GameManager : MonoBehaviour
private void OnEnable()
{
remainingTime = startTime;
InvokeRepeating("CountDown", 0, 1);
InvokeRepeating(nameof(GameManager.CountDown), 0, 1);
}
private void Start()
{
Expand Down
25 changes: 22 additions & 3 deletions Assets/Script/Manager/InputController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Collections;
using System.Collections.Generic;
using MyDelegate;
using UnityEngine;

Expand All @@ -10,6 +8,27 @@ public class InputController : MonoBehaviour, IInputDirection
// Update is called once per frame
void Update()
{

Event e = Event.current;
if (e.isKey)
{
switch(e.keyCode)
{
case KeyCode.RightArrow:
DirectoinInput?.Invoke(InputInfo.Right);
break;

case KeyCode.LeftArrow:
DirectoinInput?.Invoke(InputInfo.Left);
break;

case KeyCode.DownArrow:
DirectoinInput?.Invoke(InputInfo.Down);
break;

case KeyCode.UpArrow:
DirectoinInput?.Invoke(InputInfo.Up);
break;
}
}
}
}
11 changes: 6 additions & 5 deletions Assets/Script/Player/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
public class Player : MonoBehaviour
{
public IInputDirection InputDirection;
public Vector2Int Position { get; set; }
public string Name { get; set; }
public Vector2Int CurPosition { get; set; }
public string playerName { get; set; }
private void Awake()
{
InputDirection.DirectoinInput += UpdateDestination;
Expand All @@ -16,14 +16,15 @@ private void Awake()

public void GetPlayerData()
{
if(PlayerPrefs.HasKey("Name"))
if(PlayerPrefs.HasKey(nameof(Player.playerName)))
{
Name = PlayerPrefs.GetString("Name");
playerName = PlayerPrefs.GetString(nameof(Player.playerName));
}
}

public void UpdateDestination(InputInfo inf)
public void UpdateDestination(InputInfo info)
{
Vector2Int desPosition = CurPosition;
UpdatePosition();
}

Expand Down

0 comments on commit 1382ab4

Please sign in to comment.