private void Awake() { myForceOverLifetime = GetComponent <ParticleSystem>().forceOverLifetime; myEmission = GetComponent <ParticleSystem>().emission; render = GetComponent <SpriteRenderer>(); if (breakableTilemap == null) { breakableTilemap = FindObjectOfType <BreakableTilemap>(); } }
/// <summary> /// loads in the level data if it exists /// </summary> private void LoadLevel() { GameSaver.levelDataObjects = FindObjectsOfType <MonoBehaviour>().OfType <ILevelData>(); LevelSaveData levelData = null; if ((levelData = GameSaver.LoadLevelData(areaName)) != null) { //create a dictionary of all the loaded in level dat Dictionary <string, bool> stateLookup = new Dictionary <string, bool>(); for (int i = 0; i < levelData.objectNames.Count; i++) { stateLookup.Add(levelData.objectNames[i], levelData.objectStates[i]); } //Debug.Log((FindObjectsOfType<MonoBehaviour>().OfType<ILevelData>()).Count<ILevelData>()); //loop through all the level data objects foreach (ILevelData data in GameSaver.levelDataObjects) { //load objects based on state from the dictionary if (stateLookup.ContainsKey(data.Name)) { data.OnLevelLoad(stateLookup[data.Name]); } } BreakableTilemap breakable = FindObjectOfType <BreakableTilemap>(); if (breakable) { List <Vector2Int> tempBroken = new List <Vector2Int>(); foreach (int[] pos in levelData.broken) { tempBroken.Add(new Vector2Int(pos[0], pos[1])); } breakable.Broken = tempBroken; } } }
private void CollisionChecks(Collider2D collision) { if (!active) { return; } isBreaking = false; switch (collision.gameObject.layer) { case 17: //collision with breakable object if (breakableTilemap == null) { breakableTilemap = collision.GetComponent <BreakableTilemap>(); } breakableTilemap.BreakTile(transform.position); isBreaking = true; //start breaking the tilemap break; case 9: //collision with solid SetState(false); projectilePool.BurstParticles(transform.position); break; //collision with player case 8: if (collision.CompareTag("Player")) { //damage the player collision.GetComponent <IHealthObject>().Damage(1); //push the player pushing = collision.GetComponent <PhysicsObject>(); pushing.InputVelocity = moveVelocity * pushForce; pushing.MoveVelocity = Vector2.zero; pushing.Frozen = true; } break; } }
public static bool SaveLevelData() { //create a new level save object LevelSaveData levelData = new LevelSaveData(currentLevelName); //add the states data of all the level data objects foreach (ILevelData data in levelDataObjects) { levelData.AddObject(data.Name, data.State); } BreakableTilemap breakable = FindObjectOfType <BreakableTilemap>(); //add the breakable tilemap data if (breakable) { foreach (Vector2Int broken in breakable.Broken) { levelData.AddBroken(broken); } } //save the level data return(SaveLevelData(levelData)); }