Skip to content
Snippets Groups Projects
Commit 7006e233 authored by Heine, Eric R's avatar Heine, Eric R
Browse files

Made the variable labels able to have their output strings formatted as desired.

parent 19643572
No related branches found
No related tags found
No related merge requests found
Showing with 44 additions and 28 deletions
......@@ -4,7 +4,7 @@ using Shared.ScriptableVariables;
namespace Shared.SEUI {
// Read only UI for a BooleanVariable
// Depends on ScriptableVariable package
public class BooleanVariableLabel : ScriptableVariableLabel {
public class BooleanVariableLabel : ScriptableVariableLabel<bool> {
[Tooltip("The variable whose value we are displaying")]
public BooleanVariable value;
......@@ -14,8 +14,8 @@ namespace Shared.SEUI {
}
//---------------------------------------------------------------------------
protected override string GetValueString() {
return value.Value.ToString();
protected override bool GetValue() {
return value.Value;
}
}
}
......@@ -4,7 +4,7 @@ using Shared.ScriptableVariables;
namespace Shared.SEUI {
// Read only UI for a FloatVariable
// Depends on ScriptableVariable package
public class FloatVariableLabel : ScriptableVariableLabel {
public class FloatVariableLabel : ScriptableVariableLabel<float> {
[Tooltip("The variable whose value we are displaying")]
public FloatVariable value;
......@@ -14,8 +14,8 @@ namespace Shared.SEUI {
}
//---------------------------------------------------------------------------
protected override string GetValueString() {
return value.Value.ToString();
protected override float GetValue() {
return value.Value;
}
}
}
......@@ -4,7 +4,7 @@ using Shared.ScriptableVariables;
namespace Shared.SEUI {
// Read only UI for an IntVariable
// Depends on ScriptableVariable package
public class IntVariableLabel : ScriptableVariableLabel {
public class IntVariableLabel : ScriptableVariableLabel<int> {
[Tooltip("The variable whose value we are displaying")]
public IntVariable value;
......@@ -14,8 +14,8 @@ namespace Shared.SEUI {
}
//---------------------------------------------------------------------------
protected override string GetValueString() {
return value.Value.ToString();
protected override int GetValue() {
return value.Value;
}
}
}
......@@ -4,7 +4,7 @@ using Shared.ScriptableVariables;
namespace Shared.SEUI {
// Read only UI for a ReferenceBooleanVariable
// Depends on ScriptableVariable package
public class ReferenceBooleanVariableLabel : ScriptableVariableLabel {
public class ReferenceBooleanVariableLabel : ScriptableVariableLabel<bool> {
[Tooltip("The variable whose value we are displaying")]
public ReferenceBooleanVariable value;
......@@ -14,8 +14,8 @@ namespace Shared.SEUI {
}
//---------------------------------------------------------------------------
protected override string GetValueString() {
return value.Value.ToString();
protected override bool GetValue() {
return value.Value;
}
}
}
......@@ -4,7 +4,7 @@ using Shared.ScriptableVariables;
namespace Shared.SEUI {
// Read only UI for a ReferenceFloatVariable
// Depends on ScriptableVariable package
public class ReferenceFloatVariableLabel : ScriptableVariableLabel {
public class ReferenceFloatVariableLabel : ScriptableVariableLabel<float> {
[Tooltip("The variable whose value we are displaying")]
public ReferenceFloatVariable value;
......@@ -14,8 +14,8 @@ namespace Shared.SEUI {
}
//---------------------------------------------------------------------------
protected override string GetValueString() {
return value.Value.ToString();
protected override float GetValue() {
return value.Value;
}
}
}
......@@ -4,7 +4,7 @@ using Shared.ScriptableVariables;
namespace Shared.SEUI {
// Read only UI for a ReferenceIntVariable
// Depends on ScriptableVariable package
public class ReferenceIntVariableLabel : ScriptableVariableLabel {
public class ReferenceIntVariableLabel : ScriptableVariableLabel<int> {
[Tooltip("The variable whose value we are displaying")]
public ReferenceIntVariable value;
......@@ -14,8 +14,8 @@ namespace Shared.SEUI {
}
//---------------------------------------------------------------------------
protected override string GetValueString() {
return value.Value.ToString();
protected override int GetValue() {
return value.Value;
}
}
}
......@@ -4,7 +4,7 @@ using Shared.ScriptableVariables;
namespace Shared.SEUI {
// Read only UI for a ReferenceStringVariable
// Depends on ScriptableVariable package
public class ReferenceStringVariableLabel : ScriptableVariableLabel {
public class ReferenceStringVariableLabel : ScriptableVariableLabel<string> {
[Tooltip("The variable whose value we are displaying")]
public ReferenceStringVariable value;
......@@ -14,8 +14,8 @@ namespace Shared.SEUI {
}
//---------------------------------------------------------------------------
protected override string GetValueString() {
return value.Value.ToString();
protected override string GetValue() {
return value.Value;
}
}
}
using UnityEngine;
using System;
using UnityEngine;
using UnityEngine.UI;
namespace Shared.SEUI {
// Base class for read only UI for a ScriptableVariable
public abstract class ScriptableVariableLabel : MonoBehaviour {
public abstract class ScriptableVariableLabel<T> : MonoBehaviour {
[Tooltip("The optional Text where we are putting the variable's name")]
public Text nameLabel;
[Tooltip("The optional Text where we are putting the variable's value")]
public Text valueLabel;
[Tooltip("The C# String.Format() string for displaying the value")]
public string format;
//---------------------------------------------------------------------------
void Start() {
if (nameLabel != null) {
......@@ -37,6 +41,16 @@ namespace Shared.SEUI {
//---------------------------------------------------------------------------
// Implement with how to get the ScriptableVariable's value
protected abstract string GetValueString();
protected abstract T GetValue();
//---------------------------------------------------------------------------
// Format the current value into a string
private string GetValueString() {
var value = GetValue();
if (String.IsNullOrEmpty(format)) {
return value.ToString();
}
return String.Format(format, value);
}
}
}
using UnityEngine;
using System;
using UnityEngine;
using Shared.ScriptableVariables;
namespace Shared.SEUI {
// Read only UI for a StringVariable
// Depends on ScriptableVariable package
public class StringVariableLabel : ScriptableVariableLabel {
public class StringVariableLabel : ScriptableVariableLabel<string> {
[Tooltip("The variable whose value we are displaying")]
public StringVariable value;
......@@ -13,8 +14,9 @@ namespace Shared.SEUI {
return value.name;
}
//---------------------------------------------------------------------------
protected override string GetValueString() {
protected override string GetValue() {
return value.Value;
}
}
......
......@@ -2,7 +2,7 @@
"name": "com.futuretech.shared",
"displayName": "FutureTech Shared",
"description": "Contains shared items such as the Scriptable Variables.",
"version": "0.1.15",
"version": "0.1.16",
"unity": "2018.3",
"license": "MIT",
"repository": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment