Skip to content

Commit 8edc3c5

Browse files
committed
feat: samples and documents block
1 parent a7f1fe4 commit 8edc3c5

File tree

4 files changed

+83
-15
lines changed

4 files changed

+83
-15
lines changed

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

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using UnityEditor;
45
using UnityEngine;
56

@@ -11,32 +12,59 @@ public class IMGUIDocumentationBlock
1112
[SerializeField]
1213
List<IMGUIDocumentationUrl> m_DocUrls = new List<IMGUIDocumentationUrl>();
1314

15+
[SerializeField]
16+
List<IMGUISampleSceneUrl> m_SampleScenes = new List<IMGUISampleSceneUrl>();
17+
1418
public void AddDocumentationUrl(string title, string url)
1519
{
1620
var feature = new IMGUIDocumentationUrl(title,url);
1721
m_DocUrls.Add(feature);
1822
}
23+
24+
public void AddSampleScene(string title, string scenePath)
25+
{
26+
var feature = new IMGUISampleSceneUrl(title,scenePath);
27+
m_SampleScenes.Add(feature);
28+
}
1929

2030
public void Draw()
2131
{
22-
using (new IMGUIBlockWithSpace(new GUIContent("Documentation")))
32+
if (m_DocUrls.Count > 0)
33+
{
34+
using (new IMGUIBlockWithSpace(new GUIContent("Documentation")))
35+
{
36+
DrawLabelLinks(m_DocUrls);
37+
}
38+
}
39+
40+
if (m_SampleScenes.Count > 0)
41+
{
42+
using (new IMGUIBlockWithSpace(new GUIContent("Sample Scenes")))
43+
{
44+
DrawLabelLinks(m_SampleScenes);
45+
}
46+
}
47+
48+
}
49+
50+
void DrawLabelLinks(IEnumerable<IMGUIHyperLabel> hyperLabels)
51+
{
52+
using (new IMGUIIndentLevel(1))
2353
{
24-
using (new IMGUIIndentLevel(1))
54+
var labels = hyperLabels.ToArray();
55+
for (var i = 0; i < labels.Length; i += 2)
2556
{
26-
for (var i = 0; i < m_DocUrls.Count; i += 2)
57+
using (new IMGUIBeginHorizontal())
2758
{
28-
using (new IMGUIBeginHorizontal())
29-
{
30-
m_DocUrls[i].DrawLink(GUILayout.Width(150));
31-
if (m_DocUrls.Count > i + 1)
32-
m_DocUrls[i + 1].DrawLink(GUILayout.Width(150));
59+
labels[i].Draw(GUILayout.Width(150));
60+
if (labels.Length > i + 1)
61+
labels[i + 1].Draw(GUILayout.Width(150));
3362

34-
GUILayout.FlexibleSpace();
35-
}
63+
GUILayout.FlexibleSpace();
3664
}
37-
38-
EditorGUILayout.Space();
3965
}
66+
67+
EditorGUILayout.Space();
4068
}
4169
}
4270
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ public IMGUIDocumentationUrl(string title, string url)
2020
SetMouseOverColor(SettingsWindowStyles.SelectedElementColor);
2121
}
2222

23-
public void DrawLink(params GUILayoutOption[] options)
23+
public override bool Draw(params GUILayoutOption[] options)
2424
{
25-
var click = Draw(options);
26-
if (click) Application.OpenURL(m_URL);
25+
var click = base.Draw(options);
26+
if (click)
27+
Application.OpenURL(m_URL);
28+
29+
return click;
2730
}
2831
}
2932
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using UnityEditor.SceneManagement;
3+
using UnityEngine;
4+
5+
namespace StansAssets.Plugins.Editor
6+
{
7+
[Serializable]
8+
public class IMGUISampleSceneUrl : IMGUIHyperLabel
9+
{
10+
[SerializeField]
11+
string m_ScenePath;
12+
13+
public IMGUISampleSceneUrl(string title, string scenePath)
14+
: base(new GUIContent(
15+
title,
16+
PluginsEditorSkin.GetGenericIcon("list_arrow_white.png") //TODO unity scene Icon
17+
),
18+
SettingsWindowStyles.DescriptionLabelStyle)
19+
{
20+
m_ScenePath = scenePath;
21+
SetMouseOverColor(SettingsWindowStyles.SelectedElementColor);
22+
}
23+
24+
public override bool Draw(params GUILayoutOption[] options)
25+
{
26+
var click = base.Draw(options);
27+
if (click)
28+
EditorSceneManager.OpenScene(m_ScenePath);
29+
30+
31+
return click;
32+
}
33+
}
34+
}

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

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)