增加A2WToolBox工具集,增加Launch场景核LaunchPanel

This commit is contained in:
Wurui
2025-11-08 11:06:48 +08:00
parent 3e92e5684a
commit 3b43829e85
726 changed files with 87807 additions and 215 deletions

View File

@@ -0,0 +1,25 @@
{
"name": "MonsterLove.StateMachine.Tests.EditorTests",
"rootNamespace": "",
"references": [
"MonsterLove.StateMachine.Runtime",
"MonsterLove.StateMachine.Tests.Runtime",
"UnityEngine.TestRunner",
"UnityEditor.TestRunner"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"nunit.framework.dll"
],
"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 7a05261385aac3941b3b93eaf9a30bed
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,193 @@
using System;
using MonsterLove.StateMachine;
using NUnit.Framework;
using UnityEngine;
using UnityEditor;
using System.Collections;
using Object = UnityEngine.Object;
[TestFixture]
[Category("State Machine Tests")]
internal class TestBasicTransitions
{
public enum States
{
One,
Two,
Three,
}
private GameObject go;
private ClassWithBasicStates behaviour;
private StateMachineRunner engine;
private StateMachine<States> fsm;
[SetUp]
public void Init()
{
go = new GameObject("stateTest");
behaviour = go.AddComponent<ClassWithBasicStates>();
engine = go.AddComponent<StateMachineRunner>();
}
[TearDown]
public void Kill()
{
Object.DestroyImmediate(go);
}
[Test]
public void NoTransitions()
{
fsm = engine.Initialize<States>(behaviour);
//Goes to start state by default;
Assert.AreEqual(0, behaviour.oneStats.enterCount);
Assert.AreEqual(0, behaviour.oneStats.updateCount);
Assert.AreEqual(0, behaviour.oneStats.lateUpdateCount);
Assert.AreEqual(0, behaviour.oneStats.exitCount);
Assert.AreEqual(0, behaviour.oneStats.finallyCount);
Assert.AreEqual(0, behaviour.twoStats.enterCount);
Assert.AreEqual(0, behaviour.twoStats.updateCount);
Assert.AreEqual(0, behaviour.twoStats.lateUpdateCount);
Assert.AreEqual(0, behaviour.twoStats.exitCount);
Assert.AreEqual(0, behaviour.twoStats.finallyCount);
Assert.AreEqual(0, behaviour.threeStats.enterCount);
Assert.AreEqual(0, behaviour.threeStats.updateCount);
Assert.AreEqual(0, behaviour.threeStats.lateUpdateCount);
Assert.AreEqual(0, behaviour.threeStats.exitCount);
Assert.AreEqual(0, behaviour.threeStats.finallyCount);
}
[Test]
public void InitialTransition()
{
fsm = engine.Initialize<States>(behaviour, States.One);
fsm.ChangeState(States.Two);
Assert.AreEqual(1, behaviour.oneStats.enterCount);
Assert.AreEqual(0, behaviour.oneStats.updateCount);
Assert.AreEqual(0, behaviour.oneStats.lateUpdateCount);
Assert.AreEqual(1, behaviour.oneStats.exitCount);
Assert.AreEqual(1, behaviour.oneStats.finallyCount);
Assert.AreEqual(1, behaviour.twoStats.enterCount);
Assert.AreEqual(0, behaviour.twoStats.updateCount);
Assert.AreEqual(0, behaviour.twoStats.lateUpdateCount);
Assert.AreEqual(0, behaviour.twoStats.exitCount);
Assert.AreEqual(0, behaviour.twoStats.finallyCount);
Assert.AreEqual(0, behaviour.threeStats.enterCount);
Assert.AreEqual(0, behaviour.threeStats.updateCount);
Assert.AreEqual(0, behaviour.threeStats.lateUpdateCount);
Assert.AreEqual(0, behaviour.threeStats.exitCount);
Assert.AreEqual(0, behaviour.threeStats.finallyCount);
}
[Test]
public void IgnoreMultipleTransitions()
{
fsm = engine.Initialize<States>(behaviour, States.One);
fsm.ChangeState(States.Two);
fsm.ChangeState(States.Two);
Assert.AreEqual(1, behaviour.oneStats.enterCount);
Assert.AreEqual(0, behaviour.oneStats.updateCount);
Assert.AreEqual(0, behaviour.oneStats.lateUpdateCount);
Assert.AreEqual(1, behaviour.oneStats.exitCount);
Assert.AreEqual(1, behaviour.oneStats.finallyCount);
Assert.AreEqual(1, behaviour.twoStats.enterCount);
Assert.AreEqual(0, behaviour.twoStats.updateCount);
Assert.AreEqual(0, behaviour.twoStats.lateUpdateCount);
Assert.AreEqual(0, behaviour.twoStats.exitCount);
Assert.AreEqual(0, behaviour.twoStats.finallyCount);
Assert.AreEqual(0, behaviour.threeStats.enterCount);
Assert.AreEqual(0, behaviour.threeStats.updateCount);
Assert.AreEqual(0, behaviour.threeStats.lateUpdateCount);
Assert.AreEqual(0, behaviour.threeStats.exitCount);
Assert.AreEqual(0, behaviour.threeStats.finallyCount);
fsm.reenter = true;
fsm.ChangeState(States.Three);
fsm.ChangeState(States.Three);
Assert.AreEqual(1, behaviour.twoStats.enterCount);
Assert.AreEqual(0, behaviour.twoStats.updateCount);
Assert.AreEqual(0, behaviour.twoStats.lateUpdateCount);
Assert.AreEqual(1, behaviour.twoStats.exitCount);
Assert.AreEqual(1, behaviour.twoStats.finallyCount);
Assert.AreEqual(2, behaviour.threeStats.enterCount);
Assert.AreEqual(0, behaviour.threeStats.updateCount);
Assert.AreEqual(0, behaviour.threeStats.lateUpdateCount);
Assert.AreEqual(1, behaviour.threeStats.exitCount);
Assert.AreEqual(1, behaviour.threeStats.finallyCount);
}
[Test]
public void SpecifiedDefault()
{
fsm = engine.Initialize<States>(behaviour, States.Two);
Assert.AreEqual(0, behaviour.oneStats.enterCount);
Assert.AreEqual(0, behaviour.oneStats.updateCount);
Assert.AreEqual(0, behaviour.oneStats.lateUpdateCount);
Assert.AreEqual(0, behaviour.oneStats.exitCount);
Assert.AreEqual(0, behaviour.oneStats.finallyCount);
Assert.AreEqual(1, behaviour.twoStats.enterCount);
Assert.AreEqual(0, behaviour.twoStats.updateCount);
Assert.AreEqual(0, behaviour.twoStats.lateUpdateCount);
Assert.AreEqual(0, behaviour.twoStats.exitCount);
Assert.AreEqual(0, behaviour.twoStats.finallyCount);
Assert.AreEqual(0, behaviour.threeStats.enterCount);
Assert.AreEqual(0, behaviour.threeStats.updateCount);
Assert.AreEqual(0, behaviour.threeStats.lateUpdateCount);
Assert.AreEqual(0, behaviour.threeStats.exitCount);
Assert.AreEqual(0, behaviour.threeStats.finallyCount);
}
[Test]
public void MultipleTransitions()
{
fsm = engine.Initialize<States>(behaviour, States.One);
fsm.ChangeState(States.One);
fsm.ChangeState(States.Two);
fsm.ChangeState(States.Three);
Assert.AreEqual(1, behaviour.oneStats.enterCount);
Assert.AreEqual(0, behaviour.oneStats.updateCount);
Assert.AreEqual(0, behaviour.oneStats.lateUpdateCount);
Assert.AreEqual(1, behaviour.oneStats.exitCount);
Assert.AreEqual(1, behaviour.oneStats.finallyCount);
Assert.AreEqual(1, behaviour.twoStats.enterCount);
Assert.AreEqual(0, behaviour.twoStats.updateCount);
Assert.AreEqual(0, behaviour.twoStats.lateUpdateCount);
Assert.AreEqual(1, behaviour.twoStats.exitCount);
Assert.AreEqual(1, behaviour.twoStats.finallyCount);
Assert.AreEqual(1, behaviour.threeStats.enterCount);
Assert.AreEqual(0, behaviour.threeStats.updateCount);
Assert.AreEqual(0, behaviour.threeStats.lateUpdateCount);
Assert.AreEqual(0, behaviour.threeStats.exitCount);
Assert.AreEqual(0, behaviour.threeStats.finallyCount);
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 899062ccff9246a4c8873c29a4ac6bf4
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,108 @@
using System.Runtime.CompilerServices;
using MonsterLove.StateMachine;
using NUnit.Framework;
using UnityEngine;
/// This is an important test, enables subscription directly to driver objects
/// Eg. button.OnClick.AddListener(fsm.Driver.Foo.Invoke)
public class TestCachedDriver
{
public enum States
{
One,
Two,
Three,
Four,
}
public class Driver
{
public StateEvent Foo;
}
private GameObject go;
private StateClass behaviour;
private StateMachine<States, Driver> fsm;
private Driver driver;
[SetUp]
public void Init()
{
go = new GameObject();
behaviour = go.AddComponent<StateClass>();
fsm = new StateMachine<States, Driver>(behaviour);
driver = fsm.Driver;
}
[TearDown]
public void Kill()
{
Object.DestroyImmediate(go);
}
[Test]
public void TestCachedDriverEvents()
{
fsm.ChangeState(States.One);
driver.Foo.Invoke();
Assert.AreEqual(1, behaviour.oneFoo);
Assert.AreEqual(0, behaviour.twoFoo);
fsm.ChangeState(States.Two);
driver.Foo.Invoke();
Assert.AreEqual(1, behaviour.oneFoo);
Assert.AreEqual(1, behaviour.twoFoo);
}
private class StateClass : MonoBehaviour
{
public int oneEnter;
public int oneFoo;
public int oneExit;
public int twoEnter;
public int twoFoo;
public int twoExit;
void One_Enter()
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Enter", Time.frameCount);
oneEnter++;
}
void One_Foo()
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Foo", Time.frameCount);
oneFoo++;
}
void One_Exit()
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Exit", Time.frameCount);
oneExit++;
}
void Two_Enter()
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Enter", Time.frameCount);
twoEnter++;
}
void Two_Foo()
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Foo", Time.frameCount);
twoFoo++;
}
void Two_Exit()
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Exit", Time.frameCount);
twoExit++;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 597262340b854411b6859c314743cbfe
timeCreated: 1568106780

View File

@@ -0,0 +1,179 @@
using MonsterLove.StateMachine;
using NUnit.Framework;
using UnityEngine;
public class TestCustomDriver
{
public enum States
{
One,
Two,
Three,
Four,
}
public class Driver
{
public StateEvent Foo;
public StateEvent<int> Bar;
public StateEvent<int, int> Baz;
}
private GameObject go;
private StateClass behaviour;
private StateMachine<States, Driver> fsm;
[SetUp]
public void Init()
{
go = new GameObject();
behaviour = go.AddComponent<StateClass>();
fsm = new StateMachine<States, Driver>(behaviour);
}
[TearDown]
public void Kill()
{
Object.DestroyImmediate(go);
}
[Test]
public void TestDriverNotNull()
{
Assert.NotNull(fsm.Driver);
}
[Test]
public void TestCustomEvents()
{
fsm.ChangeState(States.One);
fsm.Driver.Foo.Invoke();
fsm.Driver.Bar.Invoke(5);
fsm.Driver.Baz.Invoke(6, 7);
Assert.AreEqual(1, behaviour.oneFoo);
Assert.AreEqual(1, behaviour.oneBar);
Assert.AreEqual(1, behaviour.oneBaz);
Assert.AreEqual(5, behaviour.oneBarValue);
Assert.AreEqual(6, behaviour.oneBazValueA);
Assert.AreEqual(7, behaviour.oneBazValueB);
Assert.AreEqual(0, behaviour.twoFoo);
Assert.AreEqual(0, behaviour.twoBar);
Assert.AreEqual(0, behaviour.twoBaz);
Assert.AreEqual(0, behaviour.twoBarValue);
Assert.AreEqual(0, behaviour.twoBazValueA);
Assert.AreEqual(0, behaviour.twoBazValueB);
fsm.ChangeState(States.Two);
fsm.Driver.Foo.Invoke();
fsm.Driver.Bar.Invoke(8);
fsm.Driver.Baz.Invoke(9, 10);
Assert.AreEqual(1, behaviour.oneFoo);
Assert.AreEqual(1, behaviour.oneBar);
Assert.AreEqual(1, behaviour.oneBaz);
Assert.AreEqual(5, behaviour.oneBarValue);
Assert.AreEqual(6, behaviour.oneBazValueA);
Assert.AreEqual(7, behaviour.oneBazValueB);
Assert.AreEqual(1, behaviour.twoFoo);
Assert.AreEqual(1, behaviour.twoBar);
Assert.AreEqual(1, behaviour.twoBaz);
Assert.AreEqual(8, behaviour.twoBarValue);
Assert.AreEqual(9, behaviour.twoBazValueA);
Assert.AreEqual(10, behaviour.twoBazValueB);
}
private class StateClass : MonoBehaviour
{
public int oneEnter;
public int oneFoo;
public int oneBar;
public int oneBaz;
public int oneExit;
public int oneBarValue;
public int oneBazValueA;
public int oneBazValueB;
public int twoEnter;
public int twoFoo;
public int twoBar;
public int twoBaz;
public int twoExit;
public int twoBarValue;
public int twoBazValueA;
public int twoBazValueB;
void One_Enter()
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Enter", Time.frameCount);
oneEnter++;
}
void One_Foo()
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Foo", Time.frameCount);
oneFoo++;
}
void One_Bar(int value)
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Bar", Time.frameCount);
oneBar++;
oneBarValue = value;
}
void One_Baz(int valueA, int valueB)
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Baz", Time.frameCount);
oneBaz++;
oneBazValueA = valueA;
oneBazValueB = valueB;
}
void One_Exit()
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Exit", Time.frameCount);
oneExit++;
}
void Two_Enter()
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Enter", Time.frameCount);
twoEnter++;
}
void Two_Foo()
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Foo", Time.frameCount);
twoFoo++;
}
void Two_Bar(int value)
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Bar", Time.frameCount);
twoBar++;
twoBarValue = value;
}
void Two_Baz(int valueA, int valueB)
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Baz", Time.frameCount);
twoBaz++;
twoBazValueA = valueA;
twoBazValueB = valueB;
}
void Two_Exit()
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Exit", Time.frameCount);
twoExit++;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9ac0e8e3b6264af6ad5122d174f3e4b5
timeCreated: 1567780312

View File

@@ -0,0 +1,60 @@
using System;
using MonsterLove.StateMachine;
using NUnit.Framework;
using UnityEngine;
using UnityEditor;
using System.Collections;
using Object = UnityEngine.Object;
[TestFixture]
[Category("State Machine Tests")]
internal class TestDerivedFromSuperClass
{
public enum States
{
One,
Two,
Three,
}
private GameObject go;
private ClassWithBasicStates behaviour;
private StateMachineRunner engine;
private StateMachine<States> fsm;
[SetUp]
public void Init()
{
go = new GameObject("stateTest");
behaviour = go.AddComponent<ClassDerivedFromSuperClass>();
engine = go.AddComponent<StateMachineRunner>();
}
[TearDown]
public void Kill()
{
Object.DestroyImmediate(go);
}
[Test]
public void InitialTransition()
{
fsm = engine.Initialize<States>(behaviour, States.One);
fsm.ChangeState(States.Two);
//Test for when we want to include superclass methods
Assert.AreEqual(1, behaviour.oneStats.enterCount);
Assert.AreEqual(0, behaviour.oneStats.updateCount);
Assert.AreEqual(0, behaviour.oneStats.lateUpdateCount);
Assert.AreEqual(1, behaviour.oneStats.exitCount);
Assert.AreEqual(1, behaviour.oneStats.finallyCount);
Assert.AreEqual(1, behaviour.twoStats.enterCount);
Assert.AreEqual(0, behaviour.twoStats.updateCount);
Assert.AreEqual(0, behaviour.twoStats.lateUpdateCount);
Assert.AreEqual(0, behaviour.twoStats.exitCount);
Assert.AreEqual(0, behaviour.twoStats.finallyCount);
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 61f4fd153167fd343a371f18957007dc
timeCreated: 1466595036
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,90 @@
using System;
using MonsterLove.StateMachine;
using NUnit.Framework;
using UnityEngine;
using UnityEditor;
using System.Collections;
using Object = UnityEngine.Object;
[TestFixture]
[Category("State Machine Tests")]
internal class TestDisabledComponent
{
public enum States
{
One,
Two,
Three,
}
private GameObject go;
private ClassWithBasicStates behaviour;
private StateMachineRunner engine;
private StateMachine<States> fsm;
[SetUp]
public void Init()
{
go = new GameObject("stateTest");
behaviour = go.AddComponent<ClassWithBasicStates>();
engine = go.AddComponent<StateMachineRunner>();
}
[TearDown]
public void Kill()
{
Object.DestroyImmediate(go);
}
[Test]
public void InitialTransition()
{
fsm = engine.Initialize<States>(behaviour, States.One);
fsm.ChangeState(States.Two);
Assert.AreEqual(1, behaviour.oneStats.enterCount);
Assert.AreEqual(0, behaviour.oneStats.updateCount);
Assert.AreEqual(0, behaviour.oneStats.lateUpdateCount);
Assert.AreEqual(1, behaviour.oneStats.exitCount);
Assert.AreEqual(1, behaviour.oneStats.finallyCount);
Assert.AreEqual(1, behaviour.twoStats.enterCount);
Assert.AreEqual(0, behaviour.twoStats.updateCount);
Assert.AreEqual(0, behaviour.twoStats.lateUpdateCount);
Assert.AreEqual(0, behaviour.twoStats.exitCount);
Assert.AreEqual(0, behaviour.twoStats.finallyCount);
Assert.AreEqual(0, behaviour.threeStats.enterCount);
Assert.AreEqual(0, behaviour.threeStats.updateCount);
Assert.AreEqual(0, behaviour.threeStats.lateUpdateCount);
Assert.AreEqual(0, behaviour.threeStats.exitCount);
Assert.AreEqual(0, behaviour.threeStats.finallyCount);
behaviour.enabled = false;
fsm.ChangeState(States.Three);
Assert.AreEqual(1, behaviour.oneStats.enterCount);
Assert.AreEqual(0, behaviour.oneStats.updateCount);
Assert.AreEqual(0, behaviour.oneStats.lateUpdateCount);
Assert.AreEqual(1, behaviour.oneStats.exitCount);
Assert.AreEqual(1, behaviour.oneStats.finallyCount);
Assert.AreEqual(1, behaviour.twoStats.enterCount);
Assert.AreEqual(0, behaviour.twoStats.updateCount);
Assert.AreEqual(0, behaviour.twoStats.lateUpdateCount);
Assert.AreEqual(1, behaviour.twoStats.exitCount);
Assert.AreEqual(1, behaviour.twoStats.finallyCount);
Assert.AreEqual(1, behaviour.threeStats.enterCount);
Assert.AreEqual(0, behaviour.threeStats.updateCount);
Assert.AreEqual(0, behaviour.threeStats.lateUpdateCount);
Assert.AreEqual(0, behaviour.threeStats.exitCount);
Assert.AreEqual(0, behaviour.threeStats.finallyCount);
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ee524972135f5c140a4a5a973cd64ce7
timeCreated: 1457610908
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,145 @@
using System.Collections;
using MonsterLove.StateMachine;
using NUnit.Framework;
using UnityEditor;
using UnityEngine;
using UnityEngine.PlayerLoop;
using UnityEngine.TestTools;
public class TestDriverLifecycle
{
public enum States
{
One,
Two,
Three,
Four,
}
public class Driver
{
public StateEvent Foo;
}
private GameObject go;
private StateClass behaviour;
private StateMachine<States, Driver> fsm;
[SetUp]
public void Init()
{
go = new GameObject();
behaviour = go.AddComponent<StateClass>();
fsm = new StateMachine<States, Driver>(behaviour);
}
[TearDown]
public void Kill()
{
Object.DestroyImmediate(go);
}
[Test]
public void TestDriverEventDoesntFireBeforeStateSet()
{
fsm.Driver.Foo.Invoke();
Assert.AreEqual(0, behaviour.oneFoo);
fsm.ChangeState(States.One);
fsm.Driver.Foo.Invoke();
Assert.AreEqual(1, behaviour.oneFoo);
}
private class StateClass : MonoBehaviour
{
public int oneEnter;
public int oneFoo;
public int oneBar;
public int oneBaz;
public int oneExit;
public int oneBarValue;
public int oneBazValueA;
public int oneBazValueB;
public int twoEnter;
public int twoFoo;
public int twoBar;
public int twoBaz;
public int twoExit;
public int twoBarValue;
public int twoBazValueA;
public int twoBazValueB;
void One_Enter()
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Enter", Time.frameCount);
oneEnter++;
}
void One_Foo()
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Foo", Time.frameCount);
oneFoo++;
}
void One_Bar(int value)
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Bar", Time.frameCount);
oneBar++;
oneBarValue = value;
}
void One_Baz(int valueA, int valueB)
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Baz", Time.frameCount);
oneBaz++;
oneBazValueA = valueA;
oneBazValueB = valueB;
}
void One_Exit()
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Exit", Time.frameCount);
oneExit++;
}
void Two_Enter()
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Enter", Time.frameCount);
twoEnter++;
}
void Two_Foo()
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Foo", Time.frameCount);
twoFoo++;
}
void Two_Bar(int value)
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Bar", Time.frameCount);
twoBar++;
twoBarValue = value;
}
void Two_Baz(int valueA, int valueB)
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Baz", Time.frameCount);
twoBaz++;
twoBazValueA = valueA;
twoBazValueB = valueB;
}
void Two_Exit()
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Exit", Time.frameCount);
twoExit++;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1ef0a3dffdbf4a6e8c8ff686a0b6efa3
timeCreated: 1616931919

View File

@@ -0,0 +1,147 @@
using MonsterLove.StateMachine;
using NUnit.Framework;
using UnityEngine;
public class TestEmptyDriver
{
public enum States
{
One,
Two,
Three,
Four,
}
public class Driver
{
}
private GameObject go;
private StateClass behaviour;
private StateMachine<States, Driver> fsm;
[SetUp]
public void Init()
{
go = new GameObject();
behaviour = go.AddComponent<StateClass>();
fsm = new StateMachine<States, Driver>(behaviour);
}
[TearDown]
public void Kill()
{
Object.DestroyImmediate(go);
}
[Test]
public void TestEmptyDriverUpdate()
{
fsm.ChangeState(States.One);
Assert.AreEqual(1, behaviour.oneEnter);
Assert.AreEqual(0, behaviour.oneExit);
Assert.AreEqual(0, behaviour.twoEnter);
Assert.AreEqual(0, behaviour.twoExit);
fsm.ChangeState(States.Two);
Assert.AreEqual(1, behaviour.oneEnter);
Assert.AreEqual(1, behaviour.oneExit);
Assert.AreEqual(1, behaviour.twoEnter);
Assert.AreEqual(0, behaviour.twoExit);
}
private class StateClass : MonoBehaviour
{
public int oneEnter;
public int oneFoo;
public int oneBar;
public int oneBaz;
public int oneExit;
public int oneBarValue;
public int oneBazValueA;
public int oneBazValueB;
public int twoEnter;
public int twoFoo;
public int twoBar;
public int twoBaz;
public int twoExit;
public int twoBarValue;
public int twoBazValueA;
public int twoBazValueB;
void One_Enter()
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Enter", Time.frameCount);
oneEnter++;
}
void One_Foo()
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Foo", Time.frameCount);
oneFoo++;
}
void One_Bar(int value)
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Bar", Time.frameCount);
oneBar++;
oneBarValue = value;
}
void One_Baz(int valueA, int valueB)
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Baz", Time.frameCount);
oneBaz++;
oneBazValueA = valueA;
oneBazValueB = valueB;
}
void One_Exit()
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Exit", Time.frameCount);
oneExit++;
}
void Two_Enter()
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Enter", Time.frameCount);
twoEnter++;
}
void Two_Foo()
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Foo", Time.frameCount);
twoFoo++;
}
void Two_Bar(int value)
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Bar", Time.frameCount);
twoBar++;
twoBarValue = value;
}
void Two_Baz(int valueA, int valueB)
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Baz", Time.frameCount);
twoBaz++;
twoBazValueA = valueA;
twoBazValueB = valueB;
}
void Two_Exit()
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Exit", Time.frameCount);
twoExit++;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d6391192757a422793fc48ab8a3fd5b7
timeCreated: 1568191151

View File

@@ -0,0 +1,129 @@
using MonsterLove.StateMachine;
using NUnit.Framework;
using UnityEngine;
public class TestInheritedDriver
{
public enum States
{
One,
Two,
Three,
Four,
}
public class Driver : StateDriverUnity
{
public StateEvent Foo;
}
private GameObject go;
private StateClass behaviour;
private StateMachine<States, Driver> fsm;
[SetUp]
public void Init()
{
go = new GameObject();
behaviour = go.AddComponent<StateClass>();
fsm = new StateMachine<States, Driver>(behaviour);
}
[TearDown]
public void Kill()
{
Object.DestroyImmediate(go);
}
[Test]
public void TestDriverNotNull()
{
Assert.NotNull(fsm.Driver);
}
[Test]
public void TestCustomEvents()
{
fsm.ChangeState(States.One);
fsm.Driver.Foo.Invoke();
fsm.Driver.Update.Invoke();
Assert.AreEqual(1, behaviour.oneFoo);
Assert.AreEqual(1, behaviour.oneUpdate);
Assert.AreEqual(0, behaviour.twoFoo);
Assert.AreEqual(0, behaviour.twoUpdate);
fsm.ChangeState(States.Two);
fsm.Driver.Foo.Invoke();
fsm.Driver.Update.Invoke();
Assert.AreEqual(1, behaviour.oneFoo);
Assert.AreEqual(1, behaviour.oneUpdate);
Assert.AreEqual(1, behaviour.twoFoo);
Assert.AreEqual(1, behaviour.twoUpdate);
}
private class StateClass : MonoBehaviour
{
public int oneEnter;
public int oneFoo;
public int oneUpdate;
public int oneExit;
public int twoEnter;
public int twoFoo;
public int twoUpdate;
public int twoExit;
void One_Enter()
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Enter", Time.frameCount);
oneEnter++;
}
void One_Foo()
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Foo", Time.frameCount);
oneFoo++;
}
void One_Update()
{
oneUpdate++;
}
void One_Exit()
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Exit", Time.frameCount);
oneExit++;
}
void Two_Enter()
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Enter", Time.frameCount);
twoEnter++;
}
void Two_Foo()
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Foo", Time.frameCount);
twoFoo++;
}
void Two_Update()
{
twoUpdate++;
}
void Two_Exit()
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Exit", Time.frameCount);
twoExit++;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7fe6b2aed376482ab4ab9842c0e791b3
timeCreated: 1568136312

View File

@@ -0,0 +1,81 @@
using System;
using MonsterLove.StateMachine;
using NUnit.Framework;
using UnityEngine;
using UnityEditor;
using System.Collections;
using Object = UnityEngine.Object;
[TestFixture]
[Category("State Machine Tests")]
internal class TestMultipleSubscribers
{
public enum States
{
One,
Two,
Three,
}
private GameObject go;
private ClassWithBasicStates behaviour1;
private ClassWithBasicStates behaviour2;
private ClassWithBasicStates behaviour3;
private StateMachineRunner engine;
private StateMachine<States> fsm;
[SetUp]
public void Init()
{
go = new GameObject("stateTest");
behaviour1 = go.AddComponent<ClassWithBasicStates>();
behaviour2 = go.AddComponent<ClassWithBasicStates>();
behaviour3 = go.AddComponent<ClassWithBasicStates>();
engine = go.AddComponent<StateMachineRunner>();
}
[TearDown]
public void Kill()
{
Object.DestroyImmediate(go);
}
[Test]
public void TestNoCrossTalk()
{
var fsm1 = engine.Initialize<States>(behaviour1, States.One);
var fsm2 = engine.Initialize<States>(behaviour2, States.Two);
var fsm3 = engine.Initialize<States>(behaviour3, States.One);
fsm2.ChangeState(States.Three);
fsm2.ChangeState(States.Two);
fsm3.ChangeState(States.Three);
Assert.AreEqual(1, behaviour1.oneStats.enterCount);
Assert.AreEqual(0, behaviour1.oneStats.exitCount);
Assert.AreEqual(0, behaviour1.twoStats.enterCount);
Assert.AreEqual(0, behaviour1.twoStats.exitCount);
Assert.AreEqual(0, behaviour1.threeStats.enterCount);
Assert.AreEqual(0, behaviour1.threeStats.exitCount);
Assert.AreEqual(0, behaviour2.oneStats.enterCount);
Assert.AreEqual(0, behaviour2.oneStats.exitCount);
Assert.AreEqual(2, behaviour2.twoStats.enterCount);
Assert.AreEqual(1, behaviour2.twoStats.exitCount);
Assert.AreEqual(1, behaviour2.threeStats.enterCount);
Assert.AreEqual(1, behaviour2.threeStats.exitCount);
Assert.AreEqual(1, behaviour3.oneStats.enterCount);
Assert.AreEqual(1, behaviour3.oneStats.exitCount);
Assert.AreEqual(0, behaviour3.twoStats.enterCount);
Assert.AreEqual(0, behaviour3.twoStats.exitCount);
Assert.AreEqual(1, behaviour3.threeStats.enterCount);
Assert.AreEqual(0, behaviour3.threeStats.exitCount);
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 871e6dc4ae40b964f999b5a2b4b88147
timeCreated: 1457534452
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections;
using MonsterLove.StateMachine;
using NUnit.Framework;
using UnityEditor;
using UnityEngine;
using UnityEngine.TestTools;
using Object = UnityEngine.Object;
public class TestNonStandardEnums
{
private enum StatesUlong : ulong
{
Foo = ulong.MaxValue,
}
private GameObject go;
private StateClass behaviour;
private StateMachine<StatesUlong, TestCachedDriver.Driver> fsm;
[SetUp]
public void Init()
{
go = new GameObject();
behaviour = go.AddComponent<StateClass>();
}
[TearDown]
public void Kill()
{
Object.DestroyImmediate(go);
}
[Test]
public void TestNonIntEnumErrors()
{
Assert.Catch(typeof(ArgumentException), () =>
{
fsm = new StateMachine<StatesUlong, TestCachedDriver.Driver>(behaviour);
});
}
private class StateClass : MonoBehaviour
{
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 58f27538abe6462f9ed6996603c5017b
timeCreated: 1616936058

View File

@@ -0,0 +1,109 @@
using System;
using MonsterLove.StateMachine;
using NUnit.Framework;
using UnityEngine;
using Object = UnityEngine.Object;
public class TestStateClassTypesMismatchDriver
{
public enum States
{
One,
Two,
Three,
Four,
}
public class Driver
{
public StateEvent Foo;
public StateEvent<int> Bar;
public StateEvent<int, int> Baz;
}
private GameObject go;
private StateClass behaviour;
private StateMachine<States, Driver> fsm;
[SetUp]
public void Init()
{
go = new GameObject();
behaviour = go.AddComponent<StateClass>();
}
[TearDown]
public void Kill()
{
Object.DestroyImmediate(go);
}
[Test]
public void TestMismatchedEvents()
{
Assert.Throws<ArgumentException>(() =>
new StateMachine<States, Driver>(behaviour)
);
}
private class StateClass : MonoBehaviour
{
public int oneEnter;
public int oneFoo;
public int oneBar;
public int oneBaz;
public int oneExit;
public int oneBarValue;
public int oneBazValueA;
public int oneBazValueB;
public int twoEnter;
public int twoExit;
void One_Enter()
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Enter", Time.frameCount);
oneEnter++;
}
void One_Baz()
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Foo", Time.frameCount);
oneFoo++;
}
void One_Foo(int value)
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Bar", Time.frameCount);
oneBar++;
oneBarValue = value;
}
void One_Bar(int valueA, int valueB)
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Baz", Time.frameCount);
oneBaz++;
oneBazValueA = valueA;
oneBazValueB = valueB;
}
void One_Exit()
{
//Debug.LogFormat("State:{0} Frame:{1}", "One Exit", Time.frameCount);
oneExit++;
}
void Two_Enter()
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Enter", Time.frameCount);
twoEnter++;
}
void Two_Exit()
{
//Debug.LogFormat("State:{0} Frame:{1}", "Two Exit", Time.frameCount);
twoExit++;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ac06595e9bcd40348af830ec6a29a7a5
timeCreated: 1568133089

View File

@@ -0,0 +1,101 @@
using System;
using MonsterLove.StateMachine;
using NUnit.Framework;
using UnityEngine;
using Object = UnityEngine.Object;
[TestFixture]
[Category("State Machine Tests")]
public class TestStateEngineInitialization
{
public enum TestStates
{
StateInit,
StatePlay,
StateEnd,
}
public enum TestNoDefines
{
}
private GameObject go;
private ClassWithBasicStates behaviour;
private StateMachineRunner engine;
[SetUp]
public void Init()
{
go = new GameObject("stateTest");
behaviour = go.AddComponent<ClassWithBasicStates>();
engine = go.AddComponent<StateMachineRunner>();
}
[TearDown]
public void Kill()
{
Object.DestroyImmediate(go);
}
[Test]
public void TestInitializedTwice()
{
//Should this throw an error? I'm not sure?
var fsm = engine.Initialize<TestStates>(behaviour);
fsm = engine.Initialize<TestStates>(behaviour);
}
[Test]
public void TestStatesDefined()
{
Assert.Throws<ArgumentException>(
() => { engine.Initialize<TestNoDefines>(behaviour); }
);
}
[Test]
public void TestStatePropBeforeChange()
{
var fsm = new StateMachine<TestStates, StateDriverUnity>(behaviour);
Assert.Throws<NullReferenceException>(() =>
{
TestStates state = fsm.State;
});
fsm.ChangeState(TestStates.StateInit);
Assert.AreEqual(TestStates.StateInit, fsm.State);
}
[Test]
public void TestLastStatePropBeforeChange()
{
var fsm = new StateMachine<TestStates, StateDriverUnity>(behaviour);
Assert.Throws<NullReferenceException>(() =>
{
TestStates state = fsm.LastState;
});
Assert.IsFalse(fsm.LastStateExists);
fsm.ChangeState(TestStates.StateInit);
//Conflicted about this. Prefer to return default values, or the current state
//but that would undermine correctness
Assert.Throws<NullReferenceException>(() =>
{
TestStates state = fsm.LastState;
});
Assert.IsFalse(fsm.LastStateExists);
fsm.ChangeState(TestStates.StatePlay);
Assert.AreEqual(TestStates.StateInit, fsm.LastState);
Assert.IsTrue(fsm.LastStateExists);
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d88daf46dc6100c44a16b31a04a34481
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData: