-
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 hierarchy view icons and tooltips
- Loading branch information
Showing
8 changed files
with
345 additions
and
0 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
Assets/OkapiKit/Scripts/Editor/OkapiDisplayHierarchy.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,108 @@ | ||
using System; | ||
using UnityEditor; | ||
using UnityEditor.PackageManager.UI; | ||
using UnityEngine; | ||
|
||
[InitializeOnLoad] | ||
public class OkapiDisplayHierarchy | ||
{ | ||
static OkapiDisplayHierarchy() | ||
{ | ||
EditorApplication.hierarchyWindowItemOnGUI += HierarchyItemCB; | ||
} | ||
|
||
private static void HierarchyItemCB(int instanceID, Rect selectionRect) | ||
{ | ||
if (selectionRect.width < 200) return; | ||
|
||
float controlsWidth = 5 * 10; | ||
float xBase = selectionRect.x + selectionRect.width - controlsWidth; | ||
|
||
if (selectionRect.Contains(Event.current.mousePosition)) | ||
{ | ||
GUI.tooltip = ""; | ||
} | ||
|
||
GameObject go = EditorUtility.InstanceIDToObject(instanceID) as GameObject; | ||
if (go != null) | ||
{ | ||
var variable = go.GetComponent<VariableInstance>(); | ||
var movement = go.GetComponent<Movement>(); | ||
var triggers = go.GetComponents<Trigger>(); | ||
var actions = go.GetComponents<Action>(); | ||
var path = go.GetComponent<Path>(); | ||
|
||
if (variable) DrawCircle(xBase, selectionRect.y, GUIUtils.ColorFromHex("#fffaa7")); | ||
if (movement) DrawCircle(xBase + 10, selectionRect.y, GUIUtils.ColorFromHex("#ffcaca")); | ||
if ((triggers != null) && (triggers.Length > 0)) DrawCircle(xBase + 20, selectionRect.y, GUIUtils.ColorFromHex("#D0FFFF")); | ||
if ((actions != null) && (actions.Length > 0)) | ||
{ | ||
DrawCircle(xBase + 30, selectionRect.y, GUIUtils.ColorFromHex("#D7E8BA")); | ||
} | ||
if (path) DrawCircle(xBase + 40, selectionRect.y, GUIUtils.ColorFromHex("#ff8040")); | ||
|
||
var tags = go.GetTagsString(); | ||
if (tags != "") | ||
{ | ||
Rect rect = new Rect(xBase - 12, selectionRect.y + 4, 10, 10); | ||
GUI.DrawTexture(rect, GUIUtils.GetTexture("Tag"), ScaleMode.ScaleToFit, true, 1.0f, Color.white, 0.0f, 0.0f); | ||
} | ||
|
||
if ((variable) && (HasTooltip(xBase, selectionRect.y))) SetTooltip(GUIUtils.ColorFromHex("#fffaa7"), "Variable", $"{variable.name}"); | ||
if ((movement) && (HasTooltip(xBase + 10, selectionRect.y))) SetTooltip(GUIUtils.ColorFromHex("#ffcaca"), "Movement", $"Movement: {movement.GetTitle()}"); | ||
if ((triggers != null) && (triggers.Length > 0) && (HasTooltip(xBase + 20, selectionRect.y))) | ||
{ | ||
string tooltip = ""; | ||
for (int i = 0; i < triggers.Length; i++) | ||
{ | ||
if (tooltip != "") tooltip += "\n---------------\n"; | ||
tooltip += triggers[i].UpdateExplanation(); | ||
} | ||
tooltip.Remove(tooltip.Length - 1); | ||
|
||
SetTooltip(GUIUtils.ColorFromHex("#D0FFFF"), "Triggers", tooltip); | ||
} | ||
if ((actions != null) && (actions.Length > 0) && (HasTooltip(xBase + 30, selectionRect.y))) | ||
{ | ||
string tooltip = ""; | ||
for (int i = 0; i < actions.Length; i++) | ||
{ | ||
tooltip += $"{i + 1}. {actions[i].UpdateExplanation()}\n"; | ||
} | ||
tooltip = tooltip.Remove(tooltip.Length - 1); | ||
|
||
SetTooltip(GUIUtils.ColorFromHex("#D7E8BA"), "Actions", tooltip); | ||
} | ||
if ((path) && (HasTooltip(xBase + 40, selectionRect.y))) SetTooltip(GUIUtils.ColorFromHex("#ffcaca"), "Path", ""); | ||
|
||
if (tags != "") | ||
{ | ||
if (HasTooltip(xBase - 12, selectionRect.y)) | ||
{ | ||
tags = tags.Replace(", ", "\n"); | ||
SetTooltip(GUIUtils.ColorFromHex("#fdd0f6"), "Hypertags", tags); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static void DrawCircle(float x, float y, Color color) | ||
{ | ||
Rect rect = new Rect(x, y + 4, 10, 10); | ||
GUI.DrawTexture(rect, GUIUtils.GetTexture("FullCircle"), ScaleMode.ScaleToFit, true, 1.0f, color, 0.0f, 0.0f); | ||
} | ||
|
||
private static bool HasTooltip(float x, float y) | ||
{ | ||
Rect rect = new Rect(x, y + 4, 10, 10); | ||
return rect.Contains(Event.current.mousePosition); | ||
} | ||
|
||
private static void SetTooltip(Color color, string title, string text) | ||
{ | ||
var window = EditorWindow.GetWindow(typeof(OkapiTooltipWindow), true, title, false) as OkapiTooltipWindow; | ||
if (window == null) return; | ||
|
||
window.Show(color, text); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/OkapiKit/Scripts/Editor/OkapiDisplayHierarchy.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,92 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEditor; | ||
using UnityEditor.PackageManager.UI; | ||
using System; | ||
|
||
public class OkapiTooltipWindow : EditorWindow | ||
{ | ||
private string tooltipText = ""; | ||
private Color tooltipColor = Color.white; | ||
private DateTime tooltipTime; | ||
|
||
public void Show(Color color, string text) | ||
{ | ||
wantsMouseMove = true; | ||
wantsMouseEnterLeaveWindow = true; | ||
|
||
tooltipText = text; | ||
tooltipColor = color; | ||
|
||
tooltipTime = DateTime.Now; | ||
|
||
var style = GUIUtils.GetTooltipTextStyle(); | ||
var lines = tooltipText.Split('\n'); | ||
Vector2 size = new Vector2(100, 20); | ||
|
||
foreach (var l in lines) | ||
{ | ||
var tmp = style.CalcSize(new GUIContent(l)); | ||
size.x = Mathf.Max(tmp.x, size.x); | ||
size.y = Mathf.Max(tmp.y, size.y); | ||
} | ||
|
||
size.y = lines.Length * (style.fixedHeight + 2); | ||
|
||
size.x += 10; | ||
size.y += 10; | ||
|
||
var newPos = GUIUtility.GUIToScreenPoint(Event.current.mousePosition); | ||
newPos.x -= 5; | ||
newPos.y -= size.y * 0.9f; | ||
position = new Rect(newPos, size); | ||
minSize = size; | ||
} | ||
|
||
private void Update() | ||
{ | ||
if (tooltipText != "") | ||
{ | ||
if (mouseOverWindow != this) | ||
{ | ||
if ((DateTime.Now - tooltipTime).Seconds > 1.0f) | ||
{ | ||
Hide(); | ||
} | ||
} | ||
else | ||
{ | ||
tooltipTime = DateTime.Now; | ||
} | ||
} | ||
} | ||
|
||
public void Hide() | ||
{ | ||
Close(); | ||
tooltipText = ""; | ||
} | ||
|
||
void OnGUI() | ||
{ | ||
if (Event.current != null) | ||
{ | ||
if (Event.current.type == EventType.MouseLeaveWindow) | ||
{ | ||
Hide(); | ||
return; | ||
} | ||
} | ||
|
||
// your GUI code here | ||
Rect boxRect = new Rect(0.0f, 0.0f, Screen.currentResolution.width, Screen.currentResolution.height); | ||
|
||
EditorGUI.DrawRect(boxRect, tooltipColor); | ||
|
||
Rect textRect = new Rect(5.0f, 5.0f, Screen.currentResolution.width - 10, Screen.currentResolution.height - 10); | ||
|
||
var style = GUIUtils.GetTooltipTextStyle(); | ||
EditorGUI.LabelField(textRect, tooltipText, style); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.