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

Added UI, variables, events, and listeners for Vector2, 3, and 4 values.

parent e84203b1
No related branches found
No related tags found
No related merge requests found
Showing
with 644 additions and 0 deletions
using System;
using UnityEngine;
using UnityEngine.Events;
using TMPro;
using Shared.ScriptableVariables;
namespace Shared.SEUI {
// UI Editor for a Vector2Variable
// Depends on ScriptableVariable package
public class Vector2VariableInput : ScriptableVariableInput<Vector2> {
[Tooltip("The variable we are editing")]
public Vector2Variable variable;
[Tooltip("The input UI to edit the variable's x value with")]
public TMP_InputField xInput;
[Tooltip("The input UI to edit the variable's y value with")]
public TMP_InputField yInput;
// Temporary callbackx to bridge value changes in the UI and the variable
private UnityAction<string> xValueConverter;
private UnityAction<string> yValueConverter;
//---------------------------------------------------------------------------
void Start() {
// Make sure the input handles the right content type
xInput.contentType = TMP_InputField.ContentType.DecimalNumber;
yInput.contentType = TMP_InputField.ContentType.DecimalNumber;
}
//---------------------------------------------------------------------------
protected override void AddUIListener(UnityAction<Vector2> callback) {
// Define the value converting bridge callback to add to the UI listener
xValueConverter = delegate(string value) {
callback(new Vector2(StringToFloat(value), variable.Value.y));
};
yValueConverter = delegate(string value) {
callback(new Vector2(variable.Value.x, StringToFloat(value)));
};
xInput.onValueChanged.AddListener(xValueConverter);
yInput.onValueChanged.AddListener(yValueConverter);
}
//---------------------------------------------------------------------------
protected override void RemoveUIListener(UnityAction<Vector2> callback) {
if (xValueConverter != null) {
xInput.onValueChanged.RemoveListener(xValueConverter);
xValueConverter = null;
}
if (yValueConverter != null) {
yInput.onValueChanged.RemoveListener(yValueConverter);
yValueConverter = null;
}
}
//---------------------------------------------------------------------------
protected override bool DoValuesMatch() {
return !String.IsNullOrEmpty(xInput.text) && Convert.ToSingle(xInput.text) == variable.Value.x &&
!String.IsNullOrEmpty(yInput.text) && Convert.ToSingle(yInput.text) == variable.Value.y;
}
//---------------------------------------------------------------------------
protected override void UpdateUIValue() {
xInput.SetTextWithoutNotify(variable.Value.x.ToString());
yInput.SetTextWithoutNotify(variable.Value.y.ToString());
}
//---------------------------------------------------------------------------
protected override void UpdateVariableValue(Vector2 value) {
variable.Value = value;
}
//---------------------------------------------------------------------------
private float StringToFloat(string value) {
if (!String.IsNullOrEmpty(xInput.text)) {
return Convert.ToSingle(value);
}
return 0.0f;
}
}
}
fileFormatVersion: 2
guid: 62a6de5a919aefe42bd6f5ac8c5eb4bd
timeCreated: 1510784910
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using Shared.ScriptableVariables;
namespace Shared.SEUI {
// Read only UI for a Vector2Variable
// Depends on ScriptableVariable package
public class Vector2VariableLabel : ScriptableVariableLabel<Vector2> {
[Tooltip("The variable whose value we are displaying")]
public Vector2Variable value;
//---------------------------------------------------------------------------
protected override string GetName() {
return value.name;
}
//---------------------------------------------------------------------------
protected override Vector2 GetValue() {
return value.Value;
}
}
}
fileFormatVersion: 2
guid: 19ff1aa3c5bfbae4189e9d7e9cdb8fbe
timeCreated: 1510784910
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using UnityEngine;
using UnityEngine.Events;
using TMPro;
using Shared.ScriptableVariables;
namespace Shared.SEUI {
// UI Editor for a Vector3Variable
// Depends on ScriptableVariable package
public class Vector3VariableInput : ScriptableVariableInput<Vector3> {
[Tooltip("The variable we are editing")]
public Vector3Variable variable;
[Tooltip("The input UI to edit the variable's x value with")]
public TMP_InputField xInput;
[Tooltip("The input UI to edit the variable's y value with")]
public TMP_InputField yInput;
[Tooltip("The input UI to edit the variable's z value with")]
public TMP_InputField zInput;
// Temporary callbackx to bridge value changes in the UI and the variable
private UnityAction<string> xValueConverter;
private UnityAction<string> yValueConverter;
private UnityAction<string> zValueConverter;
//---------------------------------------------------------------------------
void Start() {
// Make sure the input handles the right content type
xInput.contentType = TMP_InputField.ContentType.DecimalNumber;
yInput.contentType = TMP_InputField.ContentType.DecimalNumber;
zInput.contentType = TMP_InputField.ContentType.DecimalNumber;
}
//---------------------------------------------------------------------------
protected override void AddUIListener(UnityAction<Vector3> callback) {
// Define the value converting bridge callback to add to the UI listener
xValueConverter = delegate(string value) {
callback(new Vector3(StringToFloat(value), variable.Value.y, variable.Value.z));
};
yValueConverter = delegate(string value) {
callback(new Vector3(variable.Value.x, StringToFloat(value), variable.Value.z));
};
zValueConverter = delegate(string value) {
callback(new Vector3(variable.Value.x, variable.Value.y, StringToFloat(value)));
};
xInput.onValueChanged.AddListener(xValueConverter);
yInput.onValueChanged.AddListener(yValueConverter);
zInput.onValueChanged.AddListener(zValueConverter);
}
//---------------------------------------------------------------------------
protected override void RemoveUIListener(UnityAction<Vector3> callback) {
if (xValueConverter != null) {
xInput.onValueChanged.RemoveListener(xValueConverter);
xValueConverter = null;
}
if (yValueConverter != null) {
yInput.onValueChanged.RemoveListener(yValueConverter);
yValueConverter = null;
}
if (zValueConverter != null) {
zInput.onValueChanged.RemoveListener(zValueConverter);
zValueConverter = null;
}
}
//---------------------------------------------------------------------------
protected override bool DoValuesMatch() {
return !String.IsNullOrEmpty(xInput.text) && Convert.ToSingle(xInput.text) == variable.Value.x &&
!String.IsNullOrEmpty(yInput.text) && Convert.ToSingle(yInput.text) == variable.Value.y &&
!String.IsNullOrEmpty(zInput.text) && Convert.ToSingle(zInput.text) == variable.Value.z;
}
//---------------------------------------------------------------------------
protected override void UpdateUIValue() {
xInput.SetTextWithoutNotify(variable.Value.x.ToString());
yInput.SetTextWithoutNotify(variable.Value.y.ToString());
zInput.SetTextWithoutNotify(variable.Value.z.ToString());
}
//---------------------------------------------------------------------------
protected override void UpdateVariableValue(Vector3 value) {
variable.Value = value;
}
//---------------------------------------------------------------------------
private float StringToFloat(string value) {
if (!String.IsNullOrEmpty(xInput.text)) {
return Convert.ToSingle(value);
}
return 0.0f;
}
}
}
fileFormatVersion: 2
guid: c051b053eaff99d4a94087f69d61e3ed
timeCreated: 1510784910
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using Shared.ScriptableVariables;
namespace Shared.SEUI {
// Read only UI for a Vector3Variable
// Depends on ScriptableVariable package
public class Vector3VariableLabel : ScriptableVariableLabel<Vector3> {
[Tooltip("The variable whose value we are displaying")]
public Vector3Variable value;
//---------------------------------------------------------------------------
protected override string GetName() {
return value.name;
}
//---------------------------------------------------------------------------
protected override Vector3 GetValue() {
return value.Value;
}
}
}
fileFormatVersion: 2
guid: 6b90857e4d335c248877cef27d2847a0
timeCreated: 1510784910
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using UnityEngine;
using UnityEngine.Events;
using TMPro;
using Shared.ScriptableVariables;
namespace Shared.SEUI {
// UI Editor for a Vector4Variable
// Depends on ScriptableVariable package
public class Vector4VariableInput : ScriptableVariableInput<Vector4> {
[Tooltip("The variable we are editing")]
public Vector4Variable variable;
[Tooltip("The input UI to edit the variable's x value with")]
public TMP_InputField xInput;
[Tooltip("The input UI to edit the variable's y value with")]
public TMP_InputField yInput;
[Tooltip("The input UI to edit the variable's z value with")]
public TMP_InputField zInput;
[Tooltip("The input UI to edit the variable's w value with")]
public TMP_InputField wInput;
// Temporary callbackx to bridge value changes in the UI and the variable
private UnityAction<string> xValueConverter;
private UnityAction<string> yValueConverter;
private UnityAction<string> zValueConverter;
private UnityAction<string> wValueConverter;
//---------------------------------------------------------------------------
void Start() {
// Make sure the input handles the right content type
xInput.contentType = TMP_InputField.ContentType.DecimalNumber;
yInput.contentType = TMP_InputField.ContentType.DecimalNumber;
zInput.contentType = TMP_InputField.ContentType.DecimalNumber;
wInput.contentType = TMP_InputField.ContentType.DecimalNumber;
}
//---------------------------------------------------------------------------
protected override void AddUIListener(UnityAction<Vector4> callback) {
// Define the value converting bridge callback to add to the UI listener
xValueConverter = delegate(string value) {
callback(new Vector4(StringToFloat(value), variable.Value.y, variable.Value.z, variable.Value.w));
};
yValueConverter = delegate(string value) {
callback(new Vector4(variable.Value.x, StringToFloat(value), variable.Value.z, variable.Value.w));
};
zValueConverter = delegate(string value) {
callback(new Vector4(variable.Value.x, variable.Value.y, StringToFloat(value), variable.Value.w));
};
wValueConverter = delegate(string value) {
callback(new Vector4(variable.Value.x, variable.Value.y, variable.Value.z, StringToFloat(value)));
};
xInput.onValueChanged.AddListener(xValueConverter);
yInput.onValueChanged.AddListener(yValueConverter);
yInput.onValueChanged.AddListener(zValueConverter);
yInput.onValueChanged.AddListener(wValueConverter);
}
//---------------------------------------------------------------------------
protected override void RemoveUIListener(UnityAction<Vector4> callback) {
if (xValueConverter != null) {
xInput.onValueChanged.RemoveListener(xValueConverter);
xValueConverter = null;
}
if (yValueConverter != null) {
yInput.onValueChanged.RemoveListener(yValueConverter);
yValueConverter = null;
}
if (zValueConverter != null) {
zInput.onValueChanged.RemoveListener(zValueConverter);
zValueConverter = null;
}
if (wValueConverter != null) {
wInput.onValueChanged.RemoveListener(wValueConverter);
wValueConverter = null;
}
}
//---------------------------------------------------------------------------
protected override bool DoValuesMatch() {
return !String.IsNullOrEmpty(xInput.text) && Convert.ToSingle(xInput.text) == variable.Value.x &&
!String.IsNullOrEmpty(yInput.text) && Convert.ToSingle(yInput.text) == variable.Value.y &&
!String.IsNullOrEmpty(zInput.text) && Convert.ToSingle(zInput.text) == variable.Value.z &&
!String.IsNullOrEmpty(wInput.text) && Convert.ToSingle(wInput.text) == variable.Value.w;
}
//---------------------------------------------------------------------------
protected override void UpdateUIValue() {
xInput.SetTextWithoutNotify(variable.Value.x.ToString());
yInput.SetTextWithoutNotify(variable.Value.y.ToString());
zInput.SetTextWithoutNotify(variable.Value.z.ToString());
wInput.SetTextWithoutNotify(variable.Value.w.ToString());
}
//---------------------------------------------------------------------------
protected override void UpdateVariableValue(Vector4 value) {
variable.Value = value;
}
//---------------------------------------------------------------------------
private float StringToFloat(string value) {
if (!String.IsNullOrEmpty(xInput.text)) {
return Convert.ToSingle(value);
}
return 0.0f;
}
}
}
fileFormatVersion: 2
guid: 5cfc33bad7311744585edb4617313baf
timeCreated: 1510784910
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using Shared.ScriptableVariables;
namespace Shared.SEUI {
// Read only UI for a Vector4Variable
// Depends on ScriptableVariable package
public class Vector4VariableLabel : ScriptableVariableLabel<Vector4> {
[Tooltip("The variable whose value we are displaying")]
public Vector4Variable value;
//---------------------------------------------------------------------------
protected override string GetName() {
return value.name;
}
//---------------------------------------------------------------------------
protected override Vector4 GetValue() {
return value.Value;
}
}
}
fileFormatVersion: 2
guid: 35dd2766ae2da1d48aeaf81da26d347a
timeCreated: 1510784910
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEngine.Events;
namespace Shared.ScriptableVariables {
// Component to tie Unity's event system to variable values based on conditions
public class Vector2VariableComparison : MonoBehaviour {
[Tooltip("The variable we are watching value changes to compare against something else")]
public Vector2Variable variable;
[Tooltip("Scriptable Variable to compare, if null then comparison value will be used to compare")]
public Vector2Variable comparisonVariable;
[Tooltip("Hardcoded value to compare against variable if comparisonVariable isn't set")]
public Vector2 comparisonValue;
[Tooltip("Fires if variable changes and its value is equal to the comparison amount")]
public UnityEvent onEqual;
[Tooltip("Fires if variable changes and its value is not equal to the comparison amount")]
public UnityEvent onNotEqual;
[Tooltip("Fires true or false if the values are equal whenever variable's value changes")]
public BooleanUnityEvent onValueChanged;
// --------------------------------------------------------------------------
void OnEnable() {
variable.OnValueChanged += OnValueChanged;
OnValueChanged();
}
// --------------------------------------------------------------------------
void OnDisable() {
variable.OnValueChanged -= OnValueChanged;
}
// --------------------------------------------------------------------------
private void OnValueChanged() {
var equal = variable.Value == (comparisonVariable != null ? comparisonVariable.Value : comparisonValue);
if (equal) {
onEqual?.Invoke();
}
else {
onNotEqual?.Invoke();
}
onValueChanged?.Invoke(equal);
}
}
}
fileFormatVersion: 2
guid: 8b8faad62b642b2428528c3a916c6328
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEngine.Events;
namespace Shared.ScriptableVariables {
// Component to tie Unity's event system to variable values based on conditions
public class Vector3VariableComparison : MonoBehaviour {
[Tooltip("The variable we are watching value changes to compare against something else")]
public Vector3Variable variable;
[Tooltip("Scriptable Variable to compare, if null then comparison value will be used to compare")]
public Vector3Variable comparisonVariable;
[Tooltip("Hardcoded value to compare against variable if comparisonVariable isn't set")]
public Vector3 comparisonValue;
[Tooltip("Fires if variable changes and its value is equal to the comparison amount")]
public UnityEvent onEqual;
[Tooltip("Fires if variable changes and its value is not equal to the comparison amount")]
public UnityEvent onNotEqual;
[Tooltip("Fires true or false if the values are equal whenever variable's value changes")]
public BooleanUnityEvent onValueChanged;
// --------------------------------------------------------------------------
void OnEnable() {
variable.OnValueChanged += OnValueChanged;
OnValueChanged();
}
// --------------------------------------------------------------------------
void OnDisable() {
variable.OnValueChanged -= OnValueChanged;
}
// --------------------------------------------------------------------------
private void OnValueChanged() {
var equal = variable.Value == (comparisonVariable != null ? comparisonVariable.Value : comparisonValue);
if (equal) {
onEqual?.Invoke();
}
else {
onNotEqual?.Invoke();
}
onValueChanged?.Invoke(equal);
}
}
}
fileFormatVersion: 2
guid: c44be721b807a4e438f7bf132387bb5c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEngine.Events;
namespace Shared.ScriptableVariables {
// Component to tie Unity's event system to variable values based on conditions
public class Vector4VariableComparison : MonoBehaviour {
[Tooltip("The variable we are watching value changes to compare against something else")]
public Vector4Variable variable;
[Tooltip("Scriptable Variable to compare, if null then comparison value will be used to compare")]
public Vector4Variable comparisonVariable;
[Tooltip("Hardcoded value to compare against variable if comparisonVariable isn't set")]
public Vector4 comparisonValue;
[Tooltip("Fires if variable changes and its value is equal to the comparison amount")]
public UnityEvent onEqual;
[Tooltip("Fires if variable changes and its value is not equal to the comparison amount")]
public UnityEvent onNotEqual;
[Tooltip("Fires true or false if the values are equal whenever variable's value changes")]
public BooleanUnityEvent onValueChanged;
// --------------------------------------------------------------------------
void OnEnable() {
variable.OnValueChanged += OnValueChanged;
OnValueChanged();
}
// --------------------------------------------------------------------------
void OnDisable() {
variable.OnValueChanged -= OnValueChanged;
}
// --------------------------------------------------------------------------
private void OnValueChanged() {
var equal = variable.Value == (comparisonVariable != null ? comparisonVariable.Value : comparisonValue);
if (equal) {
onEqual?.Invoke();
}
else {
onNotEqual?.Invoke();
}
onValueChanged?.Invoke(equal);
}
}
}
fileFormatVersion: 2
guid: 69f20c2bd66f017499dc99f0948e14e3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEditor;
using UnityEngine;
namespace Shared.ScriptableVariables {
//---------------------------------------------------------------------------
[CustomEditor(typeof(Vector2GameEvent))]
public class Vector2GameEventEditor : Editor {
private Vector2 testValue;
//---------------------------------------------------------------------------
public override void OnInspectorGUI() {
base.OnInspectorGUI();
EditorGUILayout.BeginHorizontal();
testValue = EditorGUILayout.Vector2Field("Test Value", testValue);
if (GUILayout.Button("Fire Event")) {
((Vector2GameEvent)target).Raise(testValue);
}
EditorGUILayout.EndHorizontal();
}
}
}
fileFormatVersion: 2
guid: 31c51078b2c87fc46ae2939707c50efc
timeCreated: 1513206436
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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