[Refactor] Reworked how OrbitalBehaviour behaves under the hood
This commit is contained in:
@@ -4,7 +4,7 @@ using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Rendering.PostProcessing;
|
||||
|
||||
public class PlayerController : OrbitalPositionBehaviour
|
||||
public class PlayerController : OrbitalBehaviour
|
||||
{
|
||||
[Header("References")]
|
||||
[SerializeField] private MeshRenderer m_Renderer;
|
||||
@@ -14,7 +14,6 @@ public class PlayerController : OrbitalPositionBehaviour
|
||||
[SerializeField] private PostProcessVolume m_PostProcessVolume;
|
||||
|
||||
private static PlayerController Instance;
|
||||
public static bool IsPlayerAttached => Instance.m_OrbitalPosition.m_IsAttachedToRings;
|
||||
|
||||
private static int s_HighScore = 20;
|
||||
public static int s_PlayerScore;
|
||||
@@ -25,17 +24,20 @@ public class PlayerController : OrbitalPositionBehaviour
|
||||
private bool m_HasFreeHitActive;
|
||||
private bool m_HasInvincibility;
|
||||
private bool m_KillingItself;
|
||||
|
||||
protected override void OnStart()
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Instance = this;
|
||||
s_HighScore = Mathf.Max(s_HighScore, PlayerPrefs.GetInt("HighScore", 0));
|
||||
Debug.Log($"Loaded high score of [{s_HighScore}]");
|
||||
Instance = this;
|
||||
|
||||
GlobalOrbitalPositionManager.SetPlayer(m_OrbitalPosition);
|
||||
|
||||
m_OrbitalPosition.m_ObjectRadius = 0.1f;
|
||||
m_OrbitalPosition.m_SpinSpeed = 0.2f;
|
||||
BehaviourManager.SetPlayer(this);
|
||||
RegisterObject(new OrbitalInitializer
|
||||
{
|
||||
ObjectRadius = 0.1f,
|
||||
SpinSpeed = 0.2f
|
||||
});
|
||||
|
||||
IsAttachedToRings = true;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
@@ -45,9 +47,9 @@ public class PlayerController : OrbitalPositionBehaviour
|
||||
m_ScoreText.color = s_PlayerScore > s_HighScore ? Color.yellow : Color.white;
|
||||
m_Renderer.material = m_HasFreeHitActive ? m_FreeHitMaterial : m_DefaultMaterial;
|
||||
|
||||
if (GlobalInput.IsScreenClicked && GlobalOrbitalPositionManager.AllowPlayerInput)
|
||||
if (GlobalInput.IsScreenClicked && BehaviourManager.AllowPlayerInput)
|
||||
{
|
||||
m_OrbitalPosition.m_AttachedRing += 1;
|
||||
AdvanceRing();
|
||||
}
|
||||
|
||||
if (!m_KillingItself)
|
||||
@@ -56,32 +58,27 @@ public class PlayerController : OrbitalPositionBehaviour
|
||||
transform.position = Vector3.Lerp(m_SuicidePoint, m_SuicidePoint.normalized * 20f, m_DeathLerp);
|
||||
m_DeathLerp += Time.deltaTime;
|
||||
}
|
||||
|
||||
public static void AttachPlayer()
|
||||
{
|
||||
Instance.m_OrbitalPosition.m_IsAttachedToRings = true;
|
||||
}
|
||||
|
||||
private IEnumerator OnGrowPlayerModifier()
|
||||
{
|
||||
transform.localScale *= 1.5f;
|
||||
m_OrbitalPosition.m_ObjectRadius *= 1.5f;
|
||||
//m_OrbitalPosition.m_ObjectRadius *= 1.5f;
|
||||
|
||||
yield return new WaitForSecondsRealtime(15f);
|
||||
|
||||
transform.localScale /= 1.5f;
|
||||
m_OrbitalPosition.m_ObjectRadius /= 1.5f;
|
||||
//m_OrbitalPosition.m_ObjectRadius /= 1.5f;
|
||||
}
|
||||
|
||||
private IEnumerator OnShrinkPlayerModifier()
|
||||
{
|
||||
transform.localScale *= 0.6f;
|
||||
m_OrbitalPosition.m_ObjectRadius *= 0.6f;
|
||||
//m_OrbitalPosition.m_ObjectRadius *= 0.6f;
|
||||
|
||||
yield return new WaitForSecondsRealtime(15f);
|
||||
|
||||
transform.localScale /= 0.6f;
|
||||
m_OrbitalPosition.m_ObjectRadius /= 0.6f;
|
||||
//m_OrbitalPosition.m_ObjectRadius /= 0.6f;
|
||||
}
|
||||
|
||||
private IEnumerator TriggerInvincibility()
|
||||
@@ -94,9 +91,9 @@ public class PlayerController : OrbitalPositionBehaviour
|
||||
m_HasInvincibility = false;
|
||||
}
|
||||
|
||||
public override void OnCollision(OrbitalPositionBehaviour other)
|
||||
protected override void OnOrbitalCollision(OrbitalBehaviour other)
|
||||
{
|
||||
if (!m_OrbitalPosition.m_IsAttachedToRings)
|
||||
if (!IsAttachedToRings)
|
||||
return;
|
||||
|
||||
if (other.CompareTag("Enemy"))
|
||||
@@ -111,8 +108,9 @@ public class PlayerController : OrbitalPositionBehaviour
|
||||
StartCoroutine(TriggerInvincibility());
|
||||
return;
|
||||
}
|
||||
|
||||
GlobalOrbitalPositionManager.RestartSimulation();
|
||||
|
||||
StartCoroutine(BehaviourManager.RestartSimulation());
|
||||
|
||||
m_SuicidePoint = transform.position;
|
||||
m_KillingItself = true;
|
||||
m_DeathLerp = 0f;
|
||||
@@ -139,7 +137,7 @@ public class PlayerController : OrbitalPositionBehaviour
|
||||
break;
|
||||
|
||||
case PlayerModifier.Modifiers.SpeedUp:
|
||||
StartCoroutine(GlobalOrbitalPositionManager.Instance.StartPlayerSpeedupModifier());
|
||||
StartCoroutine(BehaviourManager.StartPlayerSpeedupModifier());
|
||||
break;
|
||||
|
||||
case PlayerModifier.Modifiers.ClearAllEnemies:
|
||||
@@ -158,7 +156,7 @@ public class PlayerController : OrbitalPositionBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnSimulationRestart()
|
||||
protected override void OnSimulationRestart()
|
||||
{
|
||||
m_KillingItself = false;
|
||||
m_Renderer.enabled = true;
|
||||
@@ -172,8 +170,13 @@ public class PlayerController : OrbitalPositionBehaviour
|
||||
s_PlayerScore = 0;
|
||||
}
|
||||
|
||||
public override void OnReachCentre()
|
||||
protected override void OnReachCentre()
|
||||
{
|
||||
GlobalOrbitalPositionManager.RestartSimulation();
|
||||
StartCoroutine(BehaviourManager.RestartSimulation());
|
||||
}
|
||||
|
||||
public static void AttachPlayer()
|
||||
{
|
||||
Instance.IsAttachedToRings = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user