Chris Gregan
7 years ago
committed by
GitHub
15 changed files with 406 additions and 0 deletions
@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 61d2004f0aa3f1847beb167296c897d8 |
||||
folderAsset: yes |
||||
timeCreated: 1523180219 |
||||
licenseType: Free |
||||
DefaultImporter: |
||||
externalObjects: {} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
@ -0,0 +1,34 @@
|
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using UnityEngine; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
/// <summary> |
||||
/// Copy the value of the Priority Count to a local IntegerVariable, intended primarily to assist with debugging use of Priority. |
||||
/// </summary> |
||||
[CommandInfo("Priority Signals", |
||||
"Get Priority Count", |
||||
"Copy the value of the Priority Count to a local IntegerVariable, intended primarily to assist with debugging use of Priority.")] |
||||
public class FungusPriorityCount : Command |
||||
{ |
||||
[VariableProperty(typeof(IntegerVariable))] |
||||
public IntegerVariable outVar; |
||||
|
||||
public override void OnEnter() |
||||
{ |
||||
outVar.Value = FungusPrioritySignals.CurrentPriorityDepth; |
||||
|
||||
Continue(); |
||||
} |
||||
|
||||
public override string GetSummary() |
||||
{ |
||||
if(outVar == null) |
||||
{ |
||||
return "Error: No out var supplied"; |
||||
} |
||||
return outVar.Key; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2 |
||||
guid: a3aeb6a9bd739484080e7965ecaab89e |
||||
timeCreated: 1523926493 |
||||
licenseType: Free |
||||
MonoImporter: |
||||
externalObjects: {} |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
@ -0,0 +1,24 @@
|
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using UnityEngine; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
/// <summary> |
||||
/// Decrease the FungusPriority count, causing the related FungusPrioritySignals to fire. |
||||
/// Intended to be used to notify external systems that fungus is doing something important and they should perhaps resume. |
||||
/// </summary> |
||||
[CommandInfo("Priority Signals", |
||||
"Priority Down", |
||||
"Decrease the FungusPriority count, causing the related FungusPrioritySignals to fire. " + |
||||
"Intended to be used to notify external systems that fungus is doing something important and they should perhaps resume.")] |
||||
public class FungusPriorityDecrease : Command |
||||
{ |
||||
public override void OnEnter() |
||||
{ |
||||
FungusPrioritySignals.DoDecreasePriorityDepth(); |
||||
|
||||
Continue(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2 |
||||
guid: ebc295ba6aed8944fa3974a64f33cc42 |
||||
timeCreated: 1523926493 |
||||
licenseType: Free |
||||
MonoImporter: |
||||
externalObjects: {} |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
@ -0,0 +1,24 @@
|
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using UnityEngine; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
/// <summary> |
||||
/// Increases the FungusPriority count, causing the related FungusPrioritySignals to fire. |
||||
/// Intended to be used to notify external systems that fungus is doing something important and they should perhaps pause. |
||||
/// </summary> |
||||
[CommandInfo("Priority Signals", |
||||
"Priority Up", |
||||
"Increases the FungusPriority count, causing the related FungusPrioritySignals to fire. " + |
||||
"Intended to be used to notify external systems that fungus is doing something important and they should perhaps pause.")] |
||||
public class FungusPriorityIncrease : Command |
||||
{ |
||||
public override void OnEnter() |
||||
{ |
||||
FungusPrioritySignals.DoIncreasePriorityDepth(); |
||||
|
||||
Continue(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 3d07cf5e706b13a4eb0ae53386c30fbd |
||||
timeCreated: 1523926493 |
||||
licenseType: Free |
||||
MonoImporter: |
||||
externalObjects: {} |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
@ -0,0 +1,22 @@
|
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using UnityEngine; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
/// <summary> |
||||
/// Resets the FungusPriority count to zero. Useful if you are among logic that is hard to have matching increase and decreases. |
||||
/// </summary> |
||||
[CommandInfo("Priority Signals", |
||||
"Priority Reset", |
||||
"Resets the FungusPriority count to zero. Useful if you are among logic that is hard to have matching increase and decreases.")] |
||||
public class FungusPriorityReset : Command |
||||
{ |
||||
public override void OnEnter() |
||||
{ |
||||
FungusPrioritySignals.DoResetPriority(); |
||||
|
||||
Continue(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2 |
||||
guid: b5b98ba2a3006db49959601485049a0d |
||||
timeCreated: 1523926493 |
||||
licenseType: Free |
||||
MonoImporter: |
||||
externalObjects: {} |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
@ -0,0 +1,96 @@
|
||||
namespace Fungus |
||||
{ |
||||
/// <summary> |
||||
/// Fungus Priority event signalling system. |
||||
/// A common point for Fungus core systems and user Commands to signal to external code that a |
||||
/// Fungus system is currently doing something important. |
||||
/// |
||||
/// One intended use case for this system is to have your code listen to this to know when to |
||||
/// stop player movement or camera movement etc. when the player is engaged in a conversation |
||||
/// with an NPC. |
||||
/// </summary> |
||||
public static class FungusPrioritySignals |
||||
{ |
||||
#region Public members |
||||
/// <summary> |
||||
/// used by increase and decrease active depth functions. |
||||
/// </summary> |
||||
private static int activeDepth; |
||||
|
||||
public static int CurrentPriorityDepth |
||||
{ |
||||
get |
||||
{ |
||||
return activeDepth; |
||||
} |
||||
} |
||||
|
||||
public static event FungusPriorityStartHandler OnFungusPriorityStart; |
||||
public delegate void FungusPriorityStartHandler(); |
||||
|
||||
public static event FungusPriorityEndHandler OnFungusPriorityEnd; |
||||
public delegate void FungusPriorityEndHandler(); |
||||
|
||||
|
||||
public static event FungusPriorityChangeHandler OnFungusPriorityChange; |
||||
public delegate void FungusPriorityChangeHandler(int previousActiveDepth, int newActiveDepth); |
||||
|
||||
/// <summary> |
||||
/// Adds 1 to the theactiveDepth. If it was zero causes the OnFungusPriorityStart |
||||
/// </summary> |
||||
public static void DoIncreasePriorityDepth() |
||||
{ |
||||
if(activeDepth == 0) |
||||
{ |
||||
if (OnFungusPriorityStart != null) |
||||
{ |
||||
OnFungusPriorityStart(); |
||||
} |
||||
} |
||||
if(OnFungusPriorityChange != null) |
||||
{ |
||||
OnFungusPriorityChange(activeDepth, activeDepth + 1); |
||||
} |
||||
activeDepth++; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Subtracts 1 to the theactiveDepth. If it reaches zero causes the OnFungusPriorityEnd |
||||
/// </summary> |
||||
public static void DoDecreasePriorityDepth() |
||||
{ |
||||
if (OnFungusPriorityChange != null) |
||||
{ |
||||
OnFungusPriorityChange(activeDepth, activeDepth - 1); |
||||
} |
||||
if(activeDepth == 1) |
||||
{ |
||||
if(OnFungusPriorityEnd != null) |
||||
{ |
||||
OnFungusPriorityEnd(); |
||||
} |
||||
} |
||||
activeDepth--; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Forces active depth back to 0. If already 0 fires no signals. |
||||
/// </summary> |
||||
public static void DoResetPriority() |
||||
{ |
||||
if (activeDepth == 0) |
||||
return; |
||||
|
||||
if (OnFungusPriorityChange != null) |
||||
{ |
||||
OnFungusPriorityChange(activeDepth, 0); |
||||
} |
||||
if (OnFungusPriorityEnd != null) |
||||
{ |
||||
OnFungusPriorityEnd(); |
||||
} |
||||
activeDepth = 0; |
||||
} |
||||
#endregion |
||||
} |
||||
} |
@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2 |
||||
guid: fd542ada4b268ba49bcab2fd4d8e465e |
||||
timeCreated: 1523173334 |
||||
licenseType: Free |
||||
MonoImporter: |
||||
externalObjects: {} |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2 |
||||
guid: b38a1b95ff88ff34abb4a8a15679fdf5 |
||||
folderAsset: yes |
||||
timeCreated: 1523182215 |
||||
licenseType: Free |
||||
DefaultImporter: |
||||
externalObjects: {} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
@ -0,0 +1,89 @@
|
||||
using UnityEngine; |
||||
using UnityEditor; |
||||
using UnityEngine.TestTools; |
||||
using NUnit.Framework; |
||||
using System.Collections; |
||||
|
||||
public class FungusPrioritySignalsTest { |
||||
|
||||
private int changeCallCount, startCallCount, endCallCount; |
||||
|
||||
[Test] |
||||
public void CountsAndSignals() |
||||
{ |
||||
Fungus.FungusPrioritySignals.OnFungusPriorityStart += FungusPrioritySignals_OnFungusPriorityStart; |
||||
Fungus.FungusPrioritySignals.OnFungusPriorityEnd += FungusPrioritySignals_OnFungusPriorityEnd; |
||||
Fungus.FungusPrioritySignals.OnFungusPriorityChange += FungusPrioritySignals_OnFungusPriorityChange; |
||||
|
||||
Assert.Zero(Fungus.FungusPrioritySignals.CurrentPriorityDepth); |
||||
|
||||
Fungus.FungusPrioritySignals.DoIncreasePriorityDepth(); |
||||
//one start, one change, no end, 1 depth |
||||
Assert.AreEqual(0, endCallCount); |
||||
Assert.AreEqual(1, startCallCount); |
||||
Assert.AreEqual(1, changeCallCount); |
||||
Assert.AreEqual(1, Fungus.FungusPrioritySignals.CurrentPriorityDepth); |
||||
|
||||
|
||||
|
||||
Fungus.FungusPrioritySignals.DoIncreasePriorityDepth(); |
||||
//one start, 2 change, no end, 2 depth |
||||
Assert.AreEqual(0, endCallCount); |
||||
Assert.AreEqual(1, startCallCount); |
||||
Assert.AreEqual(2, changeCallCount); |
||||
Assert.AreEqual(2, Fungus.FungusPrioritySignals.CurrentPriorityDepth); |
||||
|
||||
|
||||
Fungus.FungusPrioritySignals.DoIncreasePriorityDepth(); |
||||
//one start, 3 change, no end, 3 depth |
||||
Assert.AreEqual(0, endCallCount); |
||||
Assert.AreEqual(1, startCallCount); |
||||
Assert.AreEqual(3, changeCallCount); |
||||
Assert.AreEqual(3, Fungus.FungusPrioritySignals.CurrentPriorityDepth); |
||||
|
||||
|
||||
Fungus.FungusPrioritySignals.DoDecreasePriorityDepth(); |
||||
//one start, 4 change, no end, 2 depth |
||||
Assert.AreEqual(0, endCallCount); |
||||
Assert.AreEqual(1, startCallCount); |
||||
Assert.AreEqual(4, changeCallCount); |
||||
Assert.AreEqual(2, Fungus.FungusPrioritySignals.CurrentPriorityDepth); |
||||
|
||||
|
||||
Fungus.FungusPrioritySignals.DoDecreasePriorityDepth(); |
||||
Fungus.FungusPrioritySignals.DoDecreasePriorityDepth(); |
||||
//one start, 6 change, 1 end, 0 depth |
||||
Assert.AreEqual(1, endCallCount); |
||||
Assert.AreEqual(1, startCallCount); |
||||
Assert.AreEqual(6, changeCallCount); |
||||
Assert.AreEqual(0, Fungus.FungusPrioritySignals.CurrentPriorityDepth); |
||||
|
||||
Fungus.FungusPrioritySignals.OnFungusPriorityStart -= FungusPrioritySignals_OnFungusPriorityStart; |
||||
Fungus.FungusPrioritySignals.OnFungusPriorityEnd -= FungusPrioritySignals_OnFungusPriorityEnd; |
||||
Fungus.FungusPrioritySignals.OnFungusPriorityChange -= FungusPrioritySignals_OnFungusPriorityChange; |
||||
|
||||
//unsubbed so all the same |
||||
Fungus.FungusPrioritySignals.DoIncreasePriorityDepth(); |
||||
Fungus.FungusPrioritySignals.DoDecreasePriorityDepth(); |
||||
//one start, 6 change, 1 end, 0 depth |
||||
Assert.AreEqual(1, endCallCount); |
||||
Assert.AreEqual(1, startCallCount); |
||||
Assert.AreEqual(6, changeCallCount); |
||||
Assert.AreEqual(0, Fungus.FungusPrioritySignals.CurrentPriorityDepth); |
||||
} |
||||
|
||||
private void FungusPrioritySignals_OnFungusPriorityChange(int previousActiveDepth, int newActiveDepth) |
||||
{ |
||||
changeCallCount++; |
||||
} |
||||
|
||||
private void FungusPrioritySignals_OnFungusPriorityEnd() |
||||
{ |
||||
endCallCount++; |
||||
} |
||||
|
||||
private void FungusPrioritySignals_OnFungusPriorityStart() |
||||
{ |
||||
startCallCount++; |
||||
} |
||||
} |
@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 4b20617e7666fda46bd85a41ce882f9d |
||||
timeCreated: 1523182238 |
||||
licenseType: Free |
||||
MonoImporter: |
||||
externalObjects: {} |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
@ -0,0 +1,19 @@
|
||||
# Priority Signals commands # {#priority signals_commands} |
||||
|
||||
[TOC] |
||||
# Get Priority Count # {#GetPriorityCount} |
||||
Copy the value of the Priority Count to a local IntegerVariable, intended primarily to assist with debugging use of Priority. |
||||
|
||||
Defined in Fungus.FungusPriorityCount |
||||
# Priority Down # {#PriorityDown} |
||||
Decrease the FungusPriority count, causing the related FungusPrioritySignals to fire. Intended to be used to notify external systems that fungus is doing something important and they should perhaps resume. |
||||
|
||||
Defined in Fungus.FungusPriorityDecrease |
||||
# Priority Reset # {#PriorityReset} |
||||
Resets the FungusPriority count to zero. Useful if you are among logic that is hard to have matching increase and decreases. |
||||
|
||||
Defined in Fungus.FungusPriorityReset |
||||
# Priority Up # {#PriorityUp} |
||||
Increases the FungusPriority count, causing the related FungusPrioritySignals to fire. Intended to be used to notify external systems that fungus is doing something important and they should perhaps pause. |
||||
|
||||
Defined in Fungus.FungusPriorityIncrease |
Loading…
Reference in new issue