party #15
2
Assets/Prefabs/Hero.prefab
generated
2
Assets/Prefabs/Hero.prefab
generated
@ -50,7 +50,7 @@ MonoBehaviour:
|
|||||||
level: 0
|
level: 0
|
||||||
xp: 0
|
xp: 0
|
||||||
attrs: {fileID: 0}
|
attrs: {fileID: 0}
|
||||||
party: {fileID: 11400000, guid: c9a46588e6ec04d4d91bb80fdffd7869, type: 2}
|
_party: {fileID: 11400000, guid: c9a46588e6ec04d4d91bb80fdffd7869, type: 2}
|
||||||
--- !u!1 &4632618406133265053
|
--- !u!1 &4632618406133265053
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.Assertions;
|
||||||
|
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
[assembly: InternalsVisibleTo("TestsPlaymode")]
|
[assembly: InternalsVisibleTo("TestsPlaymode")]
|
||||||
@ -16,21 +17,17 @@ public class HeroUnit : MonoBehaviour
|
|||||||
[SerializeField] private long level;
|
[SerializeField] private long level;
|
||||||
[SerializeField] private long xp;
|
[SerializeField] private long xp;
|
||||||
[SerializeField] private HeroAttributesSO attrs;
|
[SerializeField] private HeroAttributesSO attrs;
|
||||||
[SerializeField] private HeroPartySO party;
|
[SerializeField] private HeroPartySO _party;
|
||||||
|
internal HeroPartySO party => _party;
|
||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
zephyr marked this conversation as resolved
|
|||||||
{
|
{
|
||||||
// NOTE(zeph): Party is mandatory. If none is set, we want an exception.
|
Assert.IsNotNull(_party);
|
||||||
party.Add(this);
|
_party.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDisable()
|
private void OnDisable()
|
||||||
{
|
{
|
||||||
party.Remove(this);
|
_party.Remove(this);
|
||||||
}
|
|
||||||
|
|
||||||
internal HeroPartySO getParty()
|
|
||||||
{
|
|
||||||
return party;
|
|
||||||
}
|
}
|
||||||
zephyr marked this conversation as resolved
madxmike
commented
Should use a property instead of a getter Should use a property instead of a getter
|
|||||||
}
|
}
|
||||||
|
@ -14,11 +14,10 @@ public IEnumerator HeroPartyGetsAllTheHeroes()
|
|||||||
Assert.IsNotNull(prefab);
|
Assert.IsNotNull(prefab);
|
||||||
var instance = Object.Instantiate(prefab);
|
var instance = Object.Instantiate(prefab);
|
||||||
var hero = instance.GetComponent<HeroUnit>();
|
var hero = instance.GetComponent<HeroUnit>();
|
||||||
var party = hero.getParty();
|
|
||||||
yield return null;
|
yield return null;
|
||||||
Assert.AreEqual(1, party.Count);
|
Assert.AreEqual(1, hero.party.Count);
|
||||||
Object.Destroy(instance);
|
Object.Destroy(instance);
|
||||||
yield return null;
|
yield return null;
|
||||||
Assert.IsEmpty(party.UnitList);
|
Assert.IsEmpty(hero.party.UnitList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user
I think its clearer to make these types of notes into assertions.
Assert.IsNotNull(party)
or something like it.