Skip to content

Commit 8ff4829

Browse files
Merge branch 'master' into aboutTab-hyperlink
2 parents 232c2f5 + 291480e commit 8ff4829

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1562
-122
lines changed

com.stansassets.plugins-dev-kit/Editor/Config/PluginsDevKitPackage.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ static class PluginsDevKitPackage
1010
public static readonly string UIToolkitPath = $"{RootPath}/Editor/UIToolkit";
1111
public static readonly string UIToolkitControlsPath = $"{UIToolkitPath}/Controls";
1212

13+
#if UNITY_2019_4_OR_NEWER
1314
/// <summary>
1415
/// Foundation package info.
1516
/// </summary>
1617
public static PackageInfo GetPackageInfo()
1718
{
1819
return PackageManagerUtility.GetPackageInfo(Name);
1920
}
21+
#endif
2022
}
2123
}

com.stansassets.plugins-dev-kit/Editor/IMGUI/Controls.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using UnityEngine;
3+
using UnityEditor;
4+
5+
namespace StansAssets.Plugins.Editor
6+
{
7+
[Serializable]
8+
public abstract class IMGUIHyperButton
9+
{
10+
bool m_IsMouseOver = false;
11+
Rect m_LabelRect = new Rect();
12+
13+
[SerializeField]
14+
bool m_IsSelected = false;
15+
16+
protected abstract void OnNormal(params GUILayoutOption[] options);
17+
protected abstract void OnMouseOver(params GUILayoutOption[] options);
18+
19+
/// <summary>
20+
/// True if current elements selection state is locked
21+
/// </summary>
22+
public bool IsSelectionLock => m_IsSelected;
23+
24+
/// <summary>
25+
/// Locked button in a selected state
26+
/// OnMouseOver mode UI will be drawn, and button will not accept
27+
/// the mouse click event.
28+
/// </summary>
29+
public void LockSelectedState(bool val)
30+
{
31+
m_IsSelected = val;
32+
}
33+
34+
public virtual bool Draw(params GUILayoutOption[] options)
35+
{
36+
if (m_IsSelected)
37+
{
38+
OnMouseOver(options);
39+
return false;
40+
}
41+
42+
if (!m_IsMouseOver)
43+
OnNormal(options);
44+
else
45+
OnMouseOver(options);
46+
47+
if (Event.current.type == EventType.Repaint)
48+
{
49+
m_LabelRect = GUILayoutUtility.GetLastRect();
50+
m_IsMouseOver = m_LabelRect.Contains(Event.current.mousePosition);
51+
}
52+
53+
if (Event.current.type == EventType.Repaint)
54+
if (m_IsMouseOver)
55+
EditorGUIUtility.AddCursorRect(m_LabelRect, MouseCursor.Link);
56+
57+
var clicked = false;
58+
if (m_IsMouseOver)
59+
if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
60+
{
61+
clicked = true;
62+
GUI.changed = true;
63+
Event.current.Use();
64+
}
65+
66+
return clicked;
67+
}
68+
}
69+
}

com.stansassets.plugins-dev-kit/Editor/IMGUI/Controls/IMGUIHyperButton.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
using System;
2+
using StansAssets.Foundation.Extensions;
3+
using UnityEngine;
4+
using UnityEditor;
5+
6+
namespace StansAssets.Plugins.Editor
7+
{
8+
[Serializable]
9+
public class IMGUIHyperLabel : IMGUIHyperButton
10+
{
11+
[SerializeField]
12+
GUIContent m_Content;
13+
[SerializeField]
14+
GUIContent m_HighlightedContext;
15+
16+
[SerializeField]
17+
GUIStyle m_Style;
18+
[SerializeField]
19+
GUIStyle m_MouseOverStyle;
20+
21+
[SerializeField]
22+
bool m_OverrideGuiColor;
23+
24+
public IMGUIHyperLabel(GUIContent content)
25+
: this(content, EditorStyles.label) { }
26+
27+
public IMGUIHyperLabel(GUIContent content, GUIStyle style)
28+
{
29+
m_Content = content;
30+
m_Style = new GUIStyle(style);
31+
m_MouseOverStyle = new GUIStyle(style);
32+
}
33+
34+
public void SetColor(Color color)
35+
{
36+
m_Style.normal.textColor = color;
37+
}
38+
39+
public void SetMouseOverColor(Color color)
40+
{
41+
m_MouseOverStyle.normal.textColor = color;
42+
}
43+
44+
public void HighLight(string pattern)
45+
{
46+
if (m_HighlightedContext == null) m_HighlightedContext = new GUIContent(m_Content);
47+
48+
var indexes = m_Content.text.AllIndexesOf(pattern, StringComparison.OrdinalIgnoreCase);
49+
if (indexes.Count == 0)
50+
{
51+
m_HighlightedContext.text = m_Content.text;
52+
}
53+
else
54+
{
55+
m_HighlightedContext.text = string.Empty;
56+
var lastCopyIndex = 0;
57+
foreach (var index in indexes)
58+
{
59+
m_HighlightedContext.text += m_Content.text.Substring(lastCopyIndex, index - lastCopyIndex);
60+
m_HighlightedContext.text += "<color=yellow>";
61+
m_HighlightedContext.text += m_Content.text.Substring(index, pattern.Length);
62+
m_HighlightedContext.text += "</color>";
63+
64+
lastCopyIndex = index + pattern.Length;
65+
}
66+
67+
m_HighlightedContext.text += m_Content.text.Substring(lastCopyIndex, m_Content.text.Length - lastCopyIndex);
68+
}
69+
}
70+
71+
public void DisableHighLight()
72+
{
73+
m_HighlightedContext = null;
74+
}
75+
76+
public bool DrawWithCalcSize()
77+
{
78+
var width = CalcSize().x + 5f;
79+
return Draw(GUILayout.Width(width));
80+
}
81+
82+
protected override void OnNormal(params GUILayoutOption[] options)
83+
{
84+
if (m_OverrideGuiColor)
85+
using (new IMGUIChangeColor(m_Style.normal.textColor))
86+
{
87+
using (new IMGUIChangeContentColor(m_Style.normal.textColor))
88+
{
89+
EditorGUILayout.LabelField(HighlightedContext ?? m_Content, m_Style, options);
90+
}
91+
}
92+
else
93+
EditorGUILayout.LabelField(HighlightedContext ?? m_Content, m_Style, options);
94+
}
95+
96+
protected override void OnMouseOver(params GUILayoutOption[] options)
97+
{
98+
var c = GUI.color;
99+
GUI.color = m_MouseOverStyle.normal.textColor;
100+
101+
EditorGUILayout.LabelField(m_Content, m_MouseOverStyle, options);
102+
GUI.color = c;
103+
}
104+
105+
public Vector2 CalcSize()
106+
{
107+
return m_Style.CalcSize(m_Content);
108+
}
109+
110+
public void SetContent(GUIContent content)
111+
{
112+
m_Content = content;
113+
}
114+
115+
public void SetStyle(GUIStyle style)
116+
{
117+
m_Style = new GUIStyle(style);
118+
}
119+
120+
public void GuiColorOverride(bool value)
121+
{
122+
m_OverrideGuiColor = value;
123+
}
124+
125+
public GUIContent Content => m_Content;
126+
127+
public Color Color => m_Style.normal.textColor;
128+
129+
GUIContent HighlightedContext
130+
{
131+
get
132+
{
133+
if (m_HighlightedContext != null && string.IsNullOrEmpty(m_HighlightedContext.text)) return null;
134+
135+
return m_HighlightedContext;
136+
}
137+
}
138+
}
139+
}

com.stansassets.plugins-dev-kit/Editor/IMGUI/Controls/IMGUIHyperLabel.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using UnityEditor;
5+
6+
namespace StansAssets.Plugins.Editor
7+
{
8+
[Serializable]
9+
public class IMGUIHyperToolbar
10+
{
11+
[SerializeField]
12+
int m_ButtonsWidth = 0;
13+
[SerializeField]
14+
int m_ButtonsHeight = 0;
15+
[SerializeField]
16+
float m_ItemsSpace = 5f;
17+
[SerializeField]
18+
List<IMGUIHyperLabel> m_Buttons = new List<IMGUIHyperLabel>();
19+
20+
public void AddButtons(params IMGUIHyperLabel[] buttons)
21+
{
22+
if (m_Buttons == null) m_Buttons = new List<IMGUIHyperLabel>();
23+
24+
foreach (var newBtn in buttons) m_Buttons.Add(newBtn);
25+
26+
ValidateButtons();
27+
}
28+
29+
void ValidateButtons()
30+
{
31+
if (m_Buttons.Count == 0) return;
32+
33+
var hasActive = false;
34+
foreach (var button in m_Buttons)
35+
if (button.IsSelectionLock)
36+
{
37+
hasActive = true;
38+
break;
39+
}
40+
41+
if (!hasActive) m_Buttons[0].LockSelectedState(true);
42+
}
43+
44+
public void SetSelectedIndex(int index)
45+
{
46+
foreach (var button in m_Buttons) button.LockSelectedState(false);
47+
48+
var selectedButton = m_Buttons[index];
49+
selectedButton.LockSelectedState(true);
50+
}
51+
52+
/// <summary>
53+
/// Draw toolbar with buttons.
54+
/// Returns selected button index
55+
/// </summary>
56+
public int Draw()
57+
{
58+
if (m_Buttons == null) return 0;
59+
60+
EditorGUILayout.BeginHorizontal();
61+
{
62+
EditorGUILayout.Space();
63+
64+
foreach (var button in m_Buttons)
65+
{
66+
float width;
67+
68+
if (m_ButtonsWidth == 0)
69+
width = button.CalcSize().x + m_ItemsSpace;
70+
else
71+
width = m_ButtonsWidth;
72+
73+
bool click;
74+
click = m_ButtonsHeight != 0
75+
? button.Draw(GUILayout.Width(width), GUILayout.Height(m_ButtonsHeight))
76+
: button.Draw(GUILayout.Width(width));
77+
78+
if (click) SetSelectedIndex(m_Buttons.IndexOf(button));
79+
}
80+
81+
EditorGUILayout.Space();
82+
}
83+
EditorGUILayout.EndHorizontal();
84+
85+
return SelectionIndex;
86+
}
87+
88+
/// <summary>
89+
/// Set's custom width for all toolbar buttons.
90+
/// The default value is 0. When value is 0 button width is calculated
91+
/// based on button GUI rect.
92+
/// </summary>
93+
/// <param name="width">width value</param>
94+
public void SetButtonsWidth(int width)
95+
{
96+
m_ButtonsWidth = width;
97+
}
98+
99+
/// <summary>
100+
/// Set's custom height for all toolbar buttons.
101+
/// The default value is 0. When value is 0 button height is calculated
102+
/// based on button GUI rect.
103+
/// </summary>
104+
/// <param name="height">height value</param>
105+
public void SetButtonsHeight(int height)
106+
{
107+
m_ButtonsHeight = height;
108+
}
109+
110+
/// <summary>
111+
/// Set's space between items.
112+
/// Default space it 5
113+
/// </summary>
114+
/// <param name="space">items space value</param>
115+
public void SetItemsSpace(float space)
116+
{
117+
m_ItemsSpace = space;
118+
}
119+
120+
/// <summary>
121+
/// Toolbar buttons
122+
/// </summary>
123+
public List<IMGUIHyperLabel> Buttons => m_Buttons;
124+
125+
public int SelectionIndex
126+
{
127+
get
128+
{
129+
foreach (var button in m_Buttons)
130+
if (button.IsSelectionLock)
131+
return m_Buttons.IndexOf(button);
132+
133+
return 0;
134+
}
135+
}
136+
}
137+
}

0 commit comments

Comments
 (0)