[Refactor] GlobalOrbitalSettings
This commit is contained in:
@@ -1,26 +1,16 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class GlobalOrbitalSettings : MonoBehaviour
|
||||
public class Settings : MonoBehaviour
|
||||
{
|
||||
private static GlobalOrbitalSettings Instance = null;
|
||||
public static Settings Instance;
|
||||
|
||||
[SerializeField, Range(0f, Mathf.PI * 2)] float m_RadiusSpeed = 2f;
|
||||
public static float RadiusSpeed => Instance.m_RadiusSpeed;
|
||||
[field: SerializeField, Range(0f, Mathf.PI * 2)] public float RadiusSpeed { get; private set; } = 2f;
|
||||
[field: SerializeField, Range(0f, 2f)] public float DistanceSpeed { get; private set; } = 0.6f;
|
||||
[field: SerializeField, Range(0f, 1f)] public float GapDistance { get; private set; } = 0.3f;
|
||||
|
||||
[SerializeField, Range(0f, 2f)] float m_DistanceSpeed = 0.6f;
|
||||
public static float DistanceSpeed => Instance.m_DistanceSpeed;
|
||||
|
||||
[SerializeField, Range(0f, 1f)] float m_GapDistance = 0.3f;
|
||||
public static float GapDistance => Instance.m_GapDistance;
|
||||
|
||||
[SerializeField] GameObject m_RingPrefab;
|
||||
public static GameObject RingPrefab => Instance.m_RingPrefab;
|
||||
|
||||
[SerializeField] GameObject m_EnemyPrefab;
|
||||
public static GameObject EnemyPrefab => Instance.m_EnemyPrefab;
|
||||
|
||||
[SerializeField] GameObject m_ModifierPrefab;
|
||||
public static GameObject ModifierPrefab => Instance.m_ModifierPrefab;
|
||||
[field: SerializeField] public GameObject RingPrefab { get; private set; }
|
||||
[field: SerializeField] public GameObject EnemyPrefab { get; private set; }
|
||||
[field: SerializeField] public GameObject ModifierPrefab { get; private set; }
|
||||
|
||||
private void Start() => Instance = this;
|
||||
}
|
||||
|
||||
@@ -129,9 +129,9 @@ public class GlobalOrbitalPositionManager : MonoBehaviour
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Time.time - m_TimeOfLastRingSpawn > (GlobalOrbitalSettings.GapDistance / m_LocalDeltaTimeScale))
|
||||
if (Time.time - m_TimeOfLastRingSpawn > (Settings.Instance.GapDistance / m_LocalDeltaTimeScale))
|
||||
{
|
||||
GameObject newRing = Instantiate(GlobalOrbitalSettings.RingPrefab);
|
||||
GameObject newRing = Instantiate(Settings.Instance.RingPrefab);
|
||||
newRing.transform.localScale = new Vector3(12f, 12f, 1);
|
||||
|
||||
Ring ring = newRing.AddComponent<Ring>();
|
||||
@@ -150,7 +150,7 @@ public class GlobalOrbitalPositionManager : MonoBehaviour
|
||||
|
||||
m_CurrentRingAllowsSpawning = Random.Range(0, 25) != 0;
|
||||
if (!m_CurrentRingAllowsSpawning && AllowPlayerInput)
|
||||
Instantiate(GlobalOrbitalSettings.ModifierPrefab);
|
||||
Instantiate(Settings.Instance.ModifierPrefab);
|
||||
}
|
||||
|
||||
List<Ring> toRemove = new();
|
||||
@@ -158,7 +158,7 @@ public class GlobalOrbitalPositionManager : MonoBehaviour
|
||||
|
||||
foreach (Ring ring in m_Rings)
|
||||
{
|
||||
float diff = LocalDeltaTime * GlobalOrbitalSettings.DistanceSpeed;
|
||||
float diff = LocalDeltaTime * Settings.Instance.DistanceSpeed;
|
||||
ring.transform.localScale -= new Vector3(diff, diff, 0f);
|
||||
|
||||
LineRenderer lineRenderer = ring.GetComponentInChildren<LineRenderer>();
|
||||
@@ -207,7 +207,7 @@ public class GlobalOrbitalPositionManager : MonoBehaviour
|
||||
|
||||
float distance = m_Distances[orbitalPosition.m_AttachedRing];
|
||||
orbitalPosition.m_DistanceFromCentre = distance;
|
||||
orbitalPosition.m_DistanceAlongRadius = (orbitalPosition.m_DistanceAlongRadius + LocalDeltaTime * GlobalOrbitalSettings.RadiusSpeed * orbitalPosition.m_SpinSpeed) % (Mathf.PI * 2);
|
||||
orbitalPosition.m_DistanceAlongRadius = (orbitalPosition.m_DistanceAlongRadius + LocalDeltaTime * Settings.Instance.RadiusSpeed * orbitalPosition.m_SpinSpeed) % (Mathf.PI * 2);
|
||||
|
||||
orbitalPosition.m_Owner.position = orbitalPosition.TranslateToVec3();
|
||||
}
|
||||
@@ -232,7 +232,7 @@ public class GlobalOrbitalPositionManager : MonoBehaviour
|
||||
}
|
||||
|
||||
if (Random.Range(0, 20) == 0 && AllowPlayerInput && m_CurrentRingAllowsSpawning)
|
||||
Instantiate(GlobalOrbitalSettings.EnemyPrefab);
|
||||
Instantiate(Settings.Instance.EnemyPrefab);
|
||||
}
|
||||
|
||||
public static void RegisterOrbitalPositionInstance(OrbitalPosition newInstance) =>
|
||||
|
||||
Reference in New Issue
Block a user