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
Tags 0.1.16
No related merge requests found
Showing with 44 additions and 28 deletions
...@@ -4,7 +4,7 @@ using Shared.ScriptableVariables; ...@@ -4,7 +4,7 @@ using Shared.ScriptableVariables;
namespace Shared.SEUI { namespace Shared.SEUI {
// Read only UI for a BooleanVariable // Read only UI for a BooleanVariable
// Depends on ScriptableVariable package // Depends on ScriptableVariable package
public class BooleanVariableLabel : ScriptableVariableLabel { public class BooleanVariableLabel : ScriptableVariableLabel<bool> {
[Tooltip("The variable whose value we are displaying")] [Tooltip("The variable whose value we are displaying")]
public BooleanVariable value; public BooleanVariable value;
...@@ -14,8 +14,8 @@ namespace Shared.SEUI { ...@@ -14,8 +14,8 @@ namespace Shared.SEUI {
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
protected override string GetValueString() { protected override bool GetValue() {
return value.Value.ToString(); return value.Value;
} }
} }
} }
...@@ -4,7 +4,7 @@ using Shared.ScriptableVariables; ...@@ -4,7 +4,7 @@ using Shared.ScriptableVariables;
namespace Shared.SEUI { namespace Shared.SEUI {
// Read only UI for a FloatVariable // Read only UI for a FloatVariable
// Depends on ScriptableVariable package // Depends on ScriptableVariable package
public class FloatVariableLabel : ScriptableVariableLabel { public class FloatVariableLabel : ScriptableVariableLabel<float> {
[Tooltip("The variable whose value we are displaying")] [Tooltip("The variable whose value we are displaying")]
public FloatVariable value; public FloatVariable value;
...@@ -14,8 +14,8 @@ namespace Shared.SEUI { ...@@ -14,8 +14,8 @@ namespace Shared.SEUI {
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
protected override string GetValueString() { protected override float GetValue() {
return value.Value.ToString(); return value.Value;
} }
} }
} }
...@@ -4,7 +4,7 @@ using Shared.ScriptableVariables; ...@@ -4,7 +4,7 @@ using Shared.ScriptableVariables;
namespace Shared.SEUI { namespace Shared.SEUI {
// Read only UI for an IntVariable // Read only UI for an IntVariable
// Depends on ScriptableVariable package // Depends on ScriptableVariable package
public class IntVariableLabel : ScriptableVariableLabel { public class IntVariableLabel : ScriptableVariableLabel<int> {
[Tooltip("The variable whose value we are displaying")] [Tooltip("The variable whose value we are displaying")]
public IntVariable value; public IntVariable value;
...@@ -14,8 +14,8 @@ namespace Shared.SEUI { ...@@ -14,8 +14,8 @@ namespace Shared.SEUI {
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
protected override string GetValueString() { protected override int GetValue() {
return value.Value.ToString(); return value.Value;
} }
} }
} }
...@@ -4,7 +4,7 @@ using Shared.ScriptableVariables; ...@@ -4,7 +4,7 @@ using Shared.ScriptableVariables;
namespace Shared.SEUI { namespace Shared.SEUI {
// Read only UI for a ReferenceBooleanVariable // Read only UI for a ReferenceBooleanVariable
// Depends on ScriptableVariable package // Depends on ScriptableVariable package
public class ReferenceBooleanVariableLabel : ScriptableVariableLabel { public class ReferenceBooleanVariableLabel : ScriptableVariableLabel<bool> {
[Tooltip("The variable whose value we are displaying")] [Tooltip("The variable whose value we are displaying")]
public ReferenceBooleanVariable value; public ReferenceBooleanVariable value;
...@@ -14,8 +14,8 @@ namespace Shared.SEUI { ...@@ -14,8 +14,8 @@ namespace Shared.SEUI {
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
protected override string GetValueString() { protected override bool GetValue() {
return value.Value.ToString(); return value.Value;
} }
} }
} }
...@@ -4,7 +4,7 @@ using Shared.ScriptableVariables; ...@@ -4,7 +4,7 @@ using Shared.ScriptableVariables;
namespace Shared.SEUI { namespace Shared.SEUI {
// Read only UI for a ReferenceFloatVariable // Read only UI for a ReferenceFloatVariable
// Depends on ScriptableVariable package // Depends on ScriptableVariable package
public class ReferenceFloatVariableLabel : ScriptableVariableLabel { public class ReferenceFloatVariableLabel : ScriptableVariableLabel<float> {
[Tooltip("The variable whose value we are displaying")] [Tooltip("The variable whose value we are displaying")]
public ReferenceFloatVariable value; public ReferenceFloatVariable value;
...@@ -14,8 +14,8 @@ namespace Shared.SEUI { ...@@ -14,8 +14,8 @@ namespace Shared.SEUI {
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
protected override string GetValueString() { protected override float GetValue() {
return value.Value.ToString(); return value.Value;
} }
} }
} }
...@@ -4,7 +4,7 @@ using Shared.ScriptableVariables; ...@@ -4,7 +4,7 @@ using Shared.ScriptableVariables;
namespace Shared.SEUI { namespace Shared.SEUI {
// Read only UI for a ReferenceIntVariable // Read only UI for a ReferenceIntVariable
// Depends on ScriptableVariable package // Depends on ScriptableVariable package
public class ReferenceIntVariableLabel : ScriptableVariableLabel { public class ReferenceIntVariableLabel : ScriptableVariableLabel<int> {
[Tooltip("The variable whose value we are displaying")] [Tooltip("The variable whose value we are displaying")]
public ReferenceIntVariable value; public ReferenceIntVariable value;
...@@ -14,8 +14,8 @@ namespace Shared.SEUI { ...@@ -14,8 +14,8 @@ namespace Shared.SEUI {
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
protected override string GetValueString() { protected override int GetValue() {
return value.Value.ToString(); return value.Value;
} }
} }
} }
...@@ -4,7 +4,7 @@ using Shared.ScriptableVariables; ...@@ -4,7 +4,7 @@ using Shared.ScriptableVariables;
namespace Shared.SEUI { namespace Shared.SEUI {
// Read only UI for a ReferenceStringVariable // Read only UI for a ReferenceStringVariable
// Depends on ScriptableVariable package // Depends on ScriptableVariable package
public class ReferenceStringVariableLabel : ScriptableVariableLabel { public class ReferenceStringVariableLabel : ScriptableVariableLabel<string> {
[Tooltip("The variable whose value we are displaying")] [Tooltip("The variable whose value we are displaying")]
public ReferenceStringVariable value; public ReferenceStringVariable value;
...@@ -14,8 +14,8 @@ namespace Shared.SEUI { ...@@ -14,8 +14,8 @@ namespace Shared.SEUI {
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
protected override string GetValueString() { protected override string GetValue() {
return value.Value.ToString(); return value.Value;
} }
} }
} }
using UnityEngine; using System;
using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
namespace Shared.SEUI { namespace Shared.SEUI {
// Base class for read only UI for a ScriptableVariable // 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")] [Tooltip("The optional Text where we are putting the variable's name")]
public Text nameLabel; public Text nameLabel;
[Tooltip("The optional Text where we are putting the variable's value")] [Tooltip("The optional Text where we are putting the variable's value")]
public Text valueLabel; public Text valueLabel;
[Tooltip("The C# String.Format() string for displaying the value")]
public string format;
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void Start() { void Start() {
if (nameLabel != null) { if (nameLabel != null) {
...@@ -37,6 +41,16 @@ namespace Shared.SEUI { ...@@ -37,6 +41,16 @@ namespace Shared.SEUI {
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Implement with how to get the ScriptableVariable's value // 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; using Shared.ScriptableVariables;
namespace Shared.SEUI { namespace Shared.SEUI {
// Read only UI for a StringVariable // Read only UI for a StringVariable
// Depends on ScriptableVariable package // Depends on ScriptableVariable package
public class StringVariableLabel : ScriptableVariableLabel { public class StringVariableLabel : ScriptableVariableLabel<string> {
[Tooltip("The variable whose value we are displaying")] [Tooltip("The variable whose value we are displaying")]
public StringVariable value; public StringVariable value;
...@@ -13,8 +14,9 @@ namespace Shared.SEUI { ...@@ -13,8 +14,9 @@ namespace Shared.SEUI {
return value.name; return value.name;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
protected override string GetValueString() { protected override string GetValue() {
return value.Value; return value.Value;
} }
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"name": "com.futuretech.shared", "name": "com.futuretech.shared",
"displayName": "FutureTech Shared", "displayName": "FutureTech Shared",
"description": "Contains shared items such as the Scriptable Variables.", "description": "Contains shared items such as the Scriptable Variables.",
"version": "0.1.15", "version": "0.1.16",
"unity": "2018.3", "unity": "2018.3",
"license": "MIT", "license": "MIT",
"repository": { "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