Skip to content

Commit

Permalink
- Tag count with condition can now be rendered by in the scene view t…
Browse files Browse the repository at this point in the history
…o be able to view the range (option on OkapiConfig scriptable object, enabled by default)

- Tags can now be seen in the scene view (option on OkapiConfig scriptable object, disabled by default)
  • Loading branch information
DiogoDeAndrade committed Feb 2, 2024
1 parent bb7fd25 commit d19b272
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 26 deletions.
7 changes: 7 additions & 0 deletions Assets/OkapiKit/Scripts/Base/OkapiConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public class OkapiConfig : ScriptableObject

[SerializeField]
private float maxPingTime = 4.0f;
[SerializeField, Header("Scene View")]
private bool displayConditions = true;
[SerializeField]
private bool displayHypertags = false;

protected OkapiElement pingComponent;
protected DateTime pingTime;
Expand Down Expand Up @@ -80,6 +84,9 @@ public static bool IsPinged(OkapiElement element)
return false;
}

public static bool showTags => (instance) ? (instance.displayHypertags) : (false);
public static bool showConditions => (instance) ? (instance.displayConditions) : (false);

static OkapiConfig instance {
get {
var allConfigs = FindAllInstances<OkapiConfig>();
Expand Down
21 changes: 12 additions & 9 deletions Assets/OkapiKit/Scripts/Editor/ActionEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,21 @@ public override void OnInspectorGUI()

public virtual void OnSceneGUI()
{
// Make sure to update the serializedObject to reflect the latest data
serializedObject.Update();
if (OkapiConfig.showConditions)
{
// Make sure to update the serializedObject to reflect the latest data
serializedObject.Update();

if (!propHasConditions.boolValue) return;
if (!propHasConditions.boolValue) return;

// Iterate through all elements in the propConditions array
for (int i = 0; i < propConditions.arraySize; i++)
{
SerializedProperty conditionElement = propConditions.GetArrayElementAtIndex(i);
// Iterate through all elements in the propConditions array
for (int i = 0; i < propConditions.arraySize; i++)
{
SerializedProperty conditionElement = propConditions.GetArrayElementAtIndex(i);

// Render the property we want
ConditionDrawer.OnSceneGUI(serializedObject, conditionElement);
// Render the property we want
ConditionDrawer.OnSceneGUI(serializedObject, conditionElement);
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions Assets/OkapiKit/Scripts/Editor/GUIUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ static public GUIStyle GetLabelStyle(string color)
}
return labelStyle;
}
static public GUIStyle GetCenteredLabelStyle(string color, Texture2D texture = null)
{
if (styles == null) styles = new Dictionary<string, GUIStyle>();

string n = $"CenteredLabel{color}";
GUIStyle labelStyle;
styles.TryGetValue(n, out labelStyle);
if (labelStyle == null)
{
labelStyle = new GUIStyle();
labelStyle.fontSize = 12;
labelStyle.fixedHeight = 12;
labelStyle.clipping = TextClipping.Overflow;
labelStyle.normal.textColor = ColorFromHex(color);
labelStyle.normal.background = texture;
labelStyle.alignment = TextAnchor.MiddleCenter;
styles.Add(n, labelStyle);
}
return labelStyle;
}

static public GUIStyle GetTooltipTextStyle()
{
Expand Down
9 changes: 9 additions & 0 deletions Assets/OkapiKit/Scripts/Editor/HypertaggedObjectEditor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using UnityEngine;
using UnityEditor;
using System.Linq;
using log4net.Util;

namespace OkapiKit.Editor
{
Expand All @@ -27,6 +28,14 @@ public override void OnInspectorGUI()
}
}

public void OnSceneGUI()
{
var ho = target as HypertaggedObject;

string tagText = ho.GetTagString();
Handles.Label(ho.transform.position, tagText);
}

protected void StdEditor(bool useOriginalEditor = true)
{
EditorGUI.BeginChangeCheck();
Expand Down
4 changes: 4 additions & 0 deletions Assets/OkapiKit/Scripts/Editor/OkapiConfigEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ protected virtual void OnEnable()
config.ForceCheckErrors();

AddProp("maxPingTime");
AddProp("displayHypertags");
AddProp("displayConditions");
}

void AddProp(string name)
Expand Down Expand Up @@ -49,6 +51,8 @@ public override void OnInspectorGUI()
EditorGUI.BeginChangeCheck();

EditorGUILayout.PropertyField(props["maxPingTime"], new GUIContent("Max. Ping Time", "When pinging an action, how long does it stays lit up."));
EditorGUILayout.PropertyField(props["displayHypertags"], new GUIContent("Display hypertags in scene view?", "Should the hypertags be visible in the scene view?"));
EditorGUILayout.PropertyField(props["displayConditions"], new GUIContent("Display conditions in scene view?", "Some conditions can be visualized in the scene view, should they?"));

if (EditorGUI.EndChangeCheck())
{
Expand Down
42 changes: 42 additions & 0 deletions Assets/OkapiKit/Scripts/Editor/OkapiSceneEditorGUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Collections;
using System.Collections.Generic;
using UnityEditor.TerrainTools;
using UnityEditor;
using UnityEngine;

namespace OkapiKit.Editor
{
[InitializeOnLoad] // Ensure the static constructor is called in the editor
public static class OkapiSceneEditorGUI
{
static OkapiSceneEditorGUI()
{
SceneView.duringSceneGui += OnSceneGUI;
}

private static void OnSceneGUI(SceneView sceneView)
{
if (OkapiConfig.showTags)
{
// Get all tags
var hos = GameObject.FindObjectsByType<HypertaggedObject>(FindObjectsInactive.Exclude, FindObjectsSortMode.None);
foreach (var h in hos)
{
var text = h.GetTagString();
if (text != "")
{
var pos = h.transform.position;

var sr = h.GetComponent<SpriteRenderer>();
if (sr)
{
pos = sr.bounds.center + sr.bounds.size.y * Vector3.up;
}

Handles.Label(pos, text, GUIUtils.GetCenteredLabelStyle("#00FFFFFF", GUIUtils.GetColorTexture("BlackBackground", Color.black)));
}
}
}
}
}
}
11 changes: 11 additions & 0 deletions Assets/OkapiKit/Scripts/Editor/OkapiSceneEditorGUI.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions Assets/OkapiKit/Scripts/Editor/TriggerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,19 @@ protected void StdEditor(bool useOriginalEditor = true, bool allowConditions = t

public virtual void OnSceneGUI()
{
// Make sure to update the serializedObject to reflect the latest data
serializedObject.Update();

// Iterate through all elements in the propConditions array
for (int i = 0; i < propPreConditions.arraySize; i++)
if (OkapiConfig.showConditions)
{
SerializedProperty conditionElement = propPreConditions.GetArrayElementAtIndex(i);
// Make sure to update the serializedObject to reflect the latest data
serializedObject.Update();

// Render the property we want
ConditionDrawer.OnSceneGUI(serializedObject, conditionElement);
// Iterate through all elements in the propConditions array
for (int i = 0; i < propPreConditions.arraySize; i++)
{
SerializedProperty conditionElement = propPreConditions.GetArrayElementAtIndex(i);

// Render the property we want
ConditionDrawer.OnSceneGUI(serializedObject, conditionElement);
}
}
}

Expand Down
19 changes: 11 additions & 8 deletions Assets/OkapiKit/Scripts/Editor/TriggerOnConditionEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,19 @@ public override void OnSceneGUI()
{
base.OnSceneGUI();

// Make sure to update the serializedObject to reflect the latest data
serializedObject.Update();

// Iterate through all elements in the propConditions array
for (int i = 0; i < propConditions.arraySize; i++)
if (OkapiConfig.showConditions)
{
SerializedProperty conditionElement = propConditions.GetArrayElementAtIndex(i);
// Make sure to update the serializedObject to reflect the latest data
serializedObject.Update();

// Iterate through all elements in the propConditions array
for (int i = 0; i < propConditions.arraySize; i++)
{
SerializedProperty conditionElement = propConditions.GetArrayElementAtIndex(i);

// Render the property we want
ConditionDrawer.OnSceneGUI(serializedObject, conditionElement);
// Render the property we want
ConditionDrawer.OnSceneGUI(serializedObject, conditionElement);
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
- Added center path option on path object
- Improved display and UI of path object
- Tag count condition can now be limited to a specific range
- Tag count with condition can now be rendered by in the scene view to be able to view the range
- Tag count with condition can now be rendered by in the scene view to be able to view the range (option on OkapiConfig scriptable object, enabled by default)
- Tags can now be seen in the scene view (option on OkapiConfig scriptable object, disabled by default)

## V1.9.2

Expand Down
1 change: 1 addition & 0 deletions Todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Features:
- Debug is just logging to the console what's happening in terms of triggers
and actions
- Tagged variables with search for variables beneath an object, etc...
- Conditions that can have visual support and interfaces on scene view should be created
- Add Network Object support to Okapi
- Add target to ActionSetParent (need rename of variables)
- Probes:
Expand Down

0 comments on commit d19b272

Please sign in to comment.