1
Fork 0
mirror of https://github.com/Steffo99/gravity-fusion.git synced 2024-11-22 08:24:17 +00:00
gravity-fusion/Assets/Components/Particle.cs

101 lines
3.2 KiB
C#
Raw Normal View History

2019-10-05 18:41:07 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Particle : MonoBehaviour {
protected int _tier = 0;
2019-10-07 13:11:17 +00:00
[HideInInspector]
2019-10-05 18:41:07 +00:00
public new Rigidbody2D rigidbody;
2019-10-07 13:11:17 +00:00
[HideInInspector]
2019-10-05 18:41:07 +00:00
public Gravitation gravitation;
2019-10-07 13:11:17 +00:00
[HideInInspector]
2019-10-05 18:41:07 +00:00
public GameController gameController;
2019-10-07 13:11:17 +00:00
[HideInInspector]
2019-10-05 18:41:07 +00:00
public Merger merger;
2019-10-07 13:11:17 +00:00
[HideInInspector]
2019-10-05 18:41:07 +00:00
public Collider2D particleCollider;
2019-10-07 13:11:17 +00:00
[HideInInspector]
2019-10-05 18:41:07 +00:00
public Collider2D mergeCollider;
2019-10-07 13:11:17 +00:00
[HideInInspector]
2019-10-05 21:50:43 +00:00
public Emitter emitter;
2019-10-07 13:11:17 +00:00
[HideInInspector]
2019-10-06 13:04:50 +00:00
public Animator animator;
2019-10-07 13:11:17 +00:00
[HideInInspector]
2019-10-06 13:04:50 +00:00
public Hue hue;
2019-10-07 13:11:17 +00:00
[HideInInspector]
2019-10-06 13:04:50 +00:00
public SpriteRenderer mainRenderer;
2019-10-07 13:11:17 +00:00
[HideInInspector]
2019-10-06 13:04:50 +00:00
public SpriteRenderer auraRenderer;
2019-10-07 13:11:17 +00:00
[HideInInspector]
2019-10-06 13:04:50 +00:00
public SpriteRenderer detailsRenderer;
2019-10-07 13:11:17 +00:00
[HideInInspector]
2019-10-06 15:44:41 +00:00
public Disappear disappear;
2019-10-05 18:41:07 +00:00
public int Tier {
get {
return _tier;
}
set {
2019-10-06 13:04:50 +00:00
_tier = value;
2019-10-06 15:44:41 +00:00
Scale = Mathf.Pow(gameController.scaleMultiplier, _tier);
2019-10-06 17:04:47 +00:00
animator.runtimeAnimatorController = gameController.tierAnimation[_tier % gameController.tierAnimation.Length];
hue.PossibleColors = gameController.tierGradients[_tier % gameController.tierGradients.Length];
gameController.CheckNewMaxTier(_tier);
2019-10-07 20:02:46 +00:00
mainRenderer.sortingOrder = -_tier;
auraRenderer.sortingOrder = -_tier;
detailsRenderer.sortingOrder = -_tier;
2019-10-06 15:44:41 +00:00
disappear.ResetTimer();
2019-10-07 20:02:46 +00:00
rigidbody.mass = Mass;
2019-10-05 18:41:07 +00:00
}
}
2019-10-07 13:11:17 +00:00
public float Scale {
2019-10-05 18:41:07 +00:00
get {
return transform.localScale.x;
}
2019-10-07 11:44:26 +00:00
protected set {
2019-10-05 18:41:07 +00:00
transform.localScale = new Vector3(value, value, 1);
}
}
public float Mass {
get {
2019-10-06 15:44:41 +00:00
return Mathf.Pow(gameController.particlesToMerge + 1, Tier);
}
}
public GameObject ParticlePrefab {
get {
return gameController.particlePrefab;
2019-10-05 18:41:07 +00:00
}
}
protected void Awake() {
rigidbody = GetComponent<Rigidbody2D>();
gravitation = GetComponent<Gravitation>();
gameController = GameObject.Find("GameController").GetComponent<GameController>();
merger = GetComponentInChildren<Merger>();
particleCollider = GetComponent<Collider2D>();
mergeCollider = merger.GetComponent<Collider2D>();
2019-10-05 21:50:43 +00:00
emitter = GetComponent<Emitter>();
2019-10-06 13:04:50 +00:00
mainRenderer = GetComponent<SpriteRenderer>();
auraRenderer = transform.Find("Aura").GetComponent<SpriteRenderer>();
detailsRenderer = transform.Find("Details").GetComponent<SpriteRenderer>();
hue = GetComponent<Hue>();
animator = GetComponent<Animator>();
2019-10-06 15:44:41 +00:00
disappear = GetComponent<Disappear>();
2019-10-06 13:04:50 +00:00
}
protected void Start() {
2019-10-06 17:04:47 +00:00
animator.runtimeAnimatorController = gameController.tierAnimation[_tier % gameController.tierAnimation.Length];
hue.PossibleColors = gameController.tierGradients[_tier % gameController.tierGradients.Length];
}
protected void OnDestroy() {
if(Tier >= gameController.maxTierPresent) {
gameController.RecalculateMaxTier();
}
2019-10-05 18:41:07 +00:00
}
}