Browse Source

Merge pull request #474 from Pavelko007/master

extract ControlWithDisplay generic base class
master
Chris Gregan 9 years ago
parent
commit
ea95f8fd3e
  1. 20
      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. 18
      Assets/Fungus/Narrative/Scripts/Commands/Portrait.cs

20
Assets/Fungus/Narrative/Scripts/Commands/ControlStage.cs

@ -21,11 +21,8 @@ namespace Fungus
[CommandInfo("Narrative",
"Control Stage",
"Controls the stage on which character portraits are displayed.")]
public class ControlStage : Command
public class ControlStage : ControlWithDisplay<StageDisplayType>
{
[Tooltip("Display type")]
public StageDisplayType display;
[Tooltip("Stage to display characters on")]
public Stage stage;
@ -44,25 +41,26 @@ namespace Fungus
public override void OnEnter()
{
// If no display specified, do nothing
if (display == StageDisplayType.None)
if (IsDisplayNone(display))
{
Continue();
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
if (stage == null)
{
stage = GameObject.FindObjectOfType<Stage>();
}
}
// 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
{

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:

18
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;
@ -121,19 +118,16 @@ namespace Fungus
}
// 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
if (stage == null)
{
stage = GameObject.FindObjectOfType<Stage>();
}
}
// 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

Loading…
Cancel
Save