-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added multi-variable text display (you can now use as a formatter s…
…omething like 'XP {0}/{1}', and use a MultiValueDisplayText component to provide multiple variables) - Created structure to allow for in the future variables, literals or functions to be used as values for most things (internals) - Added deprecated directories for scripts that will eventually be phased out
- Loading branch information
1 parent
664e45c
commit 6fd951a
Showing
22 changed files
with
633 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace OkapiKit | ||
{ | ||
[System.Serializable] | ||
public struct OkapiValue | ||
{ | ||
public enum Type { Float = 0, Integer = 1, VariableInstance = 2, Variable = 3 }; | ||
|
||
[SerializeField] private bool init; | ||
[SerializeField] private Type type; | ||
[SerializeField] private VariableInstance variableInstance; | ||
[SerializeField] private Variable variable; | ||
[SerializeField] private float floatValue; | ||
[SerializeField] private int intValue; | ||
|
||
public object GetRawValue() | ||
{ | ||
switch (type) | ||
{ | ||
case Type.Float: | ||
return floatValue; | ||
case Type.Integer: | ||
return intValue; | ||
case Type.VariableInstance: | ||
return (variableInstance) ? (variableInstance.GetRawValue()) : (null); | ||
case Type.Variable: | ||
return (variable) ? (variable.GetRawValue()) : (null); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public string GetName() | ||
{ | ||
switch (type) | ||
{ | ||
case Type.Float: | ||
break; | ||
case Type.Integer: | ||
break; | ||
case Type.VariableInstance: | ||
if (variableInstance != null) return variableInstance.name; | ||
break; | ||
case Type.Variable: | ||
if (variable != null) return variable.name; | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
return "unnamed"; | ||
} | ||
} | ||
|
||
|
||
[AttributeUsage(AttributeTargets.Field, Inherited = true, AllowMultiple = false)] | ||
public class OVNoLabelAttribute : PropertyAttribute | ||
{ | ||
} | ||
|
||
[AttributeUsage(AttributeTargets.Field, Inherited = true, AllowMultiple = false)] | ||
public class OVNoFloatAttribute : PropertyAttribute | ||
{ | ||
} | ||
|
||
[AttributeUsage(AttributeTargets.Field, Inherited = true, AllowMultiple = false)] | ||
public class OVNoIntegerAttribute : PropertyAttribute | ||
{ | ||
} | ||
|
||
[AttributeUsage(AttributeTargets.Field, Inherited = true, AllowMultiple = false)] | ||
public class OVNoVariableInstanceAttribute : PropertyAttribute | ||
{ | ||
} | ||
|
||
[AttributeUsage(AttributeTargets.Field, Inherited = true, AllowMultiple = false)] | ||
public class OVNoVariableAttribute : PropertyAttribute | ||
{ | ||
} | ||
|
||
[AttributeUsage(AttributeTargets.Field, Inherited = true, AllowMultiple = false)] | ||
public class OVNoFunctionAttribute : PropertyAttribute | ||
{ | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using UnityEngine; | ||
using UnityEditor; | ||
|
||
namespace OkapiKit.Editor | ||
{ | ||
[CustomEditor(typeof(MultiValueDisplay))] | ||
public class MultiValueDisplayEditor : OkapiBaseEditor | ||
{ | ||
protected SerializedProperty propValues; | ||
|
||
protected virtual string typeOfDisplay { get; } | ||
|
||
protected override void OnEnable() | ||
{ | ||
base.OnEnable(); | ||
|
||
propValues = serializedObject.FindProperty("values"); | ||
} | ||
|
||
public override void OnInspectorGUI() | ||
{ | ||
serializedObject.Update(); | ||
|
||
if (WriteTitle()) | ||
{ | ||
StdEditor(false); | ||
} | ||
} | ||
|
||
protected virtual void StdEditor(bool useOriginalEditor = true, bool isFinal = true) | ||
{ | ||
EditorGUI.BeginChangeCheck(); | ||
|
||
EditorGUILayout.PropertyField(propValues, new GUIContent("Values", "Values to display.\nFirst of these will replace {0} on the format string, the second will replace {1} and so forth."), true); | ||
|
||
if (isFinal) | ||
{ | ||
EditorGUILayout.PropertyField(propDescription, new GUIContent("Description", "This is for you to leave a comment for yourself or others."), true); | ||
|
||
EditorGUI.EndChangeCheck(); | ||
|
||
serializedObject.ApplyModifiedProperties(); | ||
(target as OkapiElement).UpdateExplanation(); | ||
|
||
// Draw old editor, need it for now | ||
if (useOriginalEditor) | ||
{ | ||
base.OnInspectorGUI(); | ||
} | ||
} | ||
} | ||
|
||
protected override GUIStyle GetTitleSyle() | ||
{ | ||
return GUIUtils.GetActionTitleStyle(); | ||
} | ||
|
||
protected override GUIStyle GetExplanationStyle() | ||
{ | ||
return GUIUtils.GetActionExplanationStyle(); | ||
} | ||
|
||
protected override string GetTitle() | ||
{ | ||
string varNames = "[UNDEFINED]"; | ||
|
||
// Get all var names | ||
var t = target as MultiValueDisplay; | ||
if (t != null) | ||
{ | ||
varNames = t.GetVariableNames(); | ||
} | ||
|
||
return $"Display {varNames} as {typeOfDisplay}"; | ||
} | ||
|
||
protected override Texture2D GetIcon() | ||
{ | ||
var varTexture = GUIUtils.GetTexture("VarDisplay"); | ||
|
||
return varTexture; | ||
} | ||
|
||
protected override (Color, Color, Color) GetColors() => (GUIUtils.ColorFromHex("#fffaa7"), GUIUtils.ColorFromHex("#2f4858"), GUIUtils.ColorFromHex("#ffdf6e")); | ||
|
||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/OkapiKit/Scripts/Editor/MultiValueDisplayEditor.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
Assets/OkapiKit/Scripts/Editor/MultiValueDisplayTextEditor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using UnityEngine; | ||
using UnityEditor; | ||
|
||
namespace OkapiKit.Editor | ||
{ | ||
[CustomEditor(typeof(MultiValueDisplayText))] | ||
public class MultiValueDisplayTextEditor : MultiValueDisplayEditor | ||
{ | ||
protected override string typeOfDisplay { get => "text"; } | ||
|
||
protected override void OnEnable() | ||
{ | ||
base.OnEnable(); | ||
} | ||
|
||
protected override void StdEditor(bool useOriginalEditor = true, bool isFinal = true) | ||
{ | ||
base.StdEditor(useOriginalEditor, true); | ||
} | ||
|
||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/OkapiKit/Scripts/Editor/MultiValueDisplayTextEditor.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.