Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,8 @@ crashlytics-build.properties
# Additional Rivet items
**/.DS_Store
/ProjectSettings

# Other items that come up
mono_crash.*
Assets/Resources
Assets/Resources.meta
3 changes: 2 additions & 1 deletion Assets/Rivet/Editor/BuildPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public void OnPreprocessBuild(BuildReport report)
{
// Create the asset file before the build
RivetSettings data = ScriptableObject.CreateInstance<RivetSettings>();
// data.SomeData = "Some data from the plugin";
data.ApiEndpoint = ExtensionData.ApiEndpoint;
data.RivetToken = ExtensionData.RivetToken;
AssetDatabase.CreateAsset(data, "Assets/rivet_export.asset");
AssetDatabase.SaveAssets();
}
Expand Down
24 changes: 24 additions & 0 deletions Assets/Rivet/Editor/RivetPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,34 @@
using System.IO;
using Newtonsoft.Json.Linq;

public static class ExtensionData
{
public static string RivetToken { get; set; }
private static string apiEndpoint = "https://api.rivet.gg";

public static string ApiEndpoint
{
get { return apiEndpoint; }
set { apiEndpoint = value; }
}
}

namespace Rivet
{
public class RivetPluginWindow : EditorWindow
{
public string ApiEndpoint
{
get { return ExtensionData.ApiEndpoint; }
set { ExtensionData.ApiEndpoint = value; }
}

public string RivetToken
{
get { return ExtensionData.RivetToken; }
set { ExtensionData.RivetToken = value; }
}

// Define an interface for the states
public interface IState
{
Expand Down
21 changes: 12 additions & 9 deletions Assets/Rivet/Editor/Windows/Login.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Login : RivetPluginWindow.IState
public RivetPluginWindow window;
public string url;
bool loginButtonEnabled = true;
private bool showAdvancedOptions = false;

public Login()
{
Expand Down Expand Up @@ -46,10 +47,6 @@ public void OnEnter(RivetPluginWindow pluginWindow)

public void OnGUI()
{
// Display the URL text box and the Link button
EditorGUILayout.LabelField("Enter the URL:");
url = EditorGUILayout.TextField(url);

UnityEditor.EditorGUI.BeginDisabledGroup(!loginButtonEnabled);

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

// var api_address = apiEndpointLineEdit.Text; // replace with your actual control
var api_address = "https://api.rivet.gg";

var getLinkResult = RivetCLI.RunCommand(
"--api-endpoint",
api_address,
window.ApiEndpoint,
"sidekick",
"get-link");

Expand All @@ -91,7 +85,7 @@ public void OnGUI()
// Long-poll the Rivet API until the user has logged in
var waitForLoginResult = RivetCLI.RunCommand(
"--api-endpoint",
api_address,
window.ApiEndpoint,
"sidekick",
"wait-for-login",
"--device-link-token",
Expand Down Expand Up @@ -137,6 +131,15 @@ public void OnGUI()

UnityEditor.EditorGUI.EndDisabledGroup();

// Display the Advanced Options dropdown
showAdvancedOptions = EditorGUILayout.Foldout(showAdvancedOptions, "Advanced Options");

if (showAdvancedOptions)
{
// Display the API Endpoint text box
EditorGUILayout.LabelField("API Endpoint:");
window.ApiEndpoint = EditorGUILayout.TextField(window.ApiEndpoint);
}
}
}
}
47 changes: 23 additions & 24 deletions Assets/Rivet/Editor/Windows/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@

public struct BootstrapData
{
[JsonProperty("api_endpoint")] public string ApiEndpoint;
public string ApiEndpoint
{
get { return ExtensionData.ApiEndpoint; }
set { ExtensionData.ApiEndpoint = value; }
}

[JsonProperty("game_id")] public string GameId;
[JsonProperty("token")] public string Token;
}
Expand Down Expand Up @@ -356,31 +361,25 @@ public void OnGUI()
/// </summary>
private void GetNamespaceToken()
{
new System.Threading.Thread(() =>
{
var command = thisMachineSelected ? "get-namespace-development-token" : "get-namespace-public-token";
var namespaceId = gameData.namespaces[selectedIndex].Item1.name_id;
var command = thisMachineSelected ? "get-namespace-development-token" : "get-namespace-public-token";
var namespaceId = gameData.namespaces[selectedIndex].Item1.name_id;

var result = RivetCLI.RunCommand("sidekick", command, "--namespace", namespaceId);

switch (result)
{
case SuccessResult<JObject> successResult:
var token = successResult.Data["Ok"]["token"].ToString();
UnityEngine.Debug.Log("Rivet Token: " + token);
rivetEditorToken = token;
UnityEditor.EditorApplication.delayCall += () =>
{
PlayerPrefs.SetString("RIVET_EDITOR_TOKEN", token);
Debug.Log("Saved token to PlayerPrefs");
};
break;
case ErrorResult<JObject> errorResult:
UnityEngine.Debug.LogError(errorResult.Message);
break;
}
var result = RivetCLI.RunCommand("sidekick", command, "--namespace", namespaceId);

}).Start();
switch (result)
{
case SuccessResult<JObject> successResult:
var token = successResult.Data["Ok"]["token"].ToString();
window.RivetToken = token;
UnityEditor.EditorApplication.delayCall += () =>
{
PlayerPrefs.SetString("RIVET_EDITOR_TOKEN", token);
};
break;
case ErrorResult<JObject> errorResult:
UnityEngine.Debug.LogError(errorResult.Message);
break;
}
}
}
}
28 changes: 16 additions & 12 deletions Assets/Rivet/Runtime/RivetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,20 @@ public struct RivetPlayer
[CreateAssetMenu(fileName = "RivetSettings", menuName = "ScriptableObjects/RivetSettings", order = 1)]
public class RivetSettings : ScriptableObject
{
public string? rivetToken;
public string? RivetToken;
public string? ApiEndpoint;
}

public class RivetManager : MonoBehaviour
{
const string MatchmakerApiEndpoint = "https://api.rivet.gg/matchmaker";
[HideInInspector]
public string? RivetToken = null;

[HideInInspector]
public string? ApiEndpoint = null;

[HideInInspector]
public string? rivetToken = null;
public string? MatchmakerApiEndpoint => ApiEndpoint + "/matchmaker";

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

private void Start()
{
Debug.Log("RivetManager.Start");
// Try to set the Rivet Token from the asset if it exists
if (rivetToken == null || rivetToken.Length == 0)
{
// Try to load Rivet runtime settings
var rivetSettings = Resources.Load<RivetSettings>("RivetSettings");
if (rivetSettings != null)
{
Debug.Log("RivetSettings: " + rivetSettings.rivetToken);
rivetToken = rivetSettings.rivetToken;
Debug.Log("RivetSettings: " + rivetSettings.RivetToken);
RivetToken = rivetSettings.RivetToken;

Debug.Log("RivetSettings: " + rivetSettings.ApiEndpoint);
ApiEndpoint = rivetSettings.ApiEndpoint;
}
}
}

#region API: Matchmaker.Lobbies
Expand Down Expand Up @@ -257,9 +261,9 @@ private string GetToken()
return value;
}

if (rivetToken != null && rivetToken.Length > 0)
if (RivetToken != null && RivetToken.Length > 0)
{
return rivetToken;
return RivetToken;
}

throw new Exception("RIVET_TOKEN not set");
Expand Down