Skip to content

Commit f6307e7

Browse files
committed
fix: Properly include RivetToken and ApiEndpoint with game build (#7)
Closes UTY-27, closes UTY-16, closes UTY-25, closes UTY-23, closes UTY-21.
1 parent 8b3a233 commit f6307e7

6 files changed

Lines changed: 82 additions & 46 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,8 @@ crashlytics-build.properties
7474
# Additional Rivet items
7575
**/.DS_Store
7676
/ProjectSettings
77+
78+
# Other items that come up
79+
mono_crash.*
80+
Assets/Resources
81+
Assets/Resources.meta

Assets/Rivet/Editor/BuildPipeline.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ public void OnPreprocessBuild(BuildReport report)
1111
{
1212
// Create the asset file before the build
1313
RivetSettings data = ScriptableObject.CreateInstance<RivetSettings>();
14-
// data.SomeData = "Some data from the plugin";
14+
data.ApiEndpoint = ExtensionData.ApiEndpoint;
15+
data.RivetToken = ExtensionData.RivetToken;
1516
AssetDatabase.CreateAsset(data, "Assets/rivet_export.asset");
1617
AssetDatabase.SaveAssets();
1718
}

Assets/Rivet/Editor/RivetPlugin.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,34 @@
66
using System.IO;
77
using Newtonsoft.Json.Linq;
88

9+
public static class ExtensionData
10+
{
11+
public static string RivetToken { get; set; }
12+
private static string apiEndpoint = "https://api.rivet.gg";
13+
14+
public static string ApiEndpoint
15+
{
16+
get { return apiEndpoint; }
17+
set { apiEndpoint = value; }
18+
}
19+
}
20+
921
namespace Rivet
1022
{
1123
public class RivetPluginWindow : EditorWindow
1224
{
25+
public string ApiEndpoint
26+
{
27+
get { return ExtensionData.ApiEndpoint; }
28+
set { ExtensionData.ApiEndpoint = value; }
29+
}
30+
31+
public string RivetToken
32+
{
33+
get { return ExtensionData.RivetToken; }
34+
set { ExtensionData.RivetToken = value; }
35+
}
36+
1337
// Define an interface for the states
1438
public interface IState
1539
{

Assets/Rivet/Editor/Windows/Login.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class Login : RivetPluginWindow.IState
1010
public RivetPluginWindow window;
1111
public string url;
1212
bool loginButtonEnabled = true;
13+
private bool showAdvancedOptions = false;
1314

1415
public Login()
1516
{
@@ -46,10 +47,6 @@ public void OnEnter(RivetPluginWindow pluginWindow)
4647

4748
public void OnGUI()
4849
{
49-
// Display the URL text box and the Link button
50-
EditorGUILayout.LabelField("Enter the URL:");
51-
url = EditorGUILayout.TextField(url);
52-
5350
UnityEditor.EditorGUI.BeginDisabledGroup(!loginButtonEnabled);
5451

5552
if (GUILayout.Button("Sign in to Rivet"))
@@ -59,12 +56,9 @@ public void OnGUI()
5956
// Disable the button sign in button
6057
loginButtonEnabled = false;
6158

62-
// var api_address = apiEndpointLineEdit.Text; // replace with your actual control
63-
var api_address = "https://api.rivet.gg";
64-
6559
var getLinkResult = RivetCLI.RunCommand(
6660
"--api-endpoint",
67-
api_address,
61+
window.ApiEndpoint,
6862
"sidekick",
6963
"get-link");
7064

@@ -91,7 +85,7 @@ public void OnGUI()
9185
// Long-poll the Rivet API until the user has logged in
9286
var waitForLoginResult = RivetCLI.RunCommand(
9387
"--api-endpoint",
94-
api_address,
88+
window.ApiEndpoint,
9589
"sidekick",
9690
"wait-for-login",
9791
"--device-link-token",
@@ -137,6 +131,15 @@ public void OnGUI()
137131

138132
UnityEditor.EditorGUI.EndDisabledGroup();
139133

134+
// Display the Advanced Options dropdown
135+
showAdvancedOptions = EditorGUILayout.Foldout(showAdvancedOptions, "Advanced Options");
136+
137+
if (showAdvancedOptions)
138+
{
139+
// Display the API Endpoint text box
140+
EditorGUILayout.LabelField("API Endpoint:");
141+
window.ApiEndpoint = EditorGUILayout.TextField(window.ApiEndpoint);
142+
}
140143
}
141144
}
142145
}

Assets/Rivet/Editor/Windows/Plugin.cs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010

1111
public struct BootstrapData
1212
{
13-
[JsonProperty("api_endpoint")] public string ApiEndpoint;
13+
public string ApiEndpoint
14+
{
15+
get { return ExtensionData.ApiEndpoint; }
16+
set { ExtensionData.ApiEndpoint = value; }
17+
}
18+
1419
[JsonProperty("game_id")] public string GameId;
1520
[JsonProperty("token")] public string Token;
1621
}
@@ -356,31 +361,25 @@ public void OnGUI()
356361
/// </summary>
357362
private void GetNamespaceToken()
358363
{
359-
new System.Threading.Thread(() =>
360-
{
361-
var command = thisMachineSelected ? "get-namespace-development-token" : "get-namespace-public-token";
362-
var namespaceId = gameData.namespaces[selectedIndex].Item1.name_id;
364+
var command = thisMachineSelected ? "get-namespace-development-token" : "get-namespace-public-token";
365+
var namespaceId = gameData.namespaces[selectedIndex].Item1.name_id;
363366

364-
var result = RivetCLI.RunCommand("sidekick", command, "--namespace", namespaceId);
365-
366-
switch (result)
367-
{
368-
case SuccessResult<JObject> successResult:
369-
var token = successResult.Data["Ok"]["token"].ToString();
370-
UnityEngine.Debug.Log("Rivet Token: " + token);
371-
rivetEditorToken = token;
372-
UnityEditor.EditorApplication.delayCall += () =>
373-
{
374-
PlayerPrefs.SetString("RIVET_EDITOR_TOKEN", token);
375-
Debug.Log("Saved token to PlayerPrefs");
376-
};
377-
break;
378-
case ErrorResult<JObject> errorResult:
379-
UnityEngine.Debug.LogError(errorResult.Message);
380-
break;
381-
}
367+
var result = RivetCLI.RunCommand("sidekick", command, "--namespace", namespaceId);
382368

383-
}).Start();
369+
switch (result)
370+
{
371+
case SuccessResult<JObject> successResult:
372+
var token = successResult.Data["Ok"]["token"].ToString();
373+
window.RivetToken = token;
374+
UnityEditor.EditorApplication.delayCall += () =>
375+
{
376+
PlayerPrefs.SetString("RIVET_EDITOR_TOKEN", token);
377+
};
378+
break;
379+
case ErrorResult<JObject> errorResult:
380+
UnityEngine.Debug.LogError(errorResult.Message);
381+
break;
382+
}
384383
}
385384
}
386385
}

Assets/Rivet/Runtime/RivetManager.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,20 @@ public struct RivetPlayer
6565
[CreateAssetMenu(fileName = "RivetSettings", menuName = "ScriptableObjects/RivetSettings", order = 1)]
6666
public class RivetSettings : ScriptableObject
6767
{
68-
public string? rivetToken;
68+
public string? RivetToken;
69+
public string? ApiEndpoint;
6970
}
7071

7172
public class RivetManager : MonoBehaviour
7273
{
73-
const string MatchmakerApiEndpoint = "https://api.rivet.gg/matchmaker";
74+
[HideInInspector]
75+
public string? RivetToken = null;
76+
77+
[HideInInspector]
78+
public string? ApiEndpoint = null;
7479

7580
[HideInInspector]
76-
public string? rivetToken = null;
81+
public string? MatchmakerApiEndpoint => ApiEndpoint + "/matchmaker";
7782

7883
/// <summary>
7984
/// The response from the last <see cref="FindLobby"/> call. Used to maintain information about the Rivet player &
@@ -83,17 +88,16 @@ public class RivetManager : MonoBehaviour
8388

8489
private void Start()
8590
{
86-
Debug.Log("RivetManager.Start");
87-
// Try to set the Rivet Token from the asset if it exists
88-
if (rivetToken == null || rivetToken.Length == 0)
89-
{
91+
// Try to load Rivet runtime settings
9092
var rivetSettings = Resources.Load<RivetSettings>("RivetSettings");
9193
if (rivetSettings != null)
9294
{
93-
Debug.Log("RivetSettings: " + rivetSettings.rivetToken);
94-
rivetToken = rivetSettings.rivetToken;
95+
Debug.Log("RivetSettings: " + rivetSettings.RivetToken);
96+
RivetToken = rivetSettings.RivetToken;
97+
98+
Debug.Log("RivetSettings: " + rivetSettings.ApiEndpoint);
99+
ApiEndpoint = rivetSettings.ApiEndpoint;
95100
}
96-
}
97101
}
98102

99103
#region API: Matchmaker.Lobbies
@@ -257,9 +261,9 @@ private string GetToken()
257261
return value;
258262
}
259263

260-
if (rivetToken != null && rivetToken.Length > 0)
264+
if (RivetToken != null && RivetToken.Length > 0)
261265
{
262-
return rivetToken;
266+
return RivetToken;
263267
}
264268

265269
throw new Exception("RIVET_TOKEN not set");

0 commit comments

Comments
 (0)