Browse Source

Merge pull request #474 from Pavelko007/master

extract ControlWithDisplay generic base class
master
Chris Gregan 9 years ago
parent
commit
ea95f8fd3e
  1. 40
      Assets/Fungus/Narrative/Scripts/Commands/ControlStage.cs
  2. 17
      Assets/Fungus/Narrative/Scripts/Commands/ControlWithDisplay.cs
  3. 12
      Assets/Fungus/Narrative/Scripts/Commands/ControlWithDisplay.cs.meta
  4. 36
      Assets/Fungus/Narrative/Scripts/Commands/Portrait.cs

40
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<StageDisplayType>
{
[Tooltip("Stage to display characters on")]
public Stage stage;
[Tooltip("Stage to swap with")]
@ -43,26 +40,27 @@ 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;
}
// Selected "use default Portrait Stage"
if (stage == null) // Default portrait stage selected
if (stage == null)
{
if (stage == null) // If no default specified, try to get any portrait stage in the scene
{
stage = GameObject.FindObjectOfType<Stage>();
}
}
// If portrait stage does not exist, do nothing
if (stage == null)
{
Continue();
return;
}
// If no default specified, try to get any portrait stage in the scene
stage = FindObjectOfType<Stage>();
// If portrait stage does not exist, do nothing
if (stage == null)
{
Continue();
return;
}
}
// Selected "use default Portrait Stage"
if (display == StageDisplayType.Swap) // Default portrait stage selected
{
@ -111,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;

17
Assets/Fungus/Narrative/Scripts/Commands/ControlWithDisplay.cs

@ -0,0 +1,17 @@
using System;
using UnityEngine;
namespace Fungus
{
public class ControlWithDisplay<TDisplayEnum> : Command
{
[Tooltip("Display type")]
public TDisplayEnum display;
protected bool IsDisplayNone<TEnum>(TEnum enumValue)
{
string displayTypeStr = Enum.GetName(typeof (TEnum), enumValue);
return displayTypeStr == "None";
}
}
}

12
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:

36
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<DisplayType>
{
[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;
@ -120,21 +117,18 @@ namespace Fungus
return;
}
// Selected "use default Portrait Stage"
if (stage == null) // Default portrait stage selected
{
if (stage == null) // If no default specified, try to get any portrait stage in the scene
{
stage = GameObject.FindObjectOfType<Stage>();
}
}
// If portrait stage does not exist, do nothing
if (stage == null)
{
Continue();
return;
}
// Selected "use default Portrait Stage"
if (stage == null)
{
// If no default specified, try to get any portrait stage in the scene
stage = FindObjectOfType<Stage>();
// If portrait stage does not exist, do nothing
if (stage == null)
{
Continue();
return;
}
}
// Early out if hiding a character that's already hidden
if (display == DisplayType.Hide &&

Loading…
Cancel
Save