This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add worker details to worker inspector (#1382)
- Loading branch information
Jamie Brynes
authored
Jun 4, 2020
1 parent
6e75771
commit 738f0a7
Showing
13 changed files
with
244 additions
and
5 deletions.
There are no files selected for viewing
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
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
13 changes: 13 additions & 0 deletions
13
workers/unity/Packages/io.improbable.gdk.debug/WorkerInspector/Templates/WorkerDetail.uxml
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,13 @@ | ||
<UXML xmlns="UnityEngine.UIElements"> | ||
<VisualElement name="worker-details-container"> | ||
<VisualElement name="worker-info"> | ||
<TextField name="worker-type" label="Worker Type"/> | ||
<TextField name="worker-id" label="Worker ID"/> | ||
</VisualElement> | ||
<VisualElement name="worker-flags"> | ||
<Label text="Worker Flags"/> | ||
<ListView name="worker-flags-list"> | ||
</ListView> | ||
</VisualElement> | ||
</VisualElement> | ||
</UXML> |
3 changes: 3 additions & 0 deletions
3
...s/unity/Packages/io.improbable.gdk.debug/WorkerInspector/Templates/WorkerDetail.uxml.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
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
11 changes: 11 additions & 0 deletions
11
...Packages/io.improbable.gdk.debug/WorkerInspector/Templates/WorkerInspectorWindow_Dark.uss
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,11 @@ | ||
.is-auth-toggle .unity-label:disabled { | ||
color: white; | ||
} | ||
|
||
#worker-info .unity-label:disabled { | ||
color: white; | ||
} | ||
|
||
#worker-flags .unity-label:disabled { | ||
color: white; | ||
} |
3 changes: 3 additions & 0 deletions
3
...ges/io.improbable.gdk.debug/WorkerInspector/Templates/WorkerInspectorWindow_Dark.uss.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
...ackages/io.improbable.gdk.debug/WorkerInspector/Templates/WorkerInspectorWindow_Light.uss
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,11 @@ | ||
.is-auth-toggle .unity-label:disabled { | ||
color: black; | ||
} | ||
|
||
#worker-info .unity-label:disabled { | ||
color: black; | ||
} | ||
|
||
#worker-flags .unity-label:disabled { | ||
color: black; | ||
} |
3 changes: 3 additions & 0 deletions
3
...es/io.improbable.gdk.debug/WorkerInspector/Templates/WorkerInspectorWindow_Light.uss.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
112 changes: 112 additions & 0 deletions
112
workers/unity/Packages/io.improbable.gdk.debug/WorkerInspector/WorkerDetail.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,112 @@ | ||
using System.Collections.Generic; | ||
using Improbable.Gdk.Core; | ||
using Unity.Entities; | ||
using UnityEditor; | ||
using UnityEngine.UIElements; | ||
|
||
namespace Improbable.Gdk.Debug.WorkerInspector | ||
{ | ||
internal class WorkerDetail : VisualElement | ||
{ | ||
private const string FlagKeyName = "key"; | ||
private const string FlagValueName = "value"; | ||
|
||
private readonly TextField workerType; | ||
private readonly TextField workerId; | ||
private readonly ListView workerFlags; | ||
|
||
private readonly List<KeyValuePair<string, string>> workerFlagData = new List<KeyValuePair<string, string>>(); | ||
|
||
private View view; | ||
|
||
public WorkerDetail() | ||
{ | ||
const string uxmlPath = "Packages/io.improbable.gdk.debug/WorkerInspector/Templates/WorkerDetail.uxml"; | ||
var template = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxmlPath); | ||
template.CloneTree(this); | ||
|
||
workerType = this.Q<TextField>("worker-type"); | ||
workerType.SetEnabled(false); | ||
|
||
workerId = this.Q<TextField>("worker-id"); | ||
workerId.SetEnabled(false); | ||
|
||
workerFlags = this.Q<ListView>("worker-flags-list"); | ||
workerFlags.makeItem = MakeItem; | ||
workerFlags.bindItem = BindElement; | ||
workerFlags.itemsSource = workerFlagData; | ||
workerFlags.SetEnabled(false); | ||
} | ||
|
||
public void SetWorld(World world) | ||
{ | ||
if (world == null) | ||
{ | ||
workerType.value = ""; | ||
workerId.value = ""; | ||
workerFlagData.Clear(); | ||
workerFlags.Refresh(); | ||
view = null; | ||
return; | ||
} | ||
|
||
var workerSystem = world.GetExistingSystem<WorkerSystem>(); | ||
|
||
workerType.value = workerSystem.WorkerType; | ||
workerId.value = workerSystem.WorkerId; | ||
|
||
view = workerSystem.View; | ||
Update(); | ||
} | ||
|
||
public void Update() | ||
{ | ||
if (view == null) | ||
{ | ||
return; | ||
} | ||
|
||
workerFlagData.Clear(); | ||
|
||
foreach (var pair in view.WorkerFlags) | ||
{ | ||
workerFlagData.Add(pair); | ||
} | ||
|
||
workerFlags.Refresh(); | ||
} | ||
|
||
private static VisualElement MakeItem() | ||
{ | ||
var container = new VisualElement(); | ||
container.AddToClassList("flag-element-container"); | ||
|
||
var key = new Label { name = FlagKeyName, }; | ||
|
||
key.AddToClassList("flag-element"); | ||
|
||
var value = new Label { name = FlagValueName }; | ||
|
||
value.AddToClassList("flag-element"); | ||
|
||
container.Add(key); | ||
container.Add(value); | ||
|
||
return container; | ||
} | ||
|
||
private void BindElement(VisualElement element, int index) | ||
{ | ||
var key = element.Q<Label>(FlagKeyName); | ||
var value = element.Q<Label>(FlagValueName); | ||
var kvp = workerFlagData[index]; | ||
|
||
key.text = kvp.Key; | ||
value.text = kvp.Value; | ||
} | ||
|
||
public new class UxmlFactory : UxmlFactory<WorkerDetail> | ||
{ | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
workers/unity/Packages/io.improbable.gdk.debug/WorkerInspector/WorkerDetail.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