Progrès WaveEditor
WaveObserver donne aux spawners les unités à instancier ainsi que l'intervalle de création de ceux-ci LevelConfig passe de Level vers LevelManager puis il est utilisé dans l'instance de WaveObserver
This commit is contained in:
parent
15b5976cb0
commit
d75a1ec747
@ -309,6 +309,7 @@ MonoBehaviour:
|
||||
_position: {x: 10, y: 1, z: 0}
|
||||
- _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2}
|
||||
_position: {x: 10, y: 2, z: 0}
|
||||
_isSpawner: 0
|
||||
_isInvisible: 0
|
||||
_isCollidable: 0
|
||||
_isTrigger: 0
|
||||
@ -318,6 +319,7 @@ MonoBehaviour:
|
||||
_scale: {x: 1, y: 1}
|
||||
- _key: Entities
|
||||
_tiles: []
|
||||
_isSpawner: 0
|
||||
_isInvisible: 0
|
||||
_isCollidable: 0
|
||||
_isTrigger: 0
|
||||
@ -343,6 +345,7 @@ MonoBehaviour:
|
||||
_position: {x: 10, y: 0, z: 0}
|
||||
- _tile: {fileID: 11400000, guid: 4002377ed7e87b34699f126f2b10c703, type: 2}
|
||||
_position: {x: 10, y: 2, z: 0}
|
||||
_isSpawner: 0
|
||||
_isInvisible: 0
|
||||
_isCollidable: 0
|
||||
_isTrigger: 0
|
||||
@ -350,3 +353,4 @@ MonoBehaviour:
|
||||
_renderLayer: Default
|
||||
_position: {x: 0, y: 0}
|
||||
_scale: {x: 1, y: 1}
|
||||
_waveConfig: {fileID: 11400000, guid: 21b0f85f7c746974db1e72f2df646f5d, type: 2}
|
||||
|
||||
@ -5,12 +5,42 @@ using UnityEngine;
|
||||
[CreateAssetMenu(menuName = "Gather And Defend/Levels/LevelConfig")]
|
||||
public class LevelConfig : ScriptableObject
|
||||
{
|
||||
//IEnumerable for 1. list of type 2. timer. with title of row nbr INSPIRED FROM DATA
|
||||
[SerializeField]
|
||||
private List<EnemyType> _constantSpawn = new List<EnemyType>();
|
||||
[SerializeField]
|
||||
private int _gameDuration = 0;
|
||||
public List<EnemyType> ConstantSpawn { get { return _constantSpawn; } }
|
||||
public int GameDuration { get { return _gameDuration; } }
|
||||
private float _gameDuration = 0;
|
||||
public List<EnemyType> ConstantSpawn
|
||||
{
|
||||
get
|
||||
{
|
||||
return _constantSpawn;
|
||||
}
|
||||
}
|
||||
public float GameDuration
|
||||
{
|
||||
get
|
||||
{
|
||||
float interval = SumCount().ToFloat() / _gameDuration * 0.01f;
|
||||
return interval;
|
||||
}
|
||||
}
|
||||
public EnemyType GetRandomSpawn()
|
||||
{
|
||||
if (_constantSpawn.Count == 1)
|
||||
{
|
||||
return _constantSpawn[0];
|
||||
}
|
||||
return _constantSpawn[Random.Range(0, _constantSpawn.Count - 1)];
|
||||
}
|
||||
|
||||
private int SumCount()
|
||||
{
|
||||
int sum = 0;
|
||||
foreach (EnemyType enemy in _constantSpawn)
|
||||
{
|
||||
sum += enemy.Count;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
74
Assets/Scripts/LevelConfig/WaveObserver.cs
Normal file
74
Assets/Scripts/LevelConfig/WaveObserver.cs
Normal file
@ -0,0 +1,74 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class WaveObserver : Singleton<WaveObserver>
|
||||
{
|
||||
private List<SpawnerTile> _subjects = new List<SpawnerTile>();
|
||||
private LevelConfig _levelConfig;
|
||||
public LevelConfig LevelConfig { set { _levelConfig = value; } }
|
||||
private float[] _delay = {0,1,2,3,4,5};
|
||||
private float _currentToughness = 0;
|
||||
private int _gameProgress = 0;
|
||||
private int _maxSync = 6;
|
||||
|
||||
public void Attach(SpawnerTile spawnerSubject)
|
||||
{
|
||||
spawnerSubject.Prefab = _levelConfig.GetRandomSpawn().GetEnemyObject();
|
||||
WaveUpdate(spawnerSubject);
|
||||
_subjects.Add(spawnerSubject);
|
||||
}
|
||||
|
||||
public void NotifySpawned(SpawnerTile spawnerSubject)
|
||||
{
|
||||
if (spawnerSubject.Prefab.Equals(_levelConfig.ConstantSpawn[0].GetEnemyObject()))
|
||||
{
|
||||
int currentCount = _levelConfig.ConstantSpawn[0].Count;
|
||||
if (currentCount == 0)
|
||||
{
|
||||
foreach (SpawnerTile spawner in _subjects)
|
||||
{
|
||||
if (spawner.Prefab.Equals(spawnerSubject.Prefab))
|
||||
{
|
||||
//spawner.SpawnSpeed = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void WaveUpdate(SpawnerTile spawnerSubject)
|
||||
{
|
||||
//Lottery of order. Reducing maxSync increases the chances team spawning
|
||||
int spawningOrder = Random.Range(1, _maxSync);
|
||||
Debug.Log("Je suis " + spawningOrder + "e de la liste.");
|
||||
switch (spawningOrder)
|
||||
{
|
||||
case 1:
|
||||
spawnerSubject.SpawnSpeed = _levelConfig.GameDuration + _levelConfig.GameDuration * _delay[0];
|
||||
break;
|
||||
case 2:
|
||||
spawnerSubject.SpawnSpeed = _levelConfig.GameDuration + _levelConfig.GameDuration * _delay[1];
|
||||
break;
|
||||
case 3:
|
||||
spawnerSubject.SpawnSpeed = _levelConfig.GameDuration + _levelConfig.GameDuration * _delay[2];
|
||||
break;
|
||||
case 4:
|
||||
spawnerSubject.SpawnSpeed = _levelConfig.GameDuration + _levelConfig.GameDuration * _delay[3];
|
||||
break;
|
||||
case 5:
|
||||
spawnerSubject.SpawnSpeed = _levelConfig.GameDuration + _levelConfig.GameDuration * _delay[4];
|
||||
break;
|
||||
case 6:
|
||||
spawnerSubject.SpawnSpeed = _levelConfig.GameDuration + _levelConfig.GameDuration * _delay[5];
|
||||
break;
|
||||
}
|
||||
_gameProgress++;
|
||||
|
||||
if(_gameProgress == _maxSync)
|
||||
{
|
||||
_maxSync--;
|
||||
_gameProgress = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/LevelConfig/WaveObserver.cs.meta
Normal file
11
Assets/Scripts/LevelConfig/WaveObserver.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6eab34a14c5d4d746a70792d4d7914a2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -12,7 +12,7 @@ namespace GatherAndDefend.LevelEditor
|
||||
[SerializeField]
|
||||
private List<TilemapData> _data = new List<TilemapData>();
|
||||
[SerializeField]
|
||||
private LevelConfig _levelConfig;
|
||||
private LevelConfig _waveConfig;
|
||||
public void SaveFromTilemap(Tilemap tilemap)
|
||||
{
|
||||
var data = new TilemapData();
|
||||
@ -23,9 +23,10 @@ namespace GatherAndDefend.LevelEditor
|
||||
{
|
||||
var data = _data.Find(x => x.Key == tilemap.name);
|
||||
if (data == null) return;
|
||||
|
||||
data.LoadToTilemap(tilemap, _levelConfig);
|
||||
|
||||
data.LoadToTilemap(tilemap);
|
||||
}
|
||||
public LevelConfig WaveConfig { get { return _waveConfig; } }
|
||||
|
||||
public IEnumerator<TilemapData> GetEnumerator()
|
||||
{
|
||||
|
||||
@ -33,7 +33,7 @@ namespace GatherAndDefend.LevelEditor
|
||||
|
||||
public string Key => _key;
|
||||
|
||||
public void LoadToTilemap(Tilemap reference, LevelConfig _levelConfig = null)
|
||||
public void LoadToTilemap(Tilemap reference)
|
||||
{
|
||||
reference.transform.localPosition = _position;
|
||||
reference.transform.localScale = _scale;
|
||||
@ -48,22 +48,9 @@ namespace GatherAndDefend.LevelEditor
|
||||
collision.isTrigger = _isTrigger;
|
||||
}
|
||||
|
||||
Debug.Log(_levelConfig != null);
|
||||
if ( _levelConfig != null && _key.Equals("Spawners"))
|
||||
{
|
||||
foreach (TileData spawner in _tiles)
|
||||
{
|
||||
//string id = spawner.Tile.GetInstanceID().ToString();
|
||||
//SpawnerTile spawnerGO = GameObject.Find(id).GetComponent<SpawnerTile>();
|
||||
//spawnerGO.Prefab = _levelConfig.ConstantSpawn[0].GetEnemyObject();
|
||||
Debug.Log("____GODLIKE____");
|
||||
}
|
||||
}
|
||||
foreach (TileData data in _tiles)
|
||||
{
|
||||
reference.SetTile(data.Position, data.Tile);
|
||||
Debug.Log(_key.ToString());
|
||||
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
|
||||
@ -20,6 +20,7 @@ public class LevelManager : Singleton<LevelManager>
|
||||
private readonly List<ILevelObject> _toAdd;
|
||||
private readonly List<ILevelObject> _toRemove;
|
||||
private readonly List<ILevelObject> _levelObjects;
|
||||
private WaveObserver _waveObserver;
|
||||
|
||||
private Tilemap _dynamicTilemap;
|
||||
public Tilemap DynamicTilemap
|
||||
@ -162,6 +163,10 @@ public class LevelManager : Singleton<LevelManager>
|
||||
tilemap.transform.SetParent(grid.transform);
|
||||
}
|
||||
Debug.Log("level loaded successfully");
|
||||
|
||||
Debug.Log("Decompte = " + _currentLevel.WaveConfig.GameDuration);
|
||||
_waveObserver = WaveObserver.Instance;
|
||||
_waveObserver.LevelConfig = _currentLevel.WaveConfig;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -14,7 +14,7 @@ public class EnemyType
|
||||
|
||||
public int GetEnemyToughness()
|
||||
{
|
||||
float toughness = Mathf.Round((_enemy.Hp / 10) + _enemy.AttackDamage / 2);
|
||||
float toughness = Mathf.Round((_enemy.Hp / 10) / 2);
|
||||
return (int)toughness;
|
||||
}
|
||||
|
||||
@ -22,10 +22,10 @@ public class EnemyType
|
||||
{
|
||||
return _enemy.gameObject;
|
||||
}
|
||||
|
||||
public int GetEnemyCount()
|
||||
public int Count
|
||||
{
|
||||
return _count;
|
||||
get { return _count; }
|
||||
set { _count = value; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(menuName = "Gather And Defend/Spawner Tile")]
|
||||
public class SpawnerTile : LevelTile
|
||||
public class SpawnerTile : LevelTile, IWaveSubject
|
||||
{
|
||||
[SerializeField]
|
||||
private GameObject _prefab;
|
||||
@ -13,13 +13,17 @@ public class SpawnerTile : LevelTile
|
||||
private float _spawnSpeed = 0;
|
||||
[SerializeField, Range(0, 1.001f)]
|
||||
private float _spawnCounter = 0;
|
||||
private WaveObserver _observer;
|
||||
|
||||
|
||||
public override void LevelStart()
|
||||
{
|
||||
_observer = WaveObserver.Instance;
|
||||
_observer.Attach(this);
|
||||
if (_spawnOnStart && _lifetime <= 0)
|
||||
{
|
||||
_prefab.Create(Position, parent: LevelManager.Instance.LevelTransform);
|
||||
_observer.NotifySpawned(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,6 +35,7 @@ public class SpawnerTile : LevelTile
|
||||
|
||||
_spawnCounter = 0;
|
||||
_prefab.Create(Position, parent: LevelManager.Instance.LevelTransform);
|
||||
_observer.NotifySpawned(this);
|
||||
}
|
||||
public override bool Equals(ILevelObject other)
|
||||
{
|
||||
@ -62,7 +67,17 @@ public class SpawnerTile : LevelTile
|
||||
_spawnOnStart = dict[nameof(_spawnOnStart)].ToBool();
|
||||
}
|
||||
|
||||
public GameObject Prefab { set {
|
||||
Debug.Log("Changed");
|
||||
_prefab = value; } }
|
||||
public GameObject Prefab
|
||||
{
|
||||
set
|
||||
{
|
||||
_prefab = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
return _prefab;
|
||||
}
|
||||
}
|
||||
|
||||
public float SpawnSpeed { set { _spawnSpeed = value; } }
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user