Progrès WaveEditor
WaveObserver gère le nombre d'ennemi à créer et assure d'arreter la création d'ennemis supplémentaires. SpawnerTile détermine un intervalle aléatoire automatiquement après chaque création d'ennemi. La première intervalle a plus de chance d'être plus courte que les intervalles suivantes. Config01 est le scriptable object de type LevelConfig Suppression de commentaires de tests
This commit is contained in:
parent
d75a1ec747
commit
cad2436773
18
Assets/LevelConfig/Config01.asset
Normal file
18
Assets/LevelConfig/Config01.asset
Normal file
@ -0,0 +1,18 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: eb0795e326609f0499365f5b65c2b5cd, type: 3}
|
||||
m_Name: Config01
|
||||
m_EditorClassIdentifier:
|
||||
_constantSpawn:
|
||||
- _enemy: {fileID: 313037212318601125, guid: 5bbf0d85fa5bb3f4599da79f0a84e3a9, type: 3}
|
||||
_count: 20
|
||||
_gameDuration: 3
|
||||
8
Assets/LevelConfig/Config01.asset.meta
Normal file
8
Assets/LevelConfig/Config01.asset.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21b0f85f7c746974db1e72f2df646f5d
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -16,14 +16,11 @@ public class LevelConfig : ScriptableObject
|
||||
return _constantSpawn;
|
||||
}
|
||||
}
|
||||
public float GameDuration
|
||||
{
|
||||
get
|
||||
public float GetInterval()
|
||||
{
|
||||
float interval = SumCount().ToFloat() / _gameDuration * 0.01f;
|
||||
return interval;
|
||||
}
|
||||
}
|
||||
public EnemyType GetRandomSpawn()
|
||||
{
|
||||
if (_constantSpawn.Count == 1)
|
||||
|
||||
@ -5,17 +5,25 @@ using UnityEngine;
|
||||
public class WaveObserver : Singleton<WaveObserver>
|
||||
{
|
||||
private List<SpawnerTile> _subjects = new List<SpawnerTile>();
|
||||
private List<int> _copyConstantSpawn;
|
||||
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 LevelConfig LevelConfig
|
||||
{
|
||||
set
|
||||
{
|
||||
_levelConfig = value;
|
||||
_copyConstantSpawn = new List<int>();
|
||||
foreach (EnemyType enemy in _levelConfig.ConstantSpawn)
|
||||
{
|
||||
_copyConstantSpawn.Add(enemy.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Attach(SpawnerTile spawnerSubject)
|
||||
{
|
||||
spawnerSubject.Prefab = _levelConfig.GetRandomSpawn().GetEnemyObject();
|
||||
WaveUpdate(spawnerSubject);
|
||||
spawnerSubject.InitialSpawnSpeed(_levelConfig.GetInterval());
|
||||
_subjects.Add(spawnerSubject);
|
||||
}
|
||||
|
||||
@ -23,52 +31,25 @@ public class WaveObserver : Singleton<WaveObserver>
|
||||
{
|
||||
if (spawnerSubject.Prefab.Equals(_levelConfig.ConstantSpawn[0].GetEnemyObject()))
|
||||
{
|
||||
int currentCount = _levelConfig.ConstantSpawn[0].Count;
|
||||
if (currentCount == 0)
|
||||
int currentCount = 0;
|
||||
for (int i = 0; i < _copyConstantSpawn.Count; i++)
|
||||
{
|
||||
if(_levelConfig.ConstantSpawn[i].GetEnemyObject() == spawnerSubject.Prefab)
|
||||
{
|
||||
currentCount = _copyConstantSpawn[i]--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (currentCount <= 0)
|
||||
{
|
||||
foreach (SpawnerTile spawner in _subjects)
|
||||
{
|
||||
if (spawner.Prefab.Equals(spawnerSubject.Prefab))
|
||||
{
|
||||
//spawner.SpawnSpeed = 0.0f;
|
||||
spawner.StopSpawn();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,6 +138,8 @@ public class LevelManager : Singleton<LevelManager>
|
||||
}
|
||||
|
||||
_currentLevel = level;
|
||||
_waveObserver = WaveObserver.Instance;
|
||||
_waveObserver.LevelConfig = _currentLevel.WaveConfig;
|
||||
Grid grid = Object.FindObjectOfType<Grid>();
|
||||
//create new grid if there is none
|
||||
if (!grid)
|
||||
@ -163,10 +165,6 @@ 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>
|
||||
|
||||
@ -2,7 +2,7 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(menuName = "Gather And Defend/Spawner Tile")]
|
||||
public class SpawnerTile : LevelTile, IWaveSubject
|
||||
public class SpawnerTile : LevelTile
|
||||
{
|
||||
[SerializeField]
|
||||
private GameObject _prefab;
|
||||
@ -14,6 +14,9 @@ public class SpawnerTile : LevelTile, IWaveSubject
|
||||
[SerializeField, Range(0, 1.001f)]
|
||||
private float _spawnCounter = 0;
|
||||
private WaveObserver _observer;
|
||||
private float _initialSpawnSpeed;
|
||||
private const float MAX_SPAWN_SPEED = 0.01f;
|
||||
private const float RANDOM_MODIFIER = 5.0f;
|
||||
|
||||
|
||||
public override void LevelStart()
|
||||
@ -23,7 +26,6 @@ public class SpawnerTile : LevelTile, IWaveSubject
|
||||
if (_spawnOnStart && _lifetime <= 0)
|
||||
{
|
||||
_prefab.Create(Position, parent: LevelManager.Instance.LevelTransform);
|
||||
_observer.NotifySpawned(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,6 +37,7 @@ public class SpawnerTile : LevelTile, IWaveSubject
|
||||
|
||||
_spawnCounter = 0;
|
||||
_prefab.Create(Position, parent: LevelManager.Instance.LevelTransform);
|
||||
_spawnSpeed = Mathf.Max(_initialSpawnSpeed / Random.Range(0.0f, RANDOM_MODIFIER), MAX_SPAWN_SPEED);
|
||||
_observer.NotifySpawned(this);
|
||||
}
|
||||
public override bool Equals(ILevelObject other)
|
||||
@ -55,6 +58,12 @@ public class SpawnerTile : LevelTile, IWaveSubject
|
||||
dict[nameof(_spawnOnStart)] = _spawnOnStart;
|
||||
return dict;
|
||||
}
|
||||
|
||||
internal void StopSpawn()
|
||||
{
|
||||
_spawnSpeed = 0.0f;
|
||||
}
|
||||
|
||||
public override void LoadDictionary(Dictionary<string, object> dict)
|
||||
{
|
||||
base.LoadDictionary(dict);
|
||||
@ -79,5 +88,9 @@ public class SpawnerTile : LevelTile, IWaveSubject
|
||||
}
|
||||
}
|
||||
|
||||
public float SpawnSpeed { set { _spawnSpeed = value; } }
|
||||
public void InitialSpawnSpeed(float value)
|
||||
{
|
||||
_initialSpawnSpeed = value;
|
||||
_spawnSpeed = Mathf.Max(_initialSpawnSpeed / Random.Range(0.0f, RANDOM_MODIFIER - 2.0f), MAX_SPAWN_SPEED);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user