From 977c2472a06ffd0732a47ad37b009364c3f0f57b Mon Sep 17 00:00:00 2001 From: Pavel Kvas Date: Sat, 14 May 2016 14:47:54 +0300 Subject: [PATCH] extract ControlWithDisplay generic base class --- .../Narrative/Scripts/Commands/ControlStage.cs | 15 ++++++--------- .../Scripts/Commands/ControlWithDisplay.cs | 17 +++++++++++++++++ .../Scripts/Commands/ControlWithDisplay.cs.meta | 12 ++++++++++++ .../Narrative/Scripts/Commands/Portrait.cs | 9 +++------ 4 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 Assets/Fungus/Narrative/Scripts/Commands/ControlWithDisplay.cs create mode 100644 Assets/Fungus/Narrative/Scripts/Commands/ControlWithDisplay.cs.meta diff --git a/Assets/Fungus/Narrative/Scripts/Commands/ControlStage.cs b/Assets/Fungus/Narrative/Scripts/Commands/ControlStage.cs index c1517fdb..7e525e99 100644 --- a/Assets/Fungus/Narrative/Scripts/Commands/ControlStage.cs +++ b/Assets/Fungus/Narrative/Scripts/Commands/ControlStage.cs @@ -21,12 +21,9 @@ namespace Fungus [CommandInfo("Narrative", "Control Stage", "Controls the stage on which character portraits are displayed.")] - public class ControlStage : Command - { - [Tooltip("Display type")] - public StageDisplayType display; - - [Tooltip("Stage to display characters on")] + public class ControlStage : ControlWithDisplay + { + [Tooltip("Stage to display characters on")] public Stage stage; [Tooltip("Stage to swap with")] @@ -43,8 +40,8 @@ namespace Fungus public override void OnEnter() { - // If no display specified, do nothing - if (display == StageDisplayType.None) + // If no display specified, do nothing + if (IsDisplayNone(display)) { Continue(); return; @@ -112,7 +109,7 @@ namespace Fungus } } - protected void Show(Stage stage, bool visible) + protected void Show(Stage stage, bool visible) { float duration = (fadeDuration == 0) ? float.Epsilon : fadeDuration; float targetAlpha = visible ? 1f : 0f; diff --git a/Assets/Fungus/Narrative/Scripts/Commands/ControlWithDisplay.cs b/Assets/Fungus/Narrative/Scripts/Commands/ControlWithDisplay.cs new file mode 100644 index 00000000..f428fa77 --- /dev/null +++ b/Assets/Fungus/Narrative/Scripts/Commands/ControlWithDisplay.cs @@ -0,0 +1,17 @@ +using System; +using UnityEngine; + +namespace Fungus +{ + public class ControlWithDisplay : Command + { + [Tooltip("Display type")] + public TDisplayEnum display; + + protected bool IsDisplayNone(TEnum enumValue) + { + string displayTypeStr = Enum.GetName(typeof (TEnum), enumValue); + return displayTypeStr == "None"; + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Narrative/Scripts/Commands/ControlWithDisplay.cs.meta b/Assets/Fungus/Narrative/Scripts/Commands/ControlWithDisplay.cs.meta new file mode 100644 index 00000000..7c07efb1 --- /dev/null +++ b/Assets/Fungus/Narrative/Scripts/Commands/ControlWithDisplay.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 6b4717bbde4a5e64893724b3db7eb32c +timeCreated: 1463225157 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Narrative/Scripts/Commands/Portrait.cs b/Assets/Fungus/Narrative/Scripts/Commands/Portrait.cs index 07c42ff6..e48938a0 100755 --- a/Assets/Fungus/Narrative/Scripts/Commands/Portrait.cs +++ b/Assets/Fungus/Narrative/Scripts/Commands/Portrait.cs @@ -44,14 +44,11 @@ namespace Fungus [CommandInfo("Narrative", "Portrait", "Controls a character portrait. ")] - public class Portrait : Command - { + public class Portrait : ControlWithDisplay + { [Tooltip("Stage to display portrait on")] public Stage stage; - [Tooltip("Display type")] - public DisplayType display; - [Tooltip("Character to display")] public Character character; @@ -100,7 +97,7 @@ namespace Fungus public override void OnEnter() { // If no display specified, do nothing - if (display == DisplayType.None) + if (IsDisplayNone(display)) { Continue(); return;