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

Commit e75c3c0

Browse files
author
Jamie Brynes
authored
Refactor out WorldSelector element (#1316)
1 parent c50e13b commit e75c3c0

File tree

18 files changed

+230
-57
lines changed

18 files changed

+230
-57
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- Added the ability to select a specific cluster for deployments in the [Deployment Launcher](https://documentation.improbable.io/gdk-for-unity/docs/deployment-launcher). [#1357](https://github.com/spatialos/gdk-for-unity/pull/1357)
1515
- You can select _either_ a region or a cluster, but not both!
1616
- Added non-generic overloads for the `EntityTemplate` class which allow you to use `ISpatialComponentSnapshot`s directly. [#1360](https://github.com/spatialos/gdk-for-unity/pull/1360)
17+
- Extracted the world selection UI element from the Network Analyzer window to a `WorldSelector` element. [#1316](https://github.com/spatialos/gdk-for-unity/pull/1316)
1718

1819
### Changed
1920

@@ -26,6 +27,7 @@
2627
- The Mobile Launcher will no longer break if Android build support is not installed. [#1354](https://github.com/spatialos/gdk-for-unity/pull/1354)
2728
- Fixed a bug in the `EntityTemplate` class where calling `AddComponent` with an `EntityAcl.Snapshot` would incorrectly apply its write access [#1360](https://github.com/spatialos/gdk-for-unity/pull/1360)
2829
- The Deployment Launcher will now generate Dev Auth Tokens using the environment specified in the GDK Tools Configuration. [#1366](https://github.com/spatialos/gdk-for-unity/pull/1366)
30+
- Fixed a bug where the Network Analyzer window would throw exceptions after being opened. [#1316](https://github.com/spatialos/gdk-for-unity/pull/1316)
2931

3032
### Internal
3133

workers/unity/Packages/io.improbable.gdk.core/Editor/Improbable.Gdk.Core.Editor.asmdef

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"name": "Improbable.Gdk.Core.Editor",
3-
"references": [],
3+
"references": [
4+
"GUID:734d92eba21c94caba915361bd5ac177",
5+
"GUID:edb3612c44ad0d24988d387581fd5fbe"
6+
],
47
"includePlatforms": [
58
"Editor"
69
],

workers/unity/Packages/io.improbable.gdk.core/Editor/UIElements.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.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Unity.Entities;
4+
using UnityEditor;
5+
using UnityEditor.UIElements;
6+
using UnityEngine.UIElements;
7+
8+
namespace Improbable.Gdk.Core.Editor.UIElements
9+
{
10+
public class WorldSelector : VisualElement
11+
{
12+
public delegate void WorldChanged(World world);
13+
14+
private const string UxmlPath = "Packages/io.improbable.gdk.core/Editor/UIElements/WorldSelector.uxml";
15+
16+
public World ActiveWorld { get; private set; }
17+
public WorldChanged OnWorldChanged;
18+
19+
private readonly ToolbarMenu menuElement;
20+
21+
public WorldSelector()
22+
{
23+
var template = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(UxmlPath);
24+
template.CloneTree(this);
25+
menuElement = this.Q<ToolbarMenu>("worldSelector");
26+
}
27+
28+
public void UpdateWorldSelection()
29+
{
30+
var worldMenu = menuElement.menu;
31+
32+
var spatialWorlds = new List<World>();
33+
34+
foreach (var world in World.All)
35+
{
36+
if (world.GetExistingSystem<WorkerSystem>() != null)
37+
{
38+
spatialWorlds.Add(world);
39+
}
40+
}
41+
42+
for (var i = 0; i < spatialWorlds.Count; i++)
43+
{
44+
var spatialWorld = spatialWorlds[i];
45+
worldMenu.InsertAction(i, spatialWorld.Name,
46+
action => SelectWorld((World) action.userData),
47+
action => ActiveWorld == (World) action.userData
48+
? DropdownMenuAction.Status.Checked
49+
: DropdownMenuAction.Status.Normal,
50+
spatialWorld);
51+
}
52+
53+
// Trim excess items
54+
var menuSize = worldMenu.MenuItems().Count;
55+
for (var i = spatialWorlds.Count; i < menuSize; i++)
56+
{
57+
worldMenu.RemoveItemAt(spatialWorlds.Count);
58+
}
59+
60+
// Update selected item if needed
61+
if (ActiveWorld == null || !ActiveWorld.IsCreated)
62+
{
63+
SelectWorld(spatialWorlds.FirstOrDefault());
64+
}
65+
}
66+
67+
private void SelectWorld(World world)
68+
{
69+
ActiveWorld = world;
70+
menuElement.text = ActiveWorld?.Name ?? "No SpatialOS worlds active";
71+
OnWorldChanged?.Invoke(world);
72+
}
73+
74+
public new class UxmlFactory : UxmlFactory<WorldSelector>
75+
{
76+
}
77+
}
78+
}

workers/unity/Packages/io.improbable.gdk.core/Editor/UIElements/WorldSelector.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.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.world-selector {
2+
height: 15px;
3+
flex-shrink: 0;
4+
white-space: nowrap;
5+
}

workers/unity/Packages/io.improbable.gdk.core/Editor/UIElements/WorldSelector.uss.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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<UXML xmlns="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements">
2+
<uie:ToolbarMenu name="worldSelector" class="world-selector">
3+
<Style path="Packages/io.improbable.gdk.core/Editor/UIElements/WorldSelector.uss" />
4+
</uie:ToolbarMenu>
5+
</UXML>

workers/unity/Packages/io.improbable.gdk.core/Editor/UIElements/WorldSelector.uxml.meta

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

workers/unity/Packages/io.improbable.gdk.core/Tests/Editmode/Editor.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)