From ff5bf700fb8d9ae261a9c28604a599814715598b Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 5 Oct 2019 23:50:43 +0200 Subject: [PATCH] Update some things --- Assets/Components/BigBang.cs | 20 ++++++++++++++++ Assets/Components/BigBang.cs.meta | 11 +++++++++ Assets/Components/BlackHole.cs | 2 +- Assets/Components/Emit.cs | 24 +++++++++++++++++++ Assets/Components/Emit.cs.meta | 11 +++++++++ Assets/Components/Gravitation.cs | 2 +- Assets/Components/Merger.cs | 4 ++++ Assets/Components/Particle.cs | 3 +++ Assets/Components/SpawnOnMouseClick.cs | 2 +- Assets/Components/TextFromBlackHoleMass.cs | 20 ++++++++++++++++ .../Components/TextFromBlackHoleMass.cs.meta | 11 +++++++++ Assets/Prefabs/Particle.prefab | 2 +- ProjectSettings/GraphicsSettings.asset | 7 +++++- 13 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 Assets/Components/BigBang.cs create mode 100644 Assets/Components/BigBang.cs.meta create mode 100644 Assets/Components/Emit.cs create mode 100644 Assets/Components/Emit.cs.meta create mode 100644 Assets/Components/TextFromBlackHoleMass.cs create mode 100644 Assets/Components/TextFromBlackHoleMass.cs.meta diff --git a/Assets/Components/BigBang.cs b/Assets/Components/BigBang.cs new file mode 100644 index 0000000..ca615fb --- /dev/null +++ b/Assets/Components/BigBang.cs @@ -0,0 +1,20 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class BigBang : MonoBehaviour +{ + public GameObject blackHolePrefab; + public GameObject particlePrefab; + public int particlesToSpawn; + + void Start() + { + + } + + void Update() + { + + } +} diff --git a/Assets/Components/BigBang.cs.meta b/Assets/Components/BigBang.cs.meta new file mode 100644 index 0000000..12e29d9 --- /dev/null +++ b/Assets/Components/BigBang.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 39e0b663ea04fd648950255e97005aa4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Components/BlackHole.cs b/Assets/Components/BlackHole.cs index 2df6991..2fb53b7 100644 --- a/Assets/Components/BlackHole.cs +++ b/Assets/Components/BlackHole.cs @@ -12,7 +12,7 @@ public class BlackHole : MonoBehaviour } set { rigidbody.mass = value; - Scale = Mass / Mathf.Pow(Mathf.PI, 2); + Scale = Mathf.Sqrt(Mass / Mathf.PI); } } diff --git a/Assets/Components/Emit.cs b/Assets/Components/Emit.cs new file mode 100644 index 0000000..727d2ed --- /dev/null +++ b/Assets/Components/Emit.cs @@ -0,0 +1,24 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[RequireComponent(typeof(Particle))] +public class Emitter : MonoBehaviour +{ + public GameObject particlePrefab; + protected Particle particle; + + protected void Awake() { + particle = GetComponent(); + } + + protected void Start() { + InvokeRepeating("Emit", 1f, 1f); + } + + protected void Emit() { + for(int i = 0; i < particle.Tier - 1; i++) { + Instantiate(particlePrefab, transform.position, Quaternion.identity); + } + } +} diff --git a/Assets/Components/Emit.cs.meta b/Assets/Components/Emit.cs.meta new file mode 100644 index 0000000..886d4e9 --- /dev/null +++ b/Assets/Components/Emit.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4ae389aca0e2e82408a1ddd869680dc0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Components/Gravitation.cs b/Assets/Components/Gravitation.cs index a33230e..9026cb1 100644 --- a/Assets/Components/Gravitation.cs +++ b/Assets/Components/Gravitation.cs @@ -59,7 +59,7 @@ public class Gravitation : MonoBehaviour foreach(Gravitation other in simulatedObjects) { if(other.positionInList <= this.positionInList) continue; float distance = Vector3.Distance(this.transform.position, other.transform.position); - float force = GravitationConstant * this.Mass * other.Mass / Mathf.Pow(distance, 2); + float force = GravitationConstant * this.Mass * other.Mass / Mathf.Clamp(Mathf.Pow(distance, 2), 0.1f, float.PositiveInfinity); Vector3 direction = (other.transform.position - this.transform.position).normalized; if(!this.isStatic) rigidbody.AddForce(direction * force); if(!other.isStatic) other.rigidbody.AddForce(-direction * force); diff --git a/Assets/Components/Merger.cs b/Assets/Components/Merger.cs index 278a9a0..e164d54 100644 --- a/Assets/Components/Merger.cs +++ b/Assets/Components/Merger.cs @@ -51,7 +51,11 @@ public class Merger : MonoBehaviour protected void DoMerge() { particle.Tier += 1; foreach(Merger merged in mergeCandidates.ToArray()) { + if(merged == null) continue; Destroy(merged.particle.gameObject); } + mergeCandidates.Clear(); + particle.mergeCollider.enabled = false; + particle.mergeCollider.enabled = true; } } diff --git a/Assets/Components/Particle.cs b/Assets/Components/Particle.cs index 517b07e..7a8e263 100644 --- a/Assets/Components/Particle.cs +++ b/Assets/Components/Particle.cs @@ -6,6 +6,7 @@ using UnityEngine; [RequireComponent(typeof(Rigidbody2D))] [RequireComponent(typeof(Collider2D))] [RequireComponent(typeof(Gravitation))] +[RequireComponent(typeof(Emitter))] public class Particle : MonoBehaviour { protected int _tier = 0; @@ -15,6 +16,7 @@ public class Particle : MonoBehaviour { public Merger merger; public Collider2D particleCollider; public Collider2D mergeCollider; + public Emitter emitter; public int Tier { get { @@ -48,5 +50,6 @@ public class Particle : MonoBehaviour { merger = GetComponentInChildren(); particleCollider = GetComponent(); mergeCollider = merger.GetComponent(); + emitter = GetComponent(); } } \ No newline at end of file diff --git a/Assets/Components/SpawnOnMouseClick.cs b/Assets/Components/SpawnOnMouseClick.cs index 89a1cc4..9f58cfb 100644 --- a/Assets/Components/SpawnOnMouseClick.cs +++ b/Assets/Components/SpawnOnMouseClick.cs @@ -14,7 +14,7 @@ public class SpawnOnMouseClick : MonoBehaviour void Update() { - if(Input.GetMouseButtonDown(mouseButton)) { + if(Input.GetMouseButton(mouseButton)) { Vector3 mousePosition = GetWorldMousePosition(); GameObject instance = Instantiate(prefabToSpawn, new Vector3(mousePosition.x, mousePosition.y, 0f), Quaternion.identity); } diff --git a/Assets/Components/TextFromBlackHoleMass.cs b/Assets/Components/TextFromBlackHoleMass.cs new file mode 100644 index 0000000..1be52a0 --- /dev/null +++ b/Assets/Components/TextFromBlackHoleMass.cs @@ -0,0 +1,20 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + + +public class TextFromBlackHoleMass : MonoBehaviour +{ + protected Text text; + public BlackHole blackHole; + + protected void Awake() { + text = GetComponent(); + } + + protected void Update() + { + text.text = blackHole.Mass.ToString("0"); + } +} diff --git a/Assets/Components/TextFromBlackHoleMass.cs.meta b/Assets/Components/TextFromBlackHoleMass.cs.meta new file mode 100644 index 0000000..f9e5682 --- /dev/null +++ b/Assets/Components/TextFromBlackHoleMass.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1902801cf75c7ea4f82979802e80aaef +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Particle.prefab b/Assets/Prefabs/Particle.prefab index 9306d85..8fb1e64 100644 --- a/Assets/Prefabs/Particle.prefab +++ b/Assets/Prefabs/Particle.prefab @@ -202,7 +202,7 @@ CircleCollider2D: m_UsedByComposite: 0 m_Offset: {x: 0, y: 0} serializedVersion: 2 - m_Radius: 0.55 + m_Radius: 0.75 --- !u!114 &7106168952007636313 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/ProjectSettings/GraphicsSettings.asset b/ProjectSettings/GraphicsSettings.asset index 6c2632a..4654e13 100644 --- a/ProjectSettings/GraphicsSettings.asset +++ b/ProjectSettings/GraphicsSettings.asset @@ -3,7 +3,7 @@ --- !u!30 &1 GraphicsSettings: m_ObjectHideFlags: 0 - serializedVersion: 12 + serializedVersion: 13 m_Deferred: m_Mode: 1 m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0} @@ -31,6 +31,9 @@ GraphicsSettings: m_AlwaysIncludedShaders: - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} + - {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0} + - {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0} + - {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0} m_PreloadedShaders: [] m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} @@ -55,3 +58,5 @@ GraphicsSettings: m_AlbedoSwatchInfos: [] m_LightsUseLinearIntensity: 0 m_LightsUseColorTemperature: 0 + m_LogWhenShaderIsCompiled: 0 + m_AllowEnlightenSupportForUpgradedProject: 1