Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 8adf7d4

Browse files
author
Jamie Brynes
authored
Icons in the Worker Inspector (#1385)
1 parent 0dde9a1 commit 8adf7d4

File tree

14 files changed

+108
-22
lines changed

14 files changed

+108
-22
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
- Added a new "Worker Inspector" Editor window. [#1375](https://github.com/spatialos/gdk-for-unity/pull/1375) [#1379](https://github.com/spatialos/gdk-for-unity/pull/1379) [#1382](https://github.com/spatialos/gdk-for-unity/pull/1382)
1313
- This window displays worker information like: worker flags, worker ID, and worker type.
1414
- This window also displays the entities that a worker has checked out.
15-
- For each entity checked out, you can view the components on that entity and whether the worker is authoritative over that component.
15+
- For each entity checked out, you can view the components on that entity and whether the worker is authoritative over that component.
16+
- Each component can have an icon associated with it, set through a schema annotation. [#1385](https://github.com/spatialos/gdk-for-unity/pull/1385)
1617

1718
### Fixed
1819

schema/playground/color.schema

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package playground;
22

3+
import "improbable/gdk/editor/worker_inspector.schema";
4+
35
enum Color {
46
YELLOW = 0;
57
GREEN = 1;
@@ -11,11 +13,13 @@ type ColorData {
1113
Color color = 1;
1214
}
1315

16+
[improbable.gdk.editor.ComponentIcon("PreTextureRGB")]
1417
component CubeColor {
1518
id = 12000;
1619
event ColorData change_color;
1720
}
1821

22+
[improbable.gdk.editor.ComponentIcon("PreTextureRGB")]
1923
component SpinnerColor
2024
{
2125
id = 12010;

schema/playground/launcher.schema

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package playground;
22

33
import "playground/shared.schema";
4+
import "improbable/gdk/editor/worker_inspector.schema";
45

56
// Launcher represents an entity that can launch Launchables.
67
// The act of launching costs the launcher energy.
@@ -41,9 +42,9 @@ component Launcher {
4142
command ScoreIncreaseResponse increase_score(ScoreIncreaseRequest);
4243
}
4344

45+
[improbable.gdk.editor.ComponentIcon("PhysicsMaterial2D Icon")]
4446
component Launchable {
4547
id = 12006;
4648
EntityId most_recent_launcher = 1;
4749
command LaunchMeCommandResponse launch_me(LaunchMeCommandRequest);
4850
}
49-

schema/playground/player_input.schema

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package playground;
22

3+
import "improbable/gdk/editor/worker_inspector.schema";
4+
5+
[improbable.gdk.editor.ComponentIcon("NavMeshAgent Icon")]
36
component PlayerInput
47
{
58
id = 12001;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package improbable.gdk.editor;
2+
3+
type ComponentIcon {
4+
string icon_name = 1;
5+
}

workers/unity/Packages/io.improbable.gdk.debug/.codegen/Source/Generators/DebugExtensions/ComponentVisualElementGenerator.cs

+33
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Linq;
22
using Improbable.Gdk.CodeGeneration.CodeWriter;
33
using Improbable.Gdk.CodeGeneration.CodeWriter.Scopes;
4+
using Improbable.Gdk.CodeGeneration.Model;
45
using Improbable.Gdk.CodeGeneration.Model.Details;
56

67
namespace Improbable.Gdk.CodeGenerator
@@ -51,6 +52,8 @@ private void GenerateConstructor(TypeBlock typeBlock, UnityComponentDetails deta
5152
{
5253
mb.TextList(typeGenerator.ToFieldInitialisation(field, "ComponentFoldout"));
5354
}
55+
56+
mb.Line($"InjectComponentIcon(\"{GetComponentIcon(details)}\");");
5457
});
5558
}
5659

@@ -64,5 +67,35 @@ private void GenerateUpdateMethod(TypeBlock typeBlock, UnityComponentDetails det
6467
mb.TextList(details.FieldDetails.Select(fd => typeGenerator.ToUiFieldUpdate(fd, "component")));
6568
});
6669
}
70+
71+
private static string GetComponentIcon(UnityComponentDetails details)
72+
{
73+
string componentIcon;
74+
75+
switch (details.ComponentId)
76+
{
77+
case 53: // Metadata
78+
componentIcon = "d_FilterByLabel";
79+
break;
80+
case 54: //Position
81+
componentIcon = "Transform Icon";
82+
break;
83+
case 58: // Interest
84+
componentIcon = "d_ViewToolOrbit";
85+
break;
86+
default:
87+
componentIcon = "d_TextAsset Icon";
88+
break;
89+
}
90+
91+
if (details.Annotations.TryGetValue("improbable.gdk.editor.ComponentIcon", out var annotations))
92+
{
93+
var annotation = annotations[0].TypeValue;
94+
var iconNameField = annotation.Fields.First(field => field.Name == "icon_name");
95+
componentIcon = iconNameField.Value.StringValue;
96+
}
97+
98+
return componentIcon;
99+
}
67100
}
68101
}

workers/unity/Packages/io.improbable.gdk.debug/WorkerInspector/Codegen/ComponentVisualElement.cs

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Unity.Entities;
22
using UnityEditor;
3+
using UnityEngine;
34
using UnityEngine.UIElements;
45

56
namespace Improbable.Gdk.Debug.WorkerInspector.Codegen
@@ -21,6 +22,18 @@ protected ComponentVisualElement()
2122
AuthoritativeToggle = this.Q<Toggle>(className: "is-auth-toggle");
2223
}
2324

25+
protected void InjectComponentIcon(string iconName)
26+
{
27+
var iconContent = EditorGUIUtility.IconContent(iconName);
28+
var iconVisualElement = new VisualElement();
29+
iconVisualElement.style.backgroundImage = new StyleBackground((Texture2D) iconContent.image);
30+
iconVisualElement.AddToClassList("component-icon");
31+
32+
// We want to inject the icon after the toggle icon and before the text.
33+
var foldoutToggle = ComponentFoldout.Q<VisualElement>(className: "unity-toggle__input");
34+
foldoutToggle.Insert(1, iconVisualElement);
35+
}
36+
2437
public abstract ComponentType ComponentType { get; }
2538
public abstract void Update(EntityManager manager, Entity entity);
2639
}

workers/unity/Packages/io.improbable.gdk.debug/WorkerInspector/Templates/WorkerInspectorWindow.uss

+7
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@
7474
padding-bottom: 4px;
7575
}
7676

77+
.component-foldout .component-icon {
78+
height: 15px;
79+
width: 15px;
80+
align-self: center;
81+
margin-right: 10px;
82+
}
83+
7784
#worker-details {
7885
padding: 8px 4px;
7986
border-top-color: rgba(0, 0, 0, 0.20);

workers/unity/Packages/io.improbable.gdk.deploymentlauncher/DeploymentLauncherWindow.cs

+15-15
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ private void Update()
8787
{
8888
if (wrappedTask.Task.Result.ExitCode != 0)
8989
{
90-
Debug.LogError($"Upload of {wrappedTask.Context.AssemblyName} failed.");
90+
UnityEngine.Debug.LogError($"Upload of {wrappedTask.Context.AssemblyName} failed.");
9191
}
9292
else
9393
{
94-
Debug.Log($"Upload of {wrappedTask.Context.AssemblyName} succeeded.");
94+
UnityEngine.Debug.Log($"Upload of {wrappedTask.Context.AssemblyName} succeeded.");
9595
}
9696
}
9797

@@ -115,7 +115,7 @@ private void Update()
115115
}
116116
else
117117
{
118-
Debug.LogError($"Launch of {config.Name} failed. Code: {error.Code} Message: {error.Message}");
118+
UnityEngine.Debug.LogError($"Launch of {config.Name} failed. Code: {error.Code} Message: {error.Message}");
119119
}
120120
}
121121
}
@@ -139,7 +139,7 @@ private void Update()
139139
}
140140
else
141141
{
142-
Debug.LogError($"Failed to list deployments in project {wrappedTask.Context}. Code: {error.Code} Message: {error.Message}");
142+
UnityEngine.Debug.LogError($"Failed to list deployments in project {wrappedTask.Context}. Code: {error.Code} Message: {error.Message}");
143143
}
144144
}
145145
}
@@ -150,7 +150,7 @@ private void Update()
150150
var info = wrappedTask.Context;
151151
if (result.IsOkay)
152152
{
153-
Debug.Log($"Stopped deployment: \"{info.Name}\" successfully.");
153+
UnityEngine.Debug.Log($"Stopped deployment: \"{info.Name}\" successfully.");
154154

155155
for (var i = 0; i < listedDeployments.Count; i++)
156156
{
@@ -171,7 +171,7 @@ private void Update()
171171
}
172172
else
173173
{
174-
Debug.LogError($"Failed to stop deployment: \"{info.Name}\". Code: {error.Code} Message: {error.Message}.");
174+
UnityEngine.Debug.LogError($"Failed to stop deployment: \"{info.Name}\". Code: {error.Code} Message: {error.Message}.");
175175
}
176176
}
177177
}
@@ -182,13 +182,13 @@ private void Update()
182182

183183
if (result.ExitCode == 0)
184184
{
185-
Debug.Log("Successfully authenticated with SpatialOS. Retrying previous action.");
185+
UnityEngine.Debug.Log("Successfully authenticated with SpatialOS. Retrying previous action.");
186186
}
187187
else
188188
{
189189
// Stop the potential infinite loop of retries.
190190
manager.Cancel();
191-
Debug.LogError("Failed to authenticate with SpatialOS. Please run \"spatial auth login\" manually.");
191+
UnityEngine.Debug.LogError("Failed to authenticate with SpatialOS. Please run \"spatial auth login\" manually.");
192192
}
193193
}
194194

@@ -388,11 +388,11 @@ private void CancelCurrentTask()
388388
{
389389
if (manager.CancelCurrentTask(taskId))
390390
{
391-
Debug.Log("Cancelled task.");
391+
UnityEngine.Debug.Log("Cancelled task.");
392392
}
393393
else
394394
{
395-
Debug.LogWarning("Cannot cancel task as it has already reached completion.");
395+
UnityEngine.Debug.LogWarning("Cannot cancel task as it has already reached completion.");
396396
}
397397
}
398398
}
@@ -713,7 +713,7 @@ private bool RefreshAllWorkersList()
713713
catch (Exception e)
714714
{
715715
allWorkers = new string[0];
716-
Debug.LogException(e);
716+
UnityEngine.Debug.LogException(e);
717717
return false;
718718
}
719719
}
@@ -858,15 +858,15 @@ private string GetProjectName()
858858

859859
if (!File.Exists(spatialJsonFile))
860860
{
861-
Debug.LogError($"Could not find a spatialos.json file located at: {spatialJsonFile}");
861+
UnityEngine.Debug.LogError($"Could not find a spatialos.json file located at: {spatialJsonFile}");
862862
return null;
863863
}
864864

865865
var data = Json.Deserialize(File.ReadAllText(spatialJsonFile));
866866

867867
if (data == null)
868868
{
869-
Debug.LogError($"Could not parse spatialos.json file located at: {spatialJsonFile}");
869+
UnityEngine.Debug.LogError($"Could not parse spatialos.json file located at: {spatialJsonFile}");
870870
return null;
871871
}
872872

@@ -876,7 +876,7 @@ private string GetProjectName()
876876
}
877877
catch (KeyNotFoundException e)
878878
{
879-
Debug.LogError($"Could not find a \"name\" field in {spatialJsonFile}.\n Raw exception: {e.Message}");
879+
UnityEngine.Debug.LogError($"Could not find a \"name\" field in {spatialJsonFile}.\n Raw exception: {e.Message}");
880880
return null;
881881
}
882882
}
@@ -888,7 +888,7 @@ private bool TryAuthAndRetry(Ipc.Error error)
888888
return false;
889889
}
890890

891-
Debug.Log("Attempting to authenticate...");
891+
UnityEngine.Debug.Log("Attempting to authenticate...");
892892
manager.Auth();
893893

894894
return true;

workers/unity/Packages/io.improbable.gdk.gameobjectcreation/GameObjectInitializationSystem.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private void ProcessRemovedEntities()
106106
}
107107
catch (Exception e)
108108
{
109-
Debug.LogException(e);
109+
UnityEngine.Debug.LogException(e);
110110
}
111111
});
112112

@@ -139,7 +139,7 @@ private void ProcessNewEntities()
139139
}
140140
catch (Exception e)
141141
{
142-
Debug.LogException(e);
142+
UnityEngine.Debug.LogException(e);
143143
}
144144

145145
PostUpdateCommands.AddComponent(entity, new GameObjectInitSystemStateComponent

workers/unity/Packages/io.improbable.gdk.querybasedinteresthelper/InterestQuery.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public InterestQuery FilterResults(IEnumerable<uint> resultComponentIds)
105105
{
106106
if (!resultComponentIds.Any())
107107
{
108-
Debug.LogWarning("At least one component ID must be provided to filter a query's results.");
108+
UnityEngine.Debug.LogWarning("At least one component ID must be provided to filter a query's results.");
109109
return this;
110110
}
111111

workers/unity/Packages/io.improbable.gdk.querybasedinteresthelper/InterestTemplate.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public InterestTemplate AddQueries(uint componentId, IEnumerable<InterestQuery>
173173
{
174174
if (!interestQueries.Any())
175175
{
176-
Debug.LogWarning("At least one InterestQuery must be provided to add to a component's interest.");
176+
UnityEngine.Debug.LogWarning("At least one InterestQuery must be provided to add to a component's interest.");
177177
return this;
178178
}
179179

@@ -286,7 +286,7 @@ public InterestTemplate ReplaceQueries(uint componentId, IEnumerable<InterestQue
286286
{
287287
if (!interestQueries.Any())
288288
{
289-
Debug.LogWarning("At least one InterestQuery must be provided to replace a component's interest.");
289+
UnityEngine.Debug.LogWarning("At least one InterestQuery must be provided to replace a component's interest.");
290290
return this;
291291
}
292292

workers/unity/Packages/io.improbable.gdk.tools/.CodeGenTemplate/CodeGenerationLib/Model/Details/TypeDetails/UnityComponentDetails.cs

+16
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class UnityComponentDetails : GeneratorInputDetails
1212
public IReadOnlyList<UnityFieldDetails> FieldDetails { get; private set; }
1313
public readonly IReadOnlyList<UnityCommandDetails> CommandDetails;
1414
public readonly IReadOnlyList<UnityEventDetails> EventDetails;
15+
public readonly IReadOnlyDictionary<string, List<Annotation>> Annotations;
1516

1617
private readonly ComponentDefinition rawComponentDefinition;
1718

@@ -58,6 +59,21 @@ public UnityComponentDetails(string package, ComponentDefinition rawComponentDef
5859
.ToList()
5960
.AsReadOnly();
6061

62+
var annotations = new Dictionary<string, List<Annotation>>();
63+
64+
foreach (var annotation in rawComponentDefinition.Annotations)
65+
{
66+
if (!annotations.TryGetValue(annotation.TypeValue.Type, out var list))
67+
{
68+
list = new List<Annotation>();
69+
annotations[annotation.TypeValue.Type] = list;
70+
}
71+
72+
list.Add(annotation);
73+
}
74+
75+
Annotations = annotations;
76+
6177
this.rawComponentDefinition = rawComponentDefinition;
6278
}
6379

workers/unity/Packages/io.improbable.gdk.transformsynchronization/.schema/improbable/gdk/transform_synchronization/transform_internal.schema

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package improbable.gdk.transform_synchronization;
22

3+
import "improbable/gdk/editor/worker_inspector.schema";
4+
35
type FixedPointVector3 {
46
sint32 x = 1;
57
sint32 y = 2;
@@ -10,6 +12,7 @@ type CompressedQuaternion {
1012
uint32 data = 1;
1113
}
1214

15+
[improbable.gdk.editor.ComponentIcon("Transform Icon")]
1316
component TransformInternal {
1417
id = 11000;
1518
FixedPointVector3 location = 1;

0 commit comments

Comments
 (0)