diff --git a/Assets/Components/BlackHole.cs b/Assets/Components/BlackHole.cs index b24cef0..dbd9325 100644 --- a/Assets/Components/BlackHole.cs +++ b/Assets/Components/BlackHole.cs @@ -6,7 +6,7 @@ using UnityEngine; [RequireComponent(typeof(Collider2D))] public class BlackHole : MonoBehaviour { - protected float spentMass; + public float spentMass; public float Mass { get { diff --git a/Assets/Components/CameraPan.cs b/Assets/Components/CameraPan.cs index a6bd113..cc54e37 100644 --- a/Assets/Components/CameraPan.cs +++ b/Assets/Components/CameraPan.cs @@ -7,28 +7,26 @@ public class CameraPan : MonoBehaviour { public string axisName; - protected new Camera camera; protected Vector3? lastMousePosition; private void Start() { lastMousePosition = null; - camera = GetComponent(); } private void Update() { bool panIsPressed = Input.GetAxisRaw(axisName) != 0f; Vector3? currentMousePosition = null; if(panIsPressed) { - currentMousePosition = camera.ScreenToWorldPoint(Input.mousePosition); + currentMousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); if(lastMousePosition.HasValue) { Vector3 positionDelta = lastMousePosition.Value - currentMousePosition.Value; - camera.transform.position += positionDelta; - currentMousePosition = camera.ScreenToWorldPoint(Input.mousePosition); + Camera.main.transform.position += positionDelta; + currentMousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); } } lastMousePosition = currentMousePosition; if(Input.GetAxisRaw("ResetCamera") > 0) { - camera.transform.position = new Vector3(0, 0, camera.transform.position.z); + Camera.main.transform.position = new Vector3(0, 0, Camera.main.transform.position.z); } } } diff --git a/Assets/Components/Disappear.cs b/Assets/Components/Disappear.cs index 7e3b81f..e5c6f5e 100644 --- a/Assets/Components/Disappear.cs +++ b/Assets/Components/Disappear.cs @@ -4,9 +4,15 @@ using UnityEngine; public class Disappear : MonoBehaviour { - public float health; + protected float _health; protected Particle particle; + public float Health { + get { + return _health; + } + } + protected void Awake() { particle = GetComponent(); } @@ -16,13 +22,13 @@ public class Disappear : MonoBehaviour } public void ResetTimer() { - health = 1f; + _health = 1f; } protected void Update() { - health -= Mathf.Pow(particle.gameController.particleDurationConstant, particle.gameController.maxTierPresent - particle.Tier - 4) * Time.deltaTime; + _health -= Mathf.Pow(particle.gameController.particleDurationConstant, particle.gameController.maxTierPresent - particle.Tier - 4) * Time.deltaTime; - if(health < 0) { + if(_health < 0) { Destroy(this.gameObject); } } diff --git a/Assets/Components/GameController.cs b/Assets/Components/GameController.cs index 2490cab..557a2a6 100644 --- a/Assets/Components/GameController.cs +++ b/Assets/Components/GameController.cs @@ -13,22 +13,19 @@ public class GameController : MonoBehaviour [Header("Black Hole")] public GameObject blackHolePrefab; - public BlackHole blackHole; [Header("Particles")] public GameObject particlePrefab; public Gradient[] tierGradients; public RuntimeAnimatorController[] tierAnimation; - public List simulatedObjects; - public int maxTierPresent; - [Header("Upgrades")] + [Header("Upgrade Parameters")] public float[] upgradePushForce; public float[] upgradePushRadius; public int[] upgradeParticleCount; public int[] upgradeParticleTiers; - [Header("Bought Upgrades")] + [Header("Bought Updates")] public int _levelAntig = 0; public int _levelMatter = 0; public int _levelFission = 0; @@ -64,13 +61,31 @@ public class GameController : MonoBehaviour } } + [Header("Simulation Status")] + [HideInInspector] + public List simulatedObjects; + [HideInInspector] + public int maxTierPresent; + [Header("References")] + [HideInInspector] public SpawnOnMouseClick spawner; + + [HideInInspector] public PushOnMouseClick pusher; + + [HideInInspector] public CameraPan panner; + + [HideInInspector] public MusicManager musicManager; + + [HideInInspector] public Canvas canvas; + [HideInInspector] + public BlackHole blackHole; + protected void Awake() { spawner = Camera.main.GetComponent(); pusher = Camera.main.GetComponent(); diff --git a/Assets/Components/Gravitation.cs b/Assets/Components/Gravitation.cs index 494593d..dff9adf 100644 --- a/Assets/Components/Gravitation.cs +++ b/Assets/Components/Gravitation.cs @@ -9,13 +9,9 @@ public class Gravitation : MonoBehaviour [Header("Config")] public bool isStatic; - [Header("Forces")] - protected Vector3 appliedForce; - - [Header("Internals")] + [HideInInspector] public int positionInList; - [Header("References")] protected new Rigidbody2D rigidbody; protected GameController gameController; @@ -53,7 +49,6 @@ public class Gravitation : MonoBehaviour private void Start() { - appliedForce = new Vector3(0f, 0f, 0f); } // O(n²) @@ -67,6 +62,5 @@ public class Gravitation : MonoBehaviour if(!this.isStatic) rigidbody.AddForce(direction * force); if(!other.isStatic) other.rigidbody.AddForce(-direction * force); } - appliedForce = new Vector3(0, 0, 0); } } diff --git a/Assets/Components/Hue.cs b/Assets/Components/Hue.cs index c2c4865..9cde56c 100644 --- a/Assets/Components/Hue.cs +++ b/Assets/Components/Hue.cs @@ -9,7 +9,6 @@ public class Hue : MonoBehaviour protected Particle particle; protected Material material; - protected Color color; protected void Awake() { diff --git a/Assets/Components/Merger.cs b/Assets/Components/Merger.cs index 3ed15d6..75f8ab7 100644 --- a/Assets/Components/Merger.cs +++ b/Assets/Components/Merger.cs @@ -5,13 +5,13 @@ using UnityEngine; [RequireComponent(typeof(CircleCollider2D))] public class Merger : MonoBehaviour { + public float mergeAfterSeconds; + + protected bool mergeEnabled; + protected List mergeCandidates; + [HideInInspector] public Particle particle; - public float mergeAfterSeconds; - - protected bool mergeEnabled; - - protected List mergeCandidates; protected Collider2D Collider { get { diff --git a/Assets/Components/MusicManager.cs b/Assets/Components/MusicManager.cs index 50059bc..64abd2d 100644 --- a/Assets/Components/MusicManager.cs +++ b/Assets/Components/MusicManager.cs @@ -6,21 +6,22 @@ using UnityEngine; public class MusicManager : MonoBehaviour { - public AudioSource baseLayer; public float changeSpeed = 1f; + [BeforeStart] + public AudioSource baseLayer; [BeforeStart] public AudioSource[] layers; + protected bool neverStarted; + protected float baseLayerTargetVolume; protected float[] targetVolume; - protected bool neverStarted; - protected void Start() { foreach(AudioSource audioSource in layers) { - audioSource.volume = 0; + audioSource.volume = 0f; } targetVolume = new float[layers.Length]; for(int i = 0; i < layers.Length; i++) { @@ -40,7 +41,9 @@ public class MusicManager : MonoBehaviour if(neverStarted) { foreach(AudioSource layer in layers) { - layer.Play(); + if(layer != null) { + layer.Play(); + } } neverStarted = false; } @@ -63,19 +66,23 @@ public class MusicManager : MonoBehaviour } protected void Update() { - if(baseLayer.volume > baseLayerTargetVolume) { - baseLayer.volume = Mathf.Clamp(baseLayer.volume - Time.deltaTime * changeSpeed, baseLayerTargetVolume, float.PositiveInfinity); - } - else if(baseLayer.volume < baseLayerTargetVolume) { - baseLayer.volume = Mathf.Clamp(baseLayer.volume + Time.deltaTime * changeSpeed, 0f, baseLayerTargetVolume); + if(baseLayer != null) { + if(baseLayer.volume > baseLayerTargetVolume) { + baseLayer.volume = Mathf.Clamp(baseLayer.volume - Time.deltaTime * changeSpeed, baseLayerTargetVolume, float.PositiveInfinity); + } + else if(baseLayer.volume < baseLayerTargetVolume) { + baseLayer.volume = Mathf.Clamp(baseLayer.volume + Time.deltaTime * changeSpeed, 0f, baseLayerTargetVolume); + } } for(int i = 0; i < layers.Length; i++) { - if(layers[i].volume > targetVolume[i]) { - layers[i].volume = Mathf.Clamp(layers[i].volume - Time.deltaTime * changeSpeed, targetVolume[i], float.PositiveInfinity); - } - else if(layers[i].volume < targetVolume[i]) { - layers[i].volume = Mathf.Clamp(layers[i].volume + Time.deltaTime * changeSpeed, 0f, targetVolume[i]); + if(layers[i] != null) { + if(layers[i].volume > targetVolume[i]) { + layers[i].volume = Mathf.Clamp(layers[i].volume - Time.deltaTime * changeSpeed, targetVolume[i], float.PositiveInfinity); + } + else if(layers[i].volume < targetVolume[i]) { + layers[i].volume = Mathf.Clamp(layers[i].volume + Time.deltaTime * changeSpeed, 0f, targetVolume[i]); + } } } } diff --git a/Assets/Components/Particle.cs b/Assets/Components/Particle.cs index 933b00d..6124402 100644 --- a/Assets/Components/Particle.cs +++ b/Assets/Components/Particle.cs @@ -34,11 +34,11 @@ public class Particle : MonoBehaviour { } } - public float Scale { + float Scale { get { return transform.localScale.x; } - set { + protected set { transform.localScale = new Vector3(value, value, 1); } } diff --git a/Assets/Components/PushOnMouseClick.cs b/Assets/Components/PushOnMouseClick.cs index 75d3090..065f4d4 100644 --- a/Assets/Components/PushOnMouseClick.cs +++ b/Assets/Components/PushOnMouseClick.cs @@ -4,16 +4,15 @@ using UnityEngine; public class PushOnMouseClick : MonoBehaviour { - [Header("Config")] - public int mouseButton; - public float pushForce; - public float pushRadius; + public int mouseButton = 1; + public float pushForce = 0; + public float pushRadius = 0; protected Vector3 GetWorldMousePosition() { return Camera.main.ScreenToWorldPoint(Input.mousePosition); } - void Update() + protected void Update() { if(Input.GetMouseButton(mouseButton)) { Vector3 mousePosition = GetWorldMousePosition(); diff --git a/Assets/Components/SpawnOnMouseClick.cs b/Assets/Components/SpawnOnMouseClick.cs index 74a48b7..f583eec 100644 --- a/Assets/Components/SpawnOnMouseClick.cs +++ b/Assets/Components/SpawnOnMouseClick.cs @@ -5,11 +5,12 @@ using UnityEngine; public class SpawnOnMouseClick : MonoBehaviour { [Header("Config")] - public GameController gameController; - public int mouseButton; - public int spawnedTier; - public int spawnCount; - public float appliedForce; + public int mouseButton = 0; + public int spawnedTier = 0; + public int spawnCount = 1; + public float appliedForce = 0.1f; + + protected GameController gameController; protected void Awake() { gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent(); diff --git a/Assets/Components/TempUpgradesToggler.cs b/Assets/Components/TempUpgradesToggler.cs index de526de..e1ef89a 100644 --- a/Assets/Components/TempUpgradesToggler.cs +++ b/Assets/Components/TempUpgradesToggler.cs @@ -6,7 +6,11 @@ public class TempUpgradesToggler : MonoBehaviour { public GameObject upgrades; - void Update() + protected void Start() { + Debug.LogWarning("TempUpgradesToggler should not be used."); + } + + protected void Update() { if(Input.GetKeyDown(KeyCode.P)) { upgrades.SetActive(!upgrades.activeSelf); diff --git a/Assets/Components/TextFromBlackHoleMass.cs b/Assets/Components/TextFromBlackHoleMass.cs index ac00658..6b85c7a 100644 --- a/Assets/Components/TextFromBlackHoleMass.cs +++ b/Assets/Components/TextFromBlackHoleMass.cs @@ -7,15 +7,15 @@ using UnityEngine.UI; public class TextFromBlackHoleMass : MonoBehaviour { protected Text text; - public BlackHole blackHole; + protected GameController gameController; protected void Awake() { text = GetComponent(); - blackHole = GameObject.FindGameObjectWithTag("BlackHole").GetComponent(); + gameController = GameObject.Find("GameController").GetComponent(); } protected void Update() { - text.text = blackHole.Mass.ToString("0"); + text.text = gameController.blackHole.Mass.ToString("0"); } } diff --git a/Assets/Components/TextFromCost.cs b/Assets/Components/TextFromCost.cs index 70a03a1..dd3ab5a 100644 --- a/Assets/Components/TextFromCost.cs +++ b/Assets/Components/TextFromCost.cs @@ -12,7 +12,7 @@ public class TextFromCost : MonoBehaviour } public void DisplayCost(float cost) { - if(cost > 0) { + if(cost >= 0) { text.text = cost.ToString("0"); } else { diff --git a/Assets/Components/TextFromUnspentBlackHoleMass.cs b/Assets/Components/TextFromUnspentBlackHoleMass.cs index d35b6cd..1ced623 100644 --- a/Assets/Components/TextFromUnspentBlackHoleMass.cs +++ b/Assets/Components/TextFromUnspentBlackHoleMass.cs @@ -7,15 +7,15 @@ using UnityEngine.UI; public class TextFromUnspentBlackHoleMass : MonoBehaviour { protected Text text; - public BlackHole blackHole; + protected GameController gameController; protected void Awake() { text = GetComponent(); - blackHole = GameObject.FindGameObjectWithTag("BlackHole").GetComponent(); + gameController = GameObject.Find("GameController").GetComponent(); } protected void Update() { - text.text = blackHole.UnspentMass.ToString("0"); + text.text = gameController.blackHole.UnspentMass.ToString("0"); } } diff --git a/Assets/Components/UpgradeButton.cs b/Assets/Components/UpgradeButton.cs index 443e317..42939a8 100644 --- a/Assets/Components/UpgradeButton.cs +++ b/Assets/Components/UpgradeButton.cs @@ -12,10 +12,12 @@ public enum UpgradeType { public class UpgradeButton : MonoBehaviour { + [Header("Properties")] public int cost; public int level; public UpgradeType type; + [Header("Sprites")] public Sprite cantBuySprite; public Sprite canBuySprite; public Sprite hoveredSprite; @@ -33,9 +35,8 @@ public class UpgradeButton : MonoBehaviour case UpgradeType.ANTIG: return gameController.LevelAntig >= level; case UpgradeType.MATTER: return gameController.LevelMatter >= level; case UpgradeType.FISSION: return gameController.LevelFission >= level; + default: return false; } - //ok c# - return false; } }