88using Newtonsoft . Json ;
99using Newtonsoft . Json . Converters ;
1010using Newtonsoft . Json . Linq ;
11+ using System . IO ;
1112
1213[ JsonConverter ( typeof ( StringEnumConverter ) ) ]
1314public enum CreateLobbyRequestPublicity
@@ -61,21 +62,15 @@ public struct RivetPlayer
6162 [ JsonProperty ( "token" ) ] public string Token ;
6263}
6364
64- [ CreateAssetMenu ( fileName = "RivetSettings" , menuName = "ScriptableObjects/RivetSettings" , order = 1 ) ]
65- public class RivetSettings : ScriptableObject
65+ [ System . Serializable ]
66+ public class RivetSettings
6667{
6768 public string ? RivetToken ;
6869 public string ? ApiEndpoint ;
6970}
7071
7172public class RivetManager : MonoBehaviour
7273{
73- [ HideInInspector ]
74- public string ? RivetToken = null ;
75-
76- [ HideInInspector ]
77- public string ? ApiEndpoint = null ;
78-
7974 [ HideInInspector ]
8075 public string ? MatchmakerApiEndpoint => ApiEndpoint + "/matchmaker" ;
8176
@@ -85,15 +80,61 @@ public class RivetManager : MonoBehaviour
8580 /// </summary>
8681 public FindLobbyResponse ? FindLobbyResponse { get ; private set ; }
8782
88- private void Start ( )
83+ [ HideInInspector ]
84+ public string ? RivetToken => GetRivetToken ( ) ;
85+
86+ [ HideInInspector ]
87+ public string ? ApiEndpoint => GetApiEndpoint ( ) ;
88+
89+ private string ? GetRivetToken ( )
8990 {
90- // Try to load Rivet runtime settings
91- var rivetSettings = Resources . Load < RivetSettings > ( "RivetSettings" ) ;
92- if ( rivetSettings != null )
91+ string ? token = PlayerPrefs . GetString ( "RivetToken" ) ;
92+ if ( string . IsNullOrEmpty ( token ) )
9393 {
94- RivetToken = rivetSettings . RivetToken ;
95- ApiEndpoint = rivetSettings . ApiEndpoint ;
94+ var rivetSettings = LoadRivetSettings ( ) ;
95+ if ( rivetSettings != null )
96+ {
97+ token = rivetSettings . RivetToken ;
98+ }
9699 }
100+ return token ;
101+ }
102+
103+ private string ? GetApiEndpoint ( )
104+ {
105+ string ? endpoint = PlayerPrefs . GetString ( "ApiEndpoint" ) ;
106+ if ( string . IsNullOrEmpty ( endpoint ) )
107+ {
108+ var rivetSettings = LoadRivetSettings ( ) ;
109+ if ( rivetSettings != null )
110+ {
111+ endpoint = rivetSettings . ApiEndpoint ;
112+ }
113+ }
114+ return endpoint ;
115+ }
116+
117+ private RivetSettings ? LoadRivetSettings ( )
118+ {
119+ string filePath = Path . Combine ( Application . streamingAssetsPath , "rivet_export.json" ) ;
120+ if ( File . Exists ( filePath ) )
121+ {
122+ string json = File . ReadAllText ( filePath ) ;
123+ RivetSettings rivetSettings = JsonUtility . FromJson < RivetSettings > ( json ) ;
124+ return rivetSettings ;
125+ }
126+ else
127+ {
128+ Debug . LogError ( "File not found: " + filePath ) ;
129+ return null ;
130+ }
131+ }
132+
133+ // Start function that debugs the Rivet token and API endpoint
134+ private void Start ( )
135+ {
136+ Debug . Log ( "Rivet Token: " + RivetToken ) ;
137+ Debug . Log ( "API Endpoint: " + ApiEndpoint ) ;
97138 }
98139
99140 #region API: Matchmaker.Lobbies
0 commit comments