Rework groupConfig for MonsterCoreDrop
This commit is contained in:
parent
11ca7ecdcb
commit
cfbc84e567
@ -20,16 +20,20 @@ MonoBehaviour:
|
|||||||
- _enemy: {fileID: 80204295746100150, guid: 2419a879bd4e47d4fa8b30de0fcdde42, type: 3}
|
- _enemy: {fileID: 80204295746100150, guid: 2419a879bd4e47d4fa8b30de0fcdde42, type: 3}
|
||||||
_count: 2
|
_count: 2
|
||||||
triggerTime: 0.25
|
triggerTime: 0.25
|
||||||
|
dropsMonsterCore: 1
|
||||||
- groupSpawn:
|
- groupSpawn:
|
||||||
- _enemy: {fileID: 80204295746100150, guid: 2419a879bd4e47d4fa8b30de0fcdde42, type: 3}
|
- _enemy: {fileID: 80204295746100150, guid: 2419a879bd4e47d4fa8b30de0fcdde42, type: 3}
|
||||||
_count: 9
|
_count: 9
|
||||||
triggerTime: 1.5
|
triggerTime: 1.5
|
||||||
|
dropsMonsterCore: 1
|
||||||
- groupSpawn:
|
- groupSpawn:
|
||||||
- _enemy: {fileID: 80204295746100150, guid: 1be769d6ef642314b8846bed35e7297c, type: 3}
|
- _enemy: {fileID: 80204295746100150, guid: 1be769d6ef642314b8846bed35e7297c, type: 3}
|
||||||
_count: 7
|
_count: 7
|
||||||
triggerTime: 2
|
triggerTime: 2
|
||||||
|
dropsMonsterCore: 0
|
||||||
- groupSpawn:
|
- groupSpawn:
|
||||||
- _enemy: {fileID: 80204295746100150, guid: 1be769d6ef642314b8846bed35e7297c, type: 3}
|
- _enemy: {fileID: 80204295746100150, guid: 1be769d6ef642314b8846bed35e7297c, type: 3}
|
||||||
_count: 14
|
_count: 14
|
||||||
triggerTime: 3
|
triggerTime: 3
|
||||||
|
dropsMonsterCore: 0
|
||||||
_gameDuration: 3
|
_gameDuration: 3
|
||||||
|
|||||||
@ -249,15 +249,59 @@ public class WaveObserver : Singleton<WaveObserver>
|
|||||||
private void CycleRows(List<int> usedRows, List<EnemyType> currentGroup, int groupIndex)
|
private void CycleRows(List<int> usedRows, List<EnemyType> currentGroup, int groupIndex)
|
||||||
{
|
{
|
||||||
System.Random rand = new System.Random();
|
System.Random rand = new System.Random();
|
||||||
|
bool dropsCore = _monsterCoreGroups != null && _monsterCoreGroups.Count > _currentGroupIndex && _monsterCoreGroups[_currentGroupIndex];
|
||||||
|
int totalToSpawn = _copyGroupSpawn[_currentGroupIndex][groupIndex];
|
||||||
|
int monsterCoreTarget = -1;
|
||||||
|
if (dropsCore && totalToSpawn > 0)
|
||||||
|
{
|
||||||
|
monsterCoreTarget = rand.Next(0, totalToSpawn);
|
||||||
|
}
|
||||||
|
int spawnCount = 0;
|
||||||
while (usedRows.Count < _subjects.Count)
|
while (usedRows.Count < _subjects.Count)
|
||||||
{
|
{
|
||||||
int currentRow = rand.Next(_subjects.Count);
|
int currentRow = rand.Next(_subjects.Count);
|
||||||
if (!usedRows.Contains(currentRow)) //If picked row has laready been used
|
if (!usedRows.Contains(currentRow)) //If picked row has laready been used
|
||||||
{
|
{
|
||||||
_subjects[currentRow].TriggerSpawn(currentGroup[groupIndex].GetEnemyObject());
|
GameObject spawnedInstance = _subjects[currentRow].TriggerSpawn(currentGroup[groupIndex].GetEnemyObject());
|
||||||
|
|
||||||
|
// Si ce spawn doit être le porteur du MonsterCore, on remplace/ajoute le comportement
|
||||||
|
if (monsterCoreTarget >= 0 && spawnCount == monsterCoreTarget)
|
||||||
|
{
|
||||||
|
if (spawnedInstance != null)
|
||||||
|
{
|
||||||
|
// tentative de remplacer le composant Opponent par MonsterCoreDrop
|
||||||
|
var existingOpponent = spawnedInstance.GetComponent<Opponent>();
|
||||||
|
if (existingOpponent != null)
|
||||||
|
{
|
||||||
|
// we remove the existing Opponent-derived behaviour to avoid duplicate logic
|
||||||
|
Object.Destroy(existingOpponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add MonsterCoreDrop component and configure son prefab (si disponible dans la Database)
|
||||||
|
MonsterCoreDrop mc = spawnedInstance.AddComponent<MonsterCoreDrop>();
|
||||||
|
mc.Init();
|
||||||
|
|
||||||
|
// essaye de récupérer le prefab "MonsterCore" dans la database (adapter le nom si nécessaire)
|
||||||
|
//GameObject corePrefab = null;
|
||||||
|
//try
|
||||||
|
//{
|
||||||
|
// corePrefab = Database.Instance.Prefabs["MonsterCore"];
|
||||||
|
//}
|
||||||
|
//catch { corePrefab = null; }
|
||||||
|
|
||||||
|
//if (corePrefab != null)
|
||||||
|
//{
|
||||||
|
// mc.SetCorePrefab(corePrefab);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_copyGroupSpawn[_currentGroupIndex][groupIndex]--;
|
_copyGroupSpawn[_currentGroupIndex][groupIndex]--;
|
||||||
usedRows.Add(currentRow);
|
usedRows.Add(currentRow);
|
||||||
|
spawnCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (_copyGroupSpawn[_currentGroupIndex][groupIndex] == 0) //If current ennemy has reached count of 0
|
if (_copyGroupSpawn[_currentGroupIndex][groupIndex] == 0) //If current ennemy has reached count of 0
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -4,10 +4,34 @@ using UnityEngine;
|
|||||||
|
|
||||||
public class MonsterCoreDrop : Opponent
|
public class MonsterCoreDrop : Opponent
|
||||||
{
|
{
|
||||||
private GameObject mosnterCorePrefab;
|
private GameObject _monsterCorePrefab;
|
||||||
|
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
base.Start();
|
||||||
|
|
||||||
|
// Si le prefab n'est pas fixé via l'inspector, tenter de le charger depuis Resources/"Food"
|
||||||
|
if (_monsterCorePrefab == null)
|
||||||
|
{
|
||||||
|
_monsterCorePrefab = Resources.Load<GameObject>("yieldFood");
|
||||||
|
if (_monsterCorePrefab == null)
|
||||||
|
{
|
||||||
|
Debug.LogWarning("MonsterCoreDrop: prefab 'yieldFood' introuvable dans le dossier Resources. Assignez-le dans l'inspector ou placez-le dans Resources/yieldFood.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetCorePrefab(GameObject prefab)
|
||||||
|
{
|
||||||
|
_monsterCorePrefab = prefab;
|
||||||
|
}
|
||||||
|
|
||||||
public override void Death()
|
public override void Death()
|
||||||
{
|
{
|
||||||
Instantiate(mosnterCorePrefab, transform.position, Quaternion.identity);
|
if (_monsterCorePrefab != null)
|
||||||
|
{
|
||||||
|
Instantiate(_monsterCorePrefab, transform.position, Quaternion.identity);
|
||||||
|
}
|
||||||
base.Death();
|
base.Death();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -138,9 +138,9 @@ public class SpawnerTile : LevelTile
|
|||||||
* Instantly spawns an enemy.
|
* Instantly spawns an enemy.
|
||||||
* Used for GroupSpawn
|
* Used for GroupSpawn
|
||||||
*/
|
*/
|
||||||
public void TriggerSpawn(GameObject enemy)
|
public GameObject TriggerSpawn(GameObject enemy)
|
||||||
{
|
{
|
||||||
enemy.Create(Position, parent: LevelManager.Instance.LevelTransform);
|
return enemy.Create(Position, parent: LevelManager.Instance.LevelTransform);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user