Centralised player data into game session
This commit is contained in:
parent
08338d6dc7
commit
75c890766c
@ -335,6 +335,7 @@ MonoBehaviour:
|
|||||||
player2: {fileID: 2249596435903131710}
|
player2: {fileID: 2249596435903131710}
|
||||||
scoreboard: {fileID: 634835458}
|
scoreboard: {fileID: 634835458}
|
||||||
isDuoMode: 1
|
isDuoMode: 1
|
||||||
|
playerData: {fileID: 11400000, guid: 928d6efd735c3814d955e3f955a0264a, type: 2}
|
||||||
--- !u!4 &70882853
|
--- !u!4 &70882853
|
||||||
Transform:
|
Transform:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -318,6 +318,7 @@ MonoBehaviour:
|
|||||||
player2: {fileID: 0}
|
player2: {fileID: 0}
|
||||||
scoreboard: {fileID: 634835458}
|
scoreboard: {fileID: 634835458}
|
||||||
isDuoMode: 0
|
isDuoMode: 0
|
||||||
|
playerData: {fileID: 11400000, guid: 928d6efd735c3814d955e3f955a0264a, type: 2}
|
||||||
--- !u!4 &93601729
|
--- !u!4 &93601729
|
||||||
Transform:
|
Transform:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -7,7 +7,7 @@ MonoBehaviour:
|
|||||||
m_PrefabInstance: {fileID: 0}
|
m_PrefabInstance: {fileID: 0}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 0}
|
m_GameObject: {fileID: 0}
|
||||||
m_Enabled: 1
|
m_Enabled: 0
|
||||||
m_EditorHideFlags: 0
|
m_EditorHideFlags: 0
|
||||||
m_Script: {fileID: 11500000, guid: 9055f72a604bc3f4ba01bc120f0643d2, type: 3}
|
m_Script: {fileID: 11500000, guid: 9055f72a604bc3f4ba01bc120f0643d2, type: 3}
|
||||||
m_Name: PlayerData
|
m_Name: PlayerData
|
||||||
@ -15,6 +15,6 @@ MonoBehaviour:
|
|||||||
<InvincibilityTime>k__BackingField: 600
|
<InvincibilityTime>k__BackingField: 600
|
||||||
<JumpHeight>k__BackingField: 6
|
<JumpHeight>k__BackingField: 6
|
||||||
<LaneSwitchSpeed>k__BackingField: 20
|
<LaneSwitchSpeed>k__BackingField: 20
|
||||||
<CurrentSpeed>k__BackingField: 10
|
|
||||||
<InitialSpeed>k__BackingField: 10
|
<InitialSpeed>k__BackingField: 10
|
||||||
<SpeedAcceleration>k__BackingField: 0
|
<CurrentSpeed>k__BackingField: 401.62177
|
||||||
|
<SpeedAcceleration>k__BackingField: 1
|
||||||
|
@ -1,13 +1,39 @@
|
|||||||
using System.Collections;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
[CreateAssetMenu(fileName = "PlayerData", menuName = "ScriptableObjects/Player")]
|
[CreateAssetMenu(fileName = "PlayerData", menuName = "ScriptableObjects/Player")]
|
||||||
public class PlayerData : ScriptableObject
|
public sealed class PlayerData : ScriptableObject
|
||||||
{
|
{
|
||||||
[field: SerializeField] public int InvincibilityTime { get; private set; }
|
// Serialize Fields
|
||||||
|
[field: SerializeField] public int InvincibilityTime { get; protected set; }
|
||||||
[field: SerializeField] public float JumpHeight { get; private set; }
|
[field: SerializeField] public float JumpHeight { get; private set; }
|
||||||
[field: SerializeField] public float LaneSwitchSpeed { get; private set; }
|
[field: SerializeField] public float LaneSwitchSpeed { get; private set; }
|
||||||
[field: SerializeField] public float CurrentSpeed { get; set; }
|
|
||||||
[field: SerializeField] public float InitialSpeed { get; private set; }
|
[field: SerializeField] public float InitialSpeed { get; private set; }
|
||||||
|
[field: SerializeField] public float CurrentSpeed { get; private set; }
|
||||||
[field: SerializeField] public float SpeedAcceleration { get; private set; }
|
[field: SerializeField] public float SpeedAcceleration { get; private set; }
|
||||||
|
|
||||||
|
// Other attributes
|
||||||
|
private bool onPause = false;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
CurrentSpeed = InitialSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reset()
|
||||||
|
{
|
||||||
|
CurrentSpeed = InitialSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
if (!onPause)
|
||||||
|
CurrentSpeed += SpeedAcceleration / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void isPaused(bool isPaused)
|
||||||
|
{
|
||||||
|
onPause = isPaused;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ public class GameSession : MonoBehaviour,IResettable
|
|||||||
[SerializeField] [CanBeNull] private Player player2;
|
[SerializeField] [CanBeNull] private Player player2;
|
||||||
[SerializeField] private Scoreboard scoreboard;
|
[SerializeField] private Scoreboard scoreboard;
|
||||||
[SerializeField] private Boolean isDuoMode;
|
[SerializeField] private Boolean isDuoMode;
|
||||||
|
[SerializeField] private PlayerData playerData;
|
||||||
|
|
||||||
public static GameSession Instance { get; private set; }
|
public static GameSession Instance { get; private set; }
|
||||||
public WorldCurver Curver { get; private set; }
|
public WorldCurver Curver { get; private set; }
|
||||||
@ -38,6 +39,7 @@ public class GameSession : MonoBehaviour,IResettable
|
|||||||
}
|
}
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
|
playerData.Update();
|
||||||
_player1InputTranslator.Tick();
|
_player1InputTranslator.Tick();
|
||||||
if (isDuoMode)
|
if (isDuoMode)
|
||||||
{
|
{
|
||||||
@ -45,8 +47,8 @@ public class GameSession : MonoBehaviour,IResettable
|
|||||||
}
|
}
|
||||||
|
|
||||||
Curver.Tick();
|
Curver.Tick();
|
||||||
// curver.SinCurveX();
|
// curver.SinCurveX();
|
||||||
// Curver.SinCurveY();
|
// Curver.SinCurveY();
|
||||||
//Curver.TurnWorldToLeft();
|
//Curver.TurnWorldToLeft();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,29 +64,25 @@ public class GameSession : MonoBehaviour,IResettable
|
|||||||
player2Holder.Init(true);
|
player2Holder.Init(true);
|
||||||
_player2InputTranslator = new InputTranslator<KeyBinding>(player2Holder, true);
|
_player2InputTranslator = new InputTranslator<KeyBinding>(player2Holder, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
playerData.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddCommandTranslator(ICommandTranslator translator, bool isPlayer2)
|
public void AddCommandTranslator(ICommandTranslator translator, bool isPlayer2)
|
||||||
{
|
{
|
||||||
if (isPlayer2)
|
if (isPlayer2)
|
||||||
{
|
{
|
||||||
_player2InputTranslator.AddCommandTranslator(translator);
|
_player2InputTranslator.AddCommandTranslator(translator);
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
_player1InputTranslator.AddCommandTranslator(translator);
|
_player1InputTranslator.AddCommandTranslator(translator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void PauseSession(bool isPaused)
|
public void PauseSession(bool isPaused)
|
||||||
{
|
{
|
||||||
if (isPaused)
|
playerData.isPaused(isPaused);
|
||||||
_speedAtPause = player1.playerData.CurrentSpeed;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
player1.playerData.CurrentSpeed = _speedAtPause;
|
|
||||||
}
|
|
||||||
|
|
||||||
Time.timeScale = isPaused ? 0 : 1;
|
Time.timeScale = isPaused ? 0 : 1;
|
||||||
if (!_isSessionPaused && _player1InputTranslator.IsTranslationResticted(InputConstants.InGameCommands) && _player2InputTranslator.IsTranslationResticted(InputConstants.InGameCommands) )
|
if (!_isSessionPaused && _player1InputTranslator.IsTranslationResticted(InputConstants.InGameCommands) && _player2InputTranslator.IsTranslationResticted(InputConstants.InGameCommands) )
|
||||||
{
|
{
|
||||||
@ -182,6 +180,7 @@ public class GameSession : MonoBehaviour,IResettable
|
|||||||
public void ResetToDefault()
|
public void ResetToDefault()
|
||||||
{
|
{
|
||||||
PauseSession(false);
|
PauseSession(false);
|
||||||
|
playerData.Reset();
|
||||||
if(player1 !=null)
|
if(player1 !=null)
|
||||||
player1.ResetToDefault();
|
player1.ResetToDefault();
|
||||||
if (isDuoMode && player2 != null)
|
if (isDuoMode && player2 != null)
|
||||||
@ -189,4 +188,9 @@ public class GameSession : MonoBehaviour,IResettable
|
|||||||
player2.ResetToDefault();
|
player2.ResetToDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PlayerData GetPlayerData()
|
||||||
|
{
|
||||||
|
return this.playerData;
|
||||||
|
}
|
||||||
}
|
}
|
@ -34,11 +34,10 @@ public class Player : MonoBehaviour, IResettable, ICommandTranslator
|
|||||||
|
|
||||||
#region PlayerComponents
|
#region PlayerComponents
|
||||||
|
|
||||||
[SerializeField] internal PlayerData playerData;
|
public PlayerData playerData;
|
||||||
public IDamageable PlayerHealth { get; private set; }
|
public IDamageable PlayerHealth { get; private set; }
|
||||||
public Statistics PlayerStatictics { get; private set; }
|
public Statistics PlayerStatictics { get; private set; }
|
||||||
|
|
||||||
public PlayerData PlayerData { get { return playerData; } }
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -48,14 +47,8 @@ public class Player : MonoBehaviour, IResettable, ICommandTranslator
|
|||||||
|
|
||||||
public LaneSystem LaneSystem
|
public LaneSystem LaneSystem
|
||||||
{
|
{
|
||||||
get
|
get => laneSystem;
|
||||||
{
|
private set => laneSystem = value;
|
||||||
return laneSystem;
|
|
||||||
}
|
|
||||||
private set
|
|
||||||
{
|
|
||||||
laneSystem = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -72,6 +65,7 @@ public class Player : MonoBehaviour, IResettable, ICommandTranslator
|
|||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
|
playerData = GameSession.Instance.GetPlayerData();
|
||||||
GameSession.Instance.AddCommandTranslator(this, isPlayer2);
|
GameSession.Instance.AddCommandTranslator(this, isPlayer2);
|
||||||
animator = GetComponent<Animator>();
|
animator = GetComponent<Animator>();
|
||||||
if (animator)
|
if (animator)
|
||||||
@ -82,7 +76,6 @@ public class Player : MonoBehaviour, IResettable, ICommandTranslator
|
|||||||
PlayerStatictics = GetComponent<Statistics>();
|
PlayerStatictics = GetComponent<Statistics>();
|
||||||
PlayerStateMachine = new PlayerStateMachine(this);
|
PlayerStateMachine = new PlayerStateMachine(this);
|
||||||
InvincibilityTime = playerData.InvincibilityTime;
|
InvincibilityTime = playerData.InvincibilityTime;
|
||||||
playerData.CurrentSpeed = playerData.InitialSpeed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
@ -102,7 +95,6 @@ public class Player : MonoBehaviour, IResettable, ICommandTranslator
|
|||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
playerData.CurrentSpeed += playerData.SpeedAcceleration / 1000;
|
|
||||||
PlayerStateMachine.Tick();
|
PlayerStateMachine.Tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +173,6 @@ public class Player : MonoBehaviour, IResettable, ICommandTranslator
|
|||||||
LaneSystem.ResetToDefault();
|
LaneSystem.ResetToDefault();
|
||||||
Physics.SyncTransforms();
|
Physics.SyncTransforms();
|
||||||
ReloadAnimator();
|
ReloadAnimator();
|
||||||
playerData.CurrentSpeed = playerData.InitialSpeed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TranslateCommand(ECommand command, PressedState state)
|
public void TranslateCommand(ECommand command, PressedState state)
|
||||||
|
@ -8,7 +8,7 @@ public abstract class MovingState : PlayerState
|
|||||||
private float speed; //SO
|
private float speed; //SO
|
||||||
private float laneSwitchSpeed; //SO
|
private float laneSwitchSpeed; //SO
|
||||||
protected const float gravity = -9.8f;
|
protected const float gravity = -9.8f;
|
||||||
private float invincibilityTime => playerSM.PlayerData.InvincibilityTime;
|
private float invincibilityTime => playerSM.playerData.InvincibilityTime;
|
||||||
public MovingState(PlayerStateMachine playerStateMachine) : base(playerStateMachine)
|
public MovingState(PlayerStateMachine playerStateMachine) : base(playerStateMachine)
|
||||||
{
|
{
|
||||||
this.playerSM = playerStateMachine;
|
this.playerSM = playerStateMachine;
|
||||||
|
@ -11,7 +11,7 @@ public abstract class PlayerState : State<Player>
|
|||||||
public PlayerState(PlayerStateMachine playerStateMachine)
|
public PlayerState(PlayerStateMachine playerStateMachine)
|
||||||
{
|
{
|
||||||
playerSM = playerStateMachine;
|
playerSM = playerStateMachine;
|
||||||
playerData = playerStateMachine.PlayerData;
|
playerData = playerStateMachine.playerData;
|
||||||
playerTransform = playerStateMachine.PlayerTransform;
|
playerTransform = playerStateMachine.PlayerTransform;
|
||||||
}
|
}
|
||||||
public override void Tick()
|
public override void Tick()
|
||||||
|
@ -4,14 +4,13 @@ using UnityEngine.Animations.Rigging;
|
|||||||
public class PlayerStateMachine : StateMachine<Player>
|
public class PlayerStateMachine : StateMachine<Player>
|
||||||
{
|
{
|
||||||
private Player player;
|
private Player player;
|
||||||
private PlayerData playerData;
|
public PlayerData playerData;
|
||||||
private Transform playerTransform;
|
private Transform playerTransform;
|
||||||
public Transform PlayerTransform { get { return playerTransform; } }
|
public Transform PlayerTransform { get { return playerTransform; } }
|
||||||
public PlayerData PlayerData { get { return playerData; } }
|
|
||||||
public PlayerStateMachine(Player player)
|
public PlayerStateMachine(Player player)
|
||||||
{
|
{
|
||||||
this.player = player;
|
this.player = player;
|
||||||
playerData = player.PlayerData;
|
playerData = GameSession.Instance.GetPlayerData();
|
||||||
playerTransform = player.transform;
|
playerTransform = player.transform;
|
||||||
InitStates();
|
InitStates();
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user