-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1 @@ | ||
using Mirror.Cloud.ListServerService; | ||
using UnityEngine; | ||
|
||
namespace Mirror.Cloud | ||
{ | ||
/// <summary> | ||
/// Used to requests and responses from the mirror api | ||
/// </summary> | ||
public interface IApiConnector | ||
{ | ||
ListServer ListServer { get; } | ||
} | ||
|
||
/// <summary> | ||
/// Used to requests and responses from the mirror api | ||
/// </summary> | ||
[DisallowMultipleComponent] | ||
[AddComponentMenu("Network/CloudServices/ApiConnector")] | ||
[HelpURL("https://mirror-networking.com/docs/api/Mirror.Cloud.ApiConnector.html")] | ||
public class ApiConnector : MonoBehaviour, IApiConnector, ICoroutineRunner | ||
{ | ||
#region Inspector | ||
[Header("Settings")] | ||
|
||
[Tooltip("Base URL of api, including https")] | ||
[SerializeField] string ApiAddress = ""; | ||
|
||
[Tooltip("Api key required to access api")] | ||
[SerializeField] string ApiKey = ""; | ||
|
||
[Header("Events")] | ||
|
||
[Tooltip("Triggered when server list updates")] | ||
[SerializeField] ServerListEvent _onServerListUpdated = new ServerListEvent(); | ||
#endregion | ||
|
||
IRequestCreator requestCreator; | ||
|
||
public ListServer ListServer { get; private set; } | ||
|
||
void Awake() | ||
{ | ||
requestCreator = new RequestCreator(ApiAddress, ApiKey, this); | ||
|
||
InitListServer(); | ||
} | ||
|
||
void InitListServer() | ||
{ | ||
IListServerServerApi serverApi = new ListServerServerApi(this, requestCreator); | ||
IListServerClientApi clientApi = new ListServerClientApi(this, requestCreator, _onServerListUpdated); | ||
ListServer = new ListServer(serverApi, clientApi); | ||
} | ||
|
||
public void OnDestroy() | ||
{ | ||
ListServer?.ServerApi.Shutdown(); | ||
ListServer?.ClientApi.Shutdown(); | ||
} | ||
} | ||
} | ||
// removed 2021-05-13 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1 @@ | ||
using System; | ||
|
||
namespace Mirror.Cloud | ||
{ | ||
public interface IBaseApi | ||
{ | ||
/// <summary> | ||
/// Cleans up any data created by the instance | ||
/// <para>For Example: removing server from list</para> | ||
/// </summary> | ||
void Shutdown(); | ||
} | ||
|
||
public abstract class BaseApi | ||
{ | ||
protected readonly ICoroutineRunner runner; | ||
protected readonly IRequestCreator requestCreator; | ||
|
||
protected BaseApi(ICoroutineRunner runner, IRequestCreator requestCreator) | ||
{ | ||
this.runner = runner ?? throw new ArgumentNullException(nameof(runner)); | ||
this.requestCreator = requestCreator ?? throw new ArgumentNullException(nameof(requestCreator)); | ||
} | ||
} | ||
} | ||
// removed 2021-05-13 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1 @@ | ||
using System; | ||
using Mirror.Cloud.ListServerService; | ||
using UnityEngine.Events; | ||
|
||
namespace Mirror.Cloud | ||
{ | ||
[Serializable] | ||
public class ServerListEvent : UnityEvent<ServerCollectionJson> {} | ||
|
||
[Serializable] | ||
public class MatchFoundEvent : UnityEvent<ServerJson> {} | ||
} | ||
// removed 2021-05-13 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1 @@ | ||
using UnityEngine.Networking; | ||
|
||
namespace Mirror.Cloud | ||
{ | ||
public static class Extensions | ||
{ | ||
public static bool IsOk(this UnityWebRequest webRequest) | ||
{ | ||
return 200 <= webRequest.responseCode && webRequest.responseCode <= 299; | ||
} | ||
} | ||
} | ||
// removed 2021-05-13 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1 @@ | ||
using System.Collections; | ||
using UnityEngine; | ||
|
||
namespace Mirror.Cloud | ||
{ | ||
public interface ICoroutineRunner : IUnityEqualCheck | ||
{ | ||
Coroutine StartCoroutine(IEnumerator routine); | ||
void StopCoroutine(IEnumerator routine); | ||
void StopCoroutine(Coroutine routine); | ||
} | ||
} | ||
// removed 2021-05-13 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1 @@ | ||
using System.Collections; | ||
using UnityEngine.Networking; | ||
|
||
namespace Mirror.Cloud | ||
{ | ||
public delegate void RequestSuccess(string responseBody); | ||
|
||
public delegate void RequestFail(string responseBody); | ||
|
||
/// <summary> | ||
/// Objects that can be sent to the Api must have this interface | ||
/// </summary> | ||
public interface ICanBeJson {} | ||
|
||
/// <summary> | ||
/// Methods to create and send UnityWebRequest | ||
/// </summary> | ||
public interface IRequestCreator | ||
{ | ||
UnityWebRequest Delete(string page); | ||
UnityWebRequest Get(string page); | ||
UnityWebRequest Patch<T>(string page, T json) where T : struct, ICanBeJson; | ||
UnityWebRequest Post<T>(string page, T json) where T : struct, ICanBeJson; | ||
|
||
/// <summary> | ||
/// Sends Request to api and invokes callback when finished | ||
/// <para>Starts Coroutine of SendRequestEnumerator</para> | ||
/// </summary> | ||
/// <param name="request"></param> | ||
/// <param name="onSuccess"></param> | ||
/// <param name="onFail"></param> | ||
void SendRequest(UnityWebRequest request, RequestSuccess onSuccess = null, RequestFail onFail = null); | ||
/// <summary> | ||
/// Sends Request to api and invokes callback when finished | ||
/// </summary> | ||
/// <param name="request"></param> | ||
/// <param name="onSuccess"></param> | ||
/// <param name="onFail"></param> | ||
/// <returns></returns> | ||
IEnumerator SendRequestEnumerator(UnityWebRequest request, RequestSuccess onSuccess = null, RequestFail onFail = null); | ||
} | ||
} | ||
// removed 2021-05-13 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.