-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CesiumIonServer, CesiumIonServerManager.
- Loading branch information
Showing
10 changed files
with
234 additions
and
10 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
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,95 @@ | ||
using System.Collections.Generic; | ||
using System; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace CesiumForUnity | ||
{ | ||
[FilePath("UserSettings/CesiumIonServerManager.asset", FilePathAttribute.Location.ProjectFolder)] | ||
public class CesiumIonServerManager : ScriptableSingleton<CesiumIonServerManager> | ||
{ | ||
public CesiumIonServer Current | ||
{ | ||
get | ||
{ | ||
if (this._currentCesiumIonServer == null) | ||
{ | ||
this._currentCesiumIonServer = CesiumIonServer.defaultServer; | ||
|
||
// For backward compatibility, look for an existing user access token in the EditorPrefs | ||
// and move it to the user access token map. | ||
if (string.IsNullOrEmpty(this.GetUserAccessToken(this._currentCesiumIonServer))) | ||
{ | ||
const string editorPrefKey = "CesiumUserAccessToken"; | ||
string userAccessToken = EditorPrefs.GetString(editorPrefKey); | ||
if (!string.IsNullOrEmpty(userAccessToken)) | ||
{ | ||
this.SetUserAccessToken(this._currentCesiumIonServer, userAccessToken); | ||
EditorPrefs.DeleteKey(editorPrefKey); | ||
} | ||
} | ||
|
||
} | ||
return this._currentCesiumIonServer; | ||
} | ||
} | ||
|
||
public CesiumIonSession CurrentSession | ||
{ | ||
get | ||
{ | ||
return this.GetSession(this.Current); | ||
} | ||
} | ||
|
||
public CesiumIonSession GetSession(CesiumIonServer server) | ||
{ | ||
CesiumIonSession session; | ||
if (!this._sessions.TryGetValue(server, out session)) | ||
{ | ||
session = new CesiumIonSession(server); | ||
this._sessions.Add(server, session); | ||
} | ||
return session; | ||
} | ||
|
||
private string GetUserAccessToken(CesiumIonServer server) | ||
{ | ||
int index = this._userAccessTokenMap.FindIndex(record => record.server == server); | ||
return index >= 0 ? this._userAccessTokenMap[index].token : null; | ||
} | ||
|
||
private void SetUserAccessToken(CesiumIonServer server, string token) | ||
{ | ||
int index = this._userAccessTokenMap.FindIndex(record => record.server == server); | ||
if (index >= 0) | ||
{ | ||
this._userAccessTokenMap[index].token = token; | ||
} | ||
else | ||
{ | ||
UserAccessTokenRecord record = new UserAccessTokenRecord(); | ||
record.server = server; | ||
record.token = token; | ||
this._userAccessTokenMap.Add(record); | ||
} | ||
|
||
this.Save(true); | ||
} | ||
|
||
[Serializable] | ||
private class UserAccessTokenRecord | ||
{ | ||
public CesiumIonServer server; | ||
public string token; | ||
} | ||
|
||
[SerializeField] | ||
private List<UserAccessTokenRecord> _userAccessTokenMap = new List<UserAccessTokenRecord>(); | ||
|
||
[SerializeField] | ||
private CesiumIonServer _currentCesiumIonServer; | ||
|
||
private Dictionary<CesiumIonServer, CesiumIonSession> _sessions = new Dictionary<CesiumIonServer, CesiumIonSession>(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace CesiumForUnity | ||
{ | ||
public class CesiumIonServerUI | ||
{ | ||
public static void Selector() | ||
{ | ||
|
||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace CesiumForUnity | ||
{ | ||
/// <summary> | ||
/// Defines a Cesium ion Server. This may be the public (SaaS) Cesium ion server at | ||
/// ion.cesium.com, or it may be a self-hosted instance. | ||
/// </summary> | ||
[CreateAssetMenu(fileName = "CesiumIonServer", menuName = "Cesium/Cesium ion Server")] | ||
public class CesiumIonServer : ScriptableObject | ||
{ | ||
/// <summary> | ||
/// The main URL of the Cesium ion server. For example, the server URL for the | ||
/// public Cesium ion is https://ion.cesium.com. | ||
/// </summary> | ||
public string serverUrl = "https://ion.cesium.com"; | ||
|
||
/// <summary> | ||
/// The URL of the main API endpoint of the Cesium ion server. For example, for | ||
/// the default, public Cesium ion server, this is `https://api.cesium.com`. If | ||
/// left blank, the API URL is automatically inferred from the Server URL. | ||
/// </summary> | ||
public string apiUrl = "https://api.cesium.com"; | ||
|
||
/// <summary> | ||
/// The application ID to use to log in to this server using OAuth2. This | ||
/// OAuth2 application must be configured on the server with the exact URL | ||
/// `http://127.0.0.1/cesium-for-unreal/oauth2/callback`. | ||
/// </summary> | ||
public long oauth2ApplicationID = 190; | ||
|
||
/// <summary> | ||
/// The ID of the default access token to use to access Cesium ion assets at | ||
/// runtime. This property may be an empty string, in which case the ID is | ||
/// found by searching the logged-in Cesium ion account for the | ||
/// DefaultIonAccessToken. | ||
/// </summary> | ||
public string defaultIonAccessTokenId; | ||
|
||
/// <summary> | ||
/// The default token used to access Cesium ion assets at runtime. This token | ||
/// is embedded in packaged games for use at runtime. | ||
/// </summary> | ||
public string defaultIonAccessToken; | ||
|
||
/// <summary> | ||
/// Gets the default Cesium ion Server (ion.cesium.com). | ||
/// </summary> | ||
/// <remarks> | ||
/// It is expected to be found at `Assets/CesiumSettings/CesiumIonServers/ion.cesium.com`. | ||
/// In the Editor, it will be created if it does not already exist, so this method always | ||
/// returns a valid instance. At runtime, this method returns null if the object does not | ||
/// exist. | ||
/// </remarks> | ||
public static CesiumIonServer defaultServer | ||
{ | ||
get | ||
{ | ||
CesiumIonServer result = Resources.Load<CesiumIonServer>("CesiumIonServers/ion.cesium.com"); | ||
|
||
#if UNITY_EDITOR | ||
if (result == null) | ||
{ | ||
if (!AssetDatabase.IsValidFolder("Assets/CesiumSettings")) | ||
AssetDatabase.CreateFolder("Assets", "CesiumSettings"); | ||
if (!AssetDatabase.IsValidFolder("Assets/CesiumSettings/Resources")) | ||
AssetDatabase.CreateFolder("Assets/CesiumSettings", "Resources"); | ||
if (!AssetDatabase.IsValidFolder("Assets/CesiumSettings/Resources/CesiumIonServers")) | ||
AssetDatabase.CreateFolder("Assets/CesiumSettings/Resources", "CesiumIonServers"); | ||
result = ScriptableObject.CreateInstance<CesiumIonServer>(); | ||
AssetDatabase.CreateAsset(result, "Assets/CesiumSettings/Resources/CesiumIonServers/ion.cesium.com.asset"); | ||
AssetDatabase.Refresh(); | ||
} | ||
#endif | ||
|
||
return result; | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.