refactor: unify runtime sets, update naming of event channels
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Michael 2023-08-10 18:14:51 -04:00
parent 7b48612c4b
commit 22995ac307
21 changed files with 104 additions and 80 deletions

View File

@ -50,7 +50,7 @@ MonoBehaviour:
level: 0
xp: 0
attrs: {fileID: 0}
_party: {fileID: 11400000, guid: c9a46588e6ec04d4d91bb80fdffd7869, type: 2}
_party: {fileID: 11400000, guid: 2fdb3d0bb73994d4ba32eb41950b8f15, type: 2}
--- !u!1 &4632618406133265053
GameObject:
m_ObjectHideFlags: 0

15
Assets/Runtime Sets/PlayerParty.asset generated Normal file
View File

@ -0,0 +1,15 @@
%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: 0ec1a0df7a5949a2959596c722680f76, type: 3}
m_Name: PlayerParty
m_EditorClassIdentifier:
items: []

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2fdb3d0bb73994d4ba32eb41950b8f15
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -527,9 +527,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: bb718e52728142e4a8db081fd6a36a70, type: 3}
m_Name:
m_EditorClassIdentifier:
startNewSpawnWaveEventChannel: {fileID: 11400000, guid: 3f9039af54fd5d240b144e1ab3bbeb72, type: 2}
endSpawnWaveEventChannel: {fileID: 11400000, guid: b8a8049e92364834ebac76909a03324b, type: 2}
enemyRuntimeSet: {fileID: 11400000, guid: 7c32c32e039cdda409e8a56d2e320f2d, type: 2}
startNewSpawnWaveEvent: {fileID: 11400000, guid: 3f9039af54fd5d240b144e1ab3bbeb72, type: 2}
endSpawnWaveEventEvent: {fileID: 11400000, guid: b8a8049e92364834ebac76909a03324b, type: 2}
activeEnemies: {fileID: 11400000, guid: 7c32c32e039cdda409e8a56d2e320f2d, type: 2}
spawnCenter: {fileID: 19609788}
minimumSpawnRadius: 10
timeBetweenClearedWaves: 0

View File

@ -1,11 +0,0 @@
using UnityEngine;
namespace DefaultNamespace
{
[CreateAssetMenu(menuName = "Enemy Runtime Set", fileName =
"EnemyRuntimeSet")]
public class EnemyRuntimeSetSO : RuntimeSetSO<Enemy>
{
}
}

View File

@ -4,8 +4,8 @@ using Wave;
namespace Events
{
[CreateAssetMenu(menuName = "Events/Spawn Wave SO Event Channel")]
public class SpawnWaveSOEventChannelSO : ScriptableObject
[CreateAssetMenu(menuName = "Events/Spawn Wave Event")]
public class SpawnWaveEventSO : ScriptableObject
{
public event UnityAction<SpawnWaveSO> OnEventRaised;

View File

@ -1,16 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using UnityEngine;
[CreateAssetMenu(fileName = "HeroParty", menuName = "Hero Party")]
public class HeroPartySO : ScriptableObject
{
[SerializeField]
private List<HeroUnit> unitList = new List<HeroUnit>();
public ReadOnlyCollection<HeroUnit> UnitList => unitList.AsReadOnly();
public void Add(HeroUnit unit) { unitList.Add(unit); }
public void Remove(HeroUnit unit) { unitList.Remove(unit); }
public int Count => unitList.Count;
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: f0603cf6e7f1d884e89c3eb6a478a96c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,9 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using RuntimeSet;
using UnityEngine;
using UnityEngine.Assertions;
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("TestsPlaymode")]
/// <summary>
@ -17,8 +16,8 @@ public class HeroUnit : MonoBehaviour
[SerializeField] private long level;
[SerializeField] private long xp;
[SerializeField] private HeroAttributesSO attrs;
[SerializeField] private HeroPartySO _party;
internal HeroPartySO party => _party;
[SerializeField] private HeroUnitRuntimeSetSO _party;
internal HeroUnitRuntimeSetSO party => _party;
private void OnEnable()
{

3
Assets/Scripts/RuntimeSet.meta generated Normal file
View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e9f6f30f3d8e4445a4a25d03245b2645
timeCreated: 1691632737

View File

@ -0,0 +1,10 @@
using DefaultNamespace;
using UnityEngine;
namespace RuntimeSet
{
[CreateAssetMenu(fileName = "EnemyRuntimeSet",menuName = "Runtime Set/Enemy")]
public class EnemyRuntimeSetSO : RuntimeSetSO<Enemy>
{
}
}

View File

@ -0,0 +1,9 @@
using UnityEngine;
namespace RuntimeSet
{
[CreateAssetMenu(fileName = "EnemyRuntimeSet",menuName = "Runtime Set/Hero Unit")]
public class HeroUnitRuntimeSetSO : RuntimeSetSO<HeroUnit>
{
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0ec1a0df7a5949a2959596c722680f76
timeCreated: 1691632762

View File

@ -0,0 +1,41 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace RuntimeSet
{
public abstract class RuntimeSetSO<T> : ScriptableObject, IEnumerable<T>
{
[HideInInspector] [SerializeField] private List<T> items = new();
protected IReadOnlyCollection<T> Items => items;
public bool IsEmpty => items.Count == 0;
public int Count => items.Count;
public void Add(T item)
{
if (!items.Contains(item))
{
items.Add(item);
}
}
public void Remove(T item)
{
if (items.Contains(item))
{
items.Remove(item);
}
}
public IEnumerator<T> GetEnumerator()
{
return items.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}

View File

@ -1,26 +0,0 @@
using System.Collections.Generic;
using UnityEngine;
public abstract class RuntimeSetSO<T> : ScriptableObject
{
[HideInInspector] [SerializeField] private List<T> items = new();
public IReadOnlyCollection<T> Items => items;
public bool IsEmpty => items.Count == 0;
public void Add(T thing)
{
if (!items.Contains(thing))
{
items.Add(thing);
}
}
public void Remove(T thing)
{
if (items.Contains(thing))
{
items.Remove(thing);
}
}
}

View File

@ -4,7 +4,7 @@ using UnityEngine.Serialization;
namespace Wave
{
[CreateAssetMenu(fileName = "SpawnWave", menuName = "Spawn Wave", order = 0)]
[CreateAssetMenu(fileName = "SpawnWave", menuName = "Spawn/Wave", order = 0)]
public class SpawnWaveSO : ScriptableObject
{
[SerializeField] private List<SpawnPackSO> packs;

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using DefaultNamespace;
using Events;
using RuntimeSet;
using UnityEngine;
using UnityEngine.Assertions;
using Random = UnityEngine.Random;
@ -12,8 +13,8 @@ namespace Wave
{
public class WaveSpawner : MonoBehaviour
{
[SerializeField] private SpawnWaveSOEventChannelSO startNewSpawnWaveEventChannel;
[SerializeField] private SpawnWaveSOEventChannelSO endSpawnWaveEventChannel;
[SerializeField] private SpawnWaveEventSO startNewSpawnWaveEventChannel;
[SerializeField] private SpawnWaveEventSO endSpawnWaveEventChannel;
[SerializeField] private EnemyRuntimeSetSO enemyRuntimeSet;
[SerializeField] private Transform spawnCenter;

View File

@ -1,5 +1,4 @@
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEditor;
using UnityEngine;
@ -18,6 +17,6 @@ public class HeroPartyTest
Assert.AreEqual(1, hero.party.Count);
Object.Destroy(instance);
yield return null;
Assert.IsEmpty(hero.party.UnitList);
Assert.IsEmpty(hero.party);
}
}