From e968bfd507890bf4cc41fdf541eab6b77cd82362 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Thu, 11 Sep 2014 12:11:19 +0100 Subject: [PATCH] Refactored GetFungusScript() and GetSequence() --- Assets/Example/Scenes/Example.unity | Bin 128364 -> 123948 bytes Assets/Fungus/FungusScript/Commands/Else.cs | 8 ++- Assets/Fungus/FungusScript/Commands/If.cs | 8 ++- .../FungusScript/Editor/CommandEditor.cs | 9 ++- .../FungusScript/Editor/FungusScriptWindow.cs | 15 +++-- Assets/Fungus/FungusScript/Scripts/Command.cs | 60 +++++++++--------- .../Fungus/FungusScript/Scripts/Sequence.cs | 38 ++++------- 7 files changed, 72 insertions(+), 66 deletions(-) diff --git a/Assets/Example/Scenes/Example.unity b/Assets/Example/Scenes/Example.unity index 5b48b999957383ccff889271279cab429a2ea005..e2bf1d8b608baeffd4ec4709ade39d9ae6f460cf 100644 GIT binary patch delta 6614 zcmb{03tUuH9tZGq6k(Ky7a0v*j8P|?pvOd-SgDhuj4Kr?Dh3j$z^EW2qJn8NDi#UV z*fB3YvZ=LQHCM;5hFmi?F=xxnEmLYg>i8(F)s58MXv1}XXXaeIH*)**`7ED~GxMGE z{Gb0hGtDv6I2&Gf z5c_lC06LgGG}u7zWBJ|s(INOZhUH30^(QZOj3f0kmoc$Etyh7r{$yLn_j#PVEG#Wv zP{L};`UIjr+ZfH7$|RO&3}Me3lYV}C%$3nBH!-SX^gl?vX^T+yoH@Q@i|~7rc4hoz zbM1%1q*8nNtkSue1r_Clue>i`IlF7y6lS8A!il_CG2(wLCT(=@ zj*Hnh8vF2baW*5xmX90Iu?5e)uIUlf5Lm(O=}Gll&;R^BiSy8h{eE*#>`-v=@vrql zdh@jPPKZT%ADIwO2e20WYh=>Ic=lFe6dN|N2P=FcicOn1Fp$J&CjQ#<6#tlX<2?1~ zmYQFlkMm2&uRU0C^ybGYmj2p9)QA2bj!ykuxs~_dEXhOJrqpgc**fmqpEh+&+Z&hG zO*W~1>}#FUvJXu);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8!k<1Xcj~YW-LY;Vzi|J~ct?)yjr+;hnA~JFHUkl)RR+*K}jL|HvGL zS!WQk8ujsncsT}ZgJs}4KrIf^zSL_4J8KajQpG6HvPdSHjXB_Fsg> zuojqhah1RfR{w?hD69(Gn|6Jyf{{i34Zm04_2D>}1F;w!L?c32}|RxDp_PkO>y zVcH?g9c#>KhiRwD1}j|bU*BRL2h&c|lCchBPT3Owd9ow06{cex+X>TSF8S=sxLvR|7@y9s9AdcY zfF`W=BbvZ^m~O5AFHpaS)xwmU#l5?E+&cf)1{cf)%R+r}iub_yQ1R)MC%!9T&QfHc@mVZ>`$ z{^w!$^Vz2&tSE%a@-ss$|>@~+PKI355m*13K;V4*u~$3>2RZV z9lZrx4KpI{1Np1MyQx|0YJu56`8dA^<6Af%F4^z}m<48n$=_{$ckAs^7tE%)_ZgV( zasOnhU==Vv((*{Db^!HH$ZXUzq}1ECJ{fjGQ{j5p4VX5W4KOomt3#YztPWT^OuIhH zVAdzq_udc1@Na~=pr__e!y_;dzU}n_!zPR^s zSZbyJ>HP%E4a-6t7N#dLgT@7T9|VN z_3F93G)uh-*hh=iEBz&Eu5r;&=T~c~Q6W$JK5Ejd-=;Rwqv{oM33T3Uq({_`O)sNe z-jBnFX=Rvl<*9sw26R!st~w#|br$}C1~}VJ&|LM4aVM!&y{bDYtfpD^Exnoc|GDdd z&b$`Uh_kVU?pJTKoRT%youa0i3pB#{(J4B|>DtHtAM7;#;aPcBpQiC$)yulSP_wA@ z`Wf1!Ryi6R!t9RBvg#W5TTEU)*^R%&xvo4S7oaq;6va|dGot97*IoW!1(>+)y;?I%E zxR}U4@OQ(); - foreach (Command command in commands) + foreach (Command command in sequence.commandList) { bool commandIsSelected = (fungusScript.selectedCommand == command); diff --git a/Assets/Fungus/FungusScript/Scripts/Command.cs b/Assets/Fungus/FungusScript/Scripts/Command.cs index 70210d96..2986244b 100644 --- a/Assets/Fungus/FungusScript/Scripts/Command.cs +++ b/Assets/Fungus/FungusScript/Scripts/Command.cs @@ -24,51 +24,37 @@ namespace Fungus } [RequireComponent(typeof(Sequence))] - public class Command : MonoBehaviour + public class Command : MonoBehaviour { - [HideInInspector] public string errorMessage = ""; - [HideInInspector] - public FungusScript parentFungusScript; - - [HideInInspector] - public Sequence parentSequence; - - [HideInInspector] public int indentLevel; - public virtual void Start() + public Sequence GetSequence() { - parentSequence = GetComponent(); - parentFungusScript = GetFungusScript(); + return gameObject.GetComponent(); } public FungusScript GetFungusScript() { - FungusScript sc = null; - - Transform parent = transform.parent; - while (parent != null) + Sequence s = GetSequence(); + if (s == null) { - sc = parent.gameObject.GetComponent(); - if (sc != null) - { - break; - } - parent = parent.transform.parent; + return null; } - return sc; + + return s.GetFungusScript(); } public bool IsExecuting() { - if (parentSequence == null) + Sequence sequence = GetSequence(); + if (sequence == null) { return false; } - return (parentSequence.activeCommand == this); + return (sequence.activeCommand == this); } public virtual void Execute() @@ -84,20 +70,36 @@ namespace Fungus public virtual void Continue(Command currentCommand) { OnExit(); - parentSequence.ExecuteNextCommand(currentCommand); + Sequence sequence = GetSequence(); + if (sequence != null) + { + sequence.ExecuteNextCommand(currentCommand); + } } public virtual void Stop() { OnExit(); - parentSequence.Stop(); + Sequence sequence = GetSequence(); + if (sequence != null) + { + sequence.Stop(); + } } public virtual void ExecuteSequence(Sequence s) { OnExit(); - parentSequence.Stop(); - parentFungusScript.ExecuteSequence(s); + Sequence sequence = GetSequence(); + if (sequence != null) + { + sequence.Stop(); + FungusScript fungusScript = sequence.GetFungusScript(); + if (fungusScript != null) + { + fungusScript.ExecuteSequence(s); + } + } } public virtual void OnEnter() diff --git a/Assets/Fungus/FungusScript/Scripts/Sequence.cs b/Assets/Fungus/FungusScript/Scripts/Sequence.cs index e4ee5700..e4c1b66e 100644 --- a/Assets/Fungus/FungusScript/Scripts/Sequence.cs +++ b/Assets/Fungus/FungusScript/Scripts/Sequence.cs @@ -12,18 +12,12 @@ namespace Fungus [ExecuteInEditMode] public class Sequence : MonoBehaviour { - [HideInInspector] public Rect nodeRect = new Rect(10, 10, 100, 40); - [HideInInspector] public string sequenceName = "Sequence"; - [HideInInspector] public string description = ""; - [System.NonSerialized] - public FungusScript fungusScript; - [System.NonSerialized] public Command activeCommand; @@ -31,25 +25,9 @@ namespace Fungus int executionCount; - public virtual void Start() - { - fungusScript = GetFungusScript(); - } - public FungusScript GetFungusScript() { - FungusScript sc = null; - Transform parent = transform.parent; - while (parent != null) - { - sc = parent.gameObject.GetComponent(); - - if (sc != null) - { - break; - } - } - return sc; + return GetComponentInParent(); } public bool HasError() @@ -67,6 +45,8 @@ namespace Fungus public bool IsRunning() { + FungusScript fungusScript = GetFungusScript(); + if (fungusScript == null || fungusScript.executingSequence == null) { @@ -114,14 +94,16 @@ namespace Fungus } else { - if (GetFungusScript().stepTime == 0f) + FungusScript fungusScript = GetFungusScript(); + + if (fungusScript.stepTime == 0f) { activeCommand = nextCommand; nextCommand.Execute(); } else { - StartCoroutine(ExecuteAfterDelay(nextCommand, GetFungusScript().stepTime)); + StartCoroutine(ExecuteAfterDelay(nextCommand, fungusScript.stepTime)); } } @@ -136,6 +118,12 @@ namespace Fungus public void Stop() { + FungusScript fungusScript = GetFungusScript(); + if (fungusScript == null) + { + return; + } + activeCommand = null; fungusScript.executingSequence = null; fungusScript.selectedSequence = null;