Skip to content

Commit

Permalink
Populate quick add from defaults service.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Dec 8, 2023
1 parent 80eedb3 commit b2d8956
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 97 deletions.
102 changes: 5 additions & 97 deletions Editor/CesiumEditorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,42 +172,6 @@ void DrawCesiumToolbar()
GUILayout.EndHorizontal();
}

private enum QuickAddItemType
{
BlankTileset,
DynamicCamera,
IonTileset
}

private class QuickAddItem
{
public QuickAddItemType type;
public string name;
public string tooltip;
public string tilesetName;
public long tilesetId;
public string overlayName;
public long overlayId;

public QuickAddItem(
QuickAddItemType type,
string name,
string tooltip,
string tilesetName,
long tilesetId,
string overlayName,
long overlayId)
{
this.type = type;
this.name = name;
this.tooltip = tooltip;
this.tilesetName = tilesetName;
this.tilesetId = tilesetId;
this.overlayName = overlayName;
this.overlayId = overlayId;
}
}

private readonly QuickAddItem[] _basicAssets = new[]
{
new QuickAddItem(
Expand All @@ -230,62 +194,6 @@ public QuickAddItem(
-1)
};

private readonly QuickAddItem[] _ionAssets = new[]
{
new QuickAddItem(
QuickAddItemType.IonTileset,
"Google Photorealistic 3D Tiles",
"Photorealistic 3D Tiles from Google Maps Platform.",
"Google Photorealistic 3D Tiles",
2275207,
"",
-1),
new QuickAddItem(
QuickAddItemType.IonTileset,
"Cesium World Terrain + Bing Maps Aerial imagery",
"High-resolution global terrain tileset curated from several data sources, " +
"textured with Bing Maps satellite imagery.",
"Cesium World Terrain",
1,
"Bing Maps Aerial imagery",
2),
new QuickAddItem(
QuickAddItemType.IonTileset,
"Cesium World Terrain + Bing Maps Aerial with Labels imagery",
"High-resolution global terrain tileset curated from several data sources, " +
"textured with labeled Bing Maps satellite imagery.",
"Cesium World Terrain",
1,
"Bing Maps Aerial with Labels imagery",
3),
new QuickAddItem(
QuickAddItemType.IonTileset,
"Cesium World Terrain + Bing Maps Road imagery",
"High-resolution global terrain tileset curated from several data sources, " +
"textured with labeled Bing Maps imagery.",
"Cesium World Terrain",
1,
"Bing Maps Road imagery",
4),
new QuickAddItem(
QuickAddItemType.IonTileset,
"Cesium World Terrain + Sentinel-2 imagery",
"High-resolution global terrain tileset curated from several data sources, " +
"textured with high-resolution satellite imagery from the Sentinel-2 project.",
"Cesium World Terrain",
1,
"Sentinel-2 imagery",
3954),
new QuickAddItem(
QuickAddItemType.IonTileset,
"Cesium OSM Buildings",
"A 3D buildings layer derived from OpenStreetMap covering the entire world.",
"Cesium OSM Buildings",
96188,
"",
-1)
};

void DrawQuickAddBasicAssetsPanel()
{
GUILayout.Label("Quick Add Basic Assets", CesiumEditorStyle.subheaderStyle);
Expand Down Expand Up @@ -352,23 +260,23 @@ void DrawQuickAddIonAssetsPanel()
CesiumEditorStyle.quickAddIcon,
"Add this item to the level");

for (int i = 0; i < this._ionAssets.Length; i++)
List<QuickAddItem> assets = CesiumIonServerManager.instance.currentSession.GetQuickAddItems();
for (int i = 0; i < assets.Count; i++)
{
GUILayout.BeginHorizontal(CesiumEditorStyle.quickAddItemStyle);
GUILayout.Box(new GUIContent(
this._ionAssets[i].name,
this._ionAssets[i].tooltip),
assets[i].name,
assets[i].tooltip),
EditorStyles.wordWrappedLabel);
GUILayout.FlexibleSpace();
if (GUILayout.Button(addButtonContent, CesiumEditorStyle.quickAddButtonStyle))
{
this.QuickAddAsset(this._ionAssets[i]);
this.QuickAddAsset(assets[i]);
}
GUILayout.EndHorizontal();
}
}


void DrawIonLoginPanel()
{
Texture2D logo = EditorGUIUtility.isProSkin ?
Expand Down
2 changes: 2 additions & 0 deletions Editor/CesiumIonSession.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using Reinterop;

namespace CesiumForUnity
Expand Down Expand Up @@ -48,6 +49,7 @@ public CesiumIonSession(CesiumIonServer server)
public partial string GetProfileUsername();
public partial string GetAuthorizeUrl();
public partial string GetRedirectUrl();
public partial List<QuickAddItem> GetQuickAddItems();

public partial void Tick();

Expand Down
15 changes: 15 additions & 0 deletions Editor/ConfigureReinterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ public void ExposeToCPP()
session.IsConnected();
server = session.server;
session.server = server;

List<QuickAddItem> items = new List<QuickAddItem>();
items = session.GetQuickAddItems();

QuickAddItem item = new QuickAddItem();
item.type = QuickAddItemType.BlankTileset;
item.name = "name";
item.tooltip = "tooltip";
item.tilesetName = "tilesetName";
item.tilesetId = 1;
item.overlayName = "overlayName";
item.overlayId = 2;

item = new QuickAddItem(QuickAddItemType.IonTileset, "name", "tooltip", "tilesetName", 1, "overlayName", 2);
items.Add(item);

server.defaultIonAccessToken = "";
server.defaultIonAccessTokenId = "";
Expand Down
42 changes: 42 additions & 0 deletions Editor/QuickAddItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace CesiumForUnity
{
public enum QuickAddItemType
{
BlankTileset,
DynamicCamera,
IonTileset
}

public class QuickAddItem
{
public QuickAddItemType type;
public string name;
public string tooltip;
public string tilesetName;
public long tilesetId;
public string overlayName;
public long overlayId;

public QuickAddItem()
{
}

public QuickAddItem(
QuickAddItemType type,
string name,
string tooltip,
string tilesetName,
long tilesetId,
string overlayName,
long overlayId)
{
this.type = type;
this.name = name;
this.tooltip = tooltip;
this.tilesetName = tilesetName;
this.tilesetId = tilesetId;
this.overlayName = overlayName;
this.overlayId = overlayId;
}
}
}
11 changes: 11 additions & 0 deletions Editor/QuickAddItem.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions native~/Editor/src/CesiumIonSessionImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <DotNet/CesiumForUnity/CesiumIonServer.h>
#include <DotNet/CesiumForUnity/CesiumIonServerManager.h>
#include <DotNet/CesiumForUnity/CesiumIonSession.h>
#include <DotNet/CesiumForUnity/QuickAddItem.h>
#include <DotNet/CesiumForUnity/QuickAddItemType.h>
#include <DotNet/System/Object.h>
#include <DotNet/UnityEngine/Application.h>
#include <DotNet/UnityEngine/Debug.h>
Expand Down Expand Up @@ -311,6 +313,35 @@ System::String CesiumIonSessionImpl::GetRedirectUrl(
return System::String(this->_redirectUrl);
}

DotNet::System::Collections::Generic::List1<
DotNet::CesiumForUnity::QuickAddItem>
CesiumIonSessionImpl::GetQuickAddItems(
const DotNet::CesiumForUnity::CesiumIonSession& session) {
DotNet::System::Collections::Generic::List1<
DotNet::CesiumForUnity::QuickAddItem>
result{};

const CesiumIonClient::Defaults& defaults = this->getDefaults();
for (const CesiumIonClient::QuickAddAsset& asset : defaults.quickAddAssets) {
if (asset.type == "3DTILES" ||
(asset.type == "TERRAIN" && !asset.rasterOverlays.empty())) {
CesiumForUnity::QuickAddItem item(
CesiumForUnity::QuickAddItemType::IonTileset,
System::String(asset.name),
System::String(asset.description),
System::String(asset.objectName),
asset.assetId,
asset.rasterOverlays.empty()
? nullptr
: System::String(asset.rasterOverlays[0].name),
asset.rasterOverlays.empty() ? -1 : asset.rasterOverlays[0].assetId);
result.Add(item);
}
}

return result;
}

void CesiumIonSessionImpl::RefreshProfile(
const DotNet::CesiumForUnity::CesiumIonSession& session) {
this->refreshProfile();
Expand Down
4 changes: 4 additions & 0 deletions native~/Editor/src/CesiumIonSessionImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <CesiumIonClient/Profile.h>
#include <CesiumIonClient/Token.h>

#include <DotNet/System/Collections/Generic/List1.h>
#include <DotNet/System/String.h>

#include <functional>
Expand Down Expand Up @@ -72,6 +73,9 @@ class CesiumIonSessionImpl {
GetAuthorizeUrl(const DotNet::CesiumForUnity::CesiumIonSession& session);
DotNet::System::String
GetRedirectUrl(const DotNet::CesiumForUnity::CesiumIonSession& session);
DotNet::System::Collections::Generic::List1<
DotNet::CesiumForUnity::QuickAddItem>
GetQuickAddItems(const DotNet::CesiumForUnity::CesiumIonSession& session);

void RefreshProfile(const DotNet::CesiumForUnity::CesiumIonSession& session);
void RefreshAssets(const DotNet::CesiumForUnity::CesiumIonSession& session);
Expand Down

0 comments on commit b2d8956

Please sign in to comment.