当前提交
0657af8f
共有 69 个文件被更改,包括 1621 次插入 和 300 次删除
-
1Assets/Scripts/Lobby/LobbyAPIInterface.cs
-
14Packages/com.unity.services.lobby/CHANGELOG.md
-
97Packages/com.unity.services.lobby/Runtime/Apis/LobbyApi.cs
-
7Packages/com.unity.services.lobby/Runtime/Apis/LobbyApiRequests.cs
-
12Packages/com.unity.services.lobby/Runtime/Configuration/Configuration.cs
-
4Packages/com.unity.services.lobby/Runtime/Http/JsonObject.cs
-
4Packages/com.unity.services.lobby/Runtime/LobbyService.cs
-
16Packages/com.unity.services.lobby/Runtime/LobbyServiceProvider.cs
-
44Packages/com.unity.services.lobby/package.json
-
15Packages/com.unity.services.relay/CHANGELOG.md
-
41Packages/com.unity.services.relay/Runtime/Apis/AllocationsApi.cs
-
104Packages/com.unity.services.relay/Runtime/Apis/AllocationsApiRequests.cs
-
12Packages/com.unity.services.relay/Runtime/Configuration/Configuration.cs
-
4Packages/com.unity.services.relay/Runtime/Http/BaseApiClient.cs
-
14Packages/com.unity.services.relay/Runtime/Http/DeserializationException.cs
-
54Packages/com.unity.services.relay/Runtime/Http/HttpClient.cs
-
13Packages/com.unity.services.relay/Runtime/Http/HttpException.cs
-
5Packages/com.unity.services.relay/Runtime/Http/IHttpClient.cs
-
4Packages/com.unity.services.relay/Runtime/Http/JsonHelpers.cs
-
58Packages/com.unity.services.relay/Runtime/Http/ResponseHandler.cs
-
25Packages/com.unity.services.relay/Runtime/Models/AllocateResponseBody.cs
-
49Packages/com.unity.services.relay/Runtime/Models/Allocation.cs
-
9Packages/com.unity.services.relay/Runtime/Models/AllocationData.cs
-
26Packages/com.unity.services.relay/Runtime/Models/AllocationRequest.cs
-
26Packages/com.unity.services.relay/Runtime/Models/ErrorResponseBody.cs
-
57Packages/com.unity.services.relay/Runtime/Models/JoinAllocation.cs
-
14Packages/com.unity.services.relay/Runtime/Models/JoinAllocationAllOf.cs
-
14Packages/com.unity.services.relay/Runtime/Models/JoinCodeData.cs
-
14Packages/com.unity.services.relay/Runtime/Models/JoinCodeRequest.cs
-
11Packages/com.unity.services.relay/Runtime/Models/JoinCodeResponseBody.cs
-
9Packages/com.unity.services.relay/Runtime/Models/JoinData.cs
-
14Packages/com.unity.services.relay/Runtime/Models/JoinRequest.cs
-
10Packages/com.unity.services.relay/Runtime/Models/JoinResponseBody.cs
-
10Packages/com.unity.services.relay/Runtime/Models/KeyValuePair.cs
-
20Packages/com.unity.services.relay/Runtime/Models/RelayServer.cs
-
37Packages/com.unity.services.relay/Runtime/Models/RelayServerEndpoint.cs
-
14Packages/com.unity.services.relay/Runtime/Models/ResponseLinks.cs
-
20Packages/com.unity.services.relay/Runtime/Models/ResponseMeta.cs
-
2Packages/com.unity.services.relay/Runtime/RelayService.cs
-
19Packages/com.unity.services.relay/Runtime/RelayServiceProvider.cs
-
4Packages/com.unity.services.relay/Runtime/Scheduler/ThreadHelper.cs
-
14Packages/com.unity.services.relay/package.json
-
4Packages/packages-lock.json
-
76Packages/com.unity.services.lobby/Third Party Notices.md
-
7Packages/com.unity.services.lobby/Third Party Notices.md.meta
-
15Packages/com.unity.services.relay/Runtime/Http/DeserializationSettings.cs
-
11Packages/com.unity.services.relay/Runtime/Http/DeserializationSettings.cs.meta
-
53Packages/com.unity.services.relay/Runtime/Http/JsonObject.cs
-
11Packages/com.unity.services.relay/Runtime/Http/JsonObject.cs.meta
-
28Packages/com.unity.services.relay/Runtime/Http/JsonObjectConverter.cs
-
11Packages/com.unity.services.relay/Runtime/Http/JsonObjectConverter.cs.meta
-
34Packages/com.unity.services.relay/Runtime/Http/ResponseDeserializationException.cs
-
11Packages/com.unity.services.relay/Runtime/Http/ResponseDeserializationException.cs.meta
-
52Packages/com.unity.services.relay/Runtime/Models/Region.cs
-
11Packages/com.unity.services.relay/Runtime/Models/Region.cs.meta
-
42Packages/com.unity.services.relay/Runtime/Models/RegionsData.cs
-
11Packages/com.unity.services.relay/Runtime/Models/RegionsData.cs.meta
-
39Packages/com.unity.services.relay/Runtime/Models/RegionsResponseBody.cs
-
11Packages/com.unity.services.relay/Runtime/Models/RegionsResponseBody.cs.meta
-
76Packages/com.unity.services.relay/Third Party Notices.md
-
7Packages/com.unity.services.relay/Third Party Notices.md.meta
-
8Packages/com.unity.services.lobby/Samples~/HelloWorld.meta
-
5Packages/com.unity.services.lobby/Samples~/HelloWorld/.sample.json
-
430Packages/com.unity.services.lobby/Samples~/HelloWorld/LobbyHelloWorld.cs
-
11Packages/com.unity.services.lobby/Samples~/HelloWorld/LobbyHelloWorld.cs.meta
-
9Packages/com.unity.services.lobby/CONTRIBUTING.md
-
7Packages/com.unity.services.lobby/CONTRIBUTING.md.meta
|
|||
{ |
|||
"name": "com.unity.services.lobby", |
|||
"displayName":"Unity Lobby", |
|||
"version": "0.2.1-preview", |
|||
"unity": "2020.3", |
|||
"description": "Client API SDK Package for communicating with the Unity Lobby service", |
|||
"dependencies": { |
|||
"com.unity.services.core": "1.1.0-pre.2", |
|||
"com.unity.modules.unitywebrequest": "1.0.0", |
|||
"com.unity.modules.unitywebrequestassetbundle": "1.0.0", |
|||
"com.unity.modules.unitywebrequestaudio": "1.0.0", |
|||
"com.unity.modules.unitywebrequesttexture": "1.0.0", |
|||
"com.unity.modules.unitywebrequestwww": "1.0.0", |
|||
"com.unity.nuget.newtonsoft-json": "2.0.0" |
|||
"name": "com.unity.services.lobby", |
|||
"displayName": "Lobby", |
|||
"version": "1.0.0-pre.2", |
|||
"unity": "2020.3", |
|||
"description": "Enable players to find, create, and join lobbies with Lobby. Add Lobby to your multiplayer game to empower players to create the gaming experiences they want. Features include Quick Join, Public Lobby, and Private Match to allow flexibility in how players want to game with each other.", |
|||
"dependencies": { |
|||
"com.unity.services.core": "1.1.0-pre.4", |
|||
"com.unity.modules.unitywebrequest": "1.0.0", |
|||
"com.unity.modules.unitywebrequestassetbundle": "1.0.0", |
|||
"com.unity.modules.unitywebrequestaudio": "1.0.0", |
|||
"com.unity.modules.unitywebrequesttexture": "1.0.0", |
|||
"com.unity.modules.unitywebrequestwww": "1.0.0", |
|||
"com.unity.nuget.newtonsoft-json": "2.0.0" |
|||
}, |
|||
"relatedPackages": { |
|||
"com.unity.services.lobby.tests": "1.0.0-pre.2" |
|||
}, |
|||
"upmCi": { |
|||
"footprint": "81d7a8922f15a5246bfe1dd090a8fe34920efa5f" |
|||
}, |
|||
"repository": { |
|||
"url": "https://github.cds.internal.unity3d.com/unity/com.unity.services.rooms.git", |
|||
"type": "git", |
|||
"revision": "d1b949fb990f301ebd08a2a7dfe4e1a8489e3a20" |
|||
}, |
|||
"samples": [ |
|||
{ |
|||
"displayName": "Hello World Sample", |
|||
"description": "This sample walks through using most of the Lobby APIs in a simple, linear way.", |
|||
"path": "Samples~/HelloWorld" |
|||
] |
|||
} |
|
|||
This package contains third-party software components governed by the license(s) indicated below: |
|||
--------- |
|||
|
|||
Component Name: Newtonsoft.Json |
|||
|
|||
License Type: MIT |
|||
|
|||
The MIT License (MIT) |
|||
|
|||
Copyright (c) 2007 James Newton-King |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|||
|
|||
|
|||
<hr> |
|||
|
|||
|
|||
Component Name: Json.Net.Unity3D |
|||
|
|||
License Type: MIT |
|||
|
|||
The MIT License (MIT) |
|||
|
|||
Copyright (c) Copyright (c) 2016 SaladLab |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|||
|
|||
|
|||
<hr> |
|||
|
|||
|
|||
Component Name: Newtonsoft.Json-for-Unity |
|||
|
|||
License Type: MIT |
|||
|
|||
The MIT License (MIT) |
|||
|
|||
Copyright (c) Copyright (c) 2019 Kalle Jillheden (jilleJr) |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|||
|
|||
|
|||
<hr> |
|||
|
|||
|
|||
Component Name: com.newtonsoft.json |
|||
|
|||
License Type: MIT |
|||
|
|||
MIT License |
|||
|
|||
Copyright (c) 2019 Mike Wuetherick |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
of this software and associated documentation files (the "Software"), to deal |
|||
in the Software without restriction, including without limitation the rights |
|||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
copies of the Software, and to permit persons to whom the Software is |
|||
furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all |
|||
copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
|||
fileFormatVersion: 2 |
|||
guid: 941f0de9f9074c74485555365dd5c67c |
|||
TextScriptImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
|
|||
namespace Unity.Services.Relay.Http |
|||
{ |
|||
public enum MissingMemberHandling |
|||
{ |
|||
Error, |
|||
Ignore |
|||
} |
|||
public class DeserializationSettings |
|||
{ |
|||
public MissingMemberHandling MissingMemberHandling = MissingMemberHandling.Error; |
|||
} |
|||
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b764d3594d93a411cbcdfc89f56291e6 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using Newtonsoft.Json; |
|||
using Newtonsoft.Json.Converters; |
|||
using Newtonsoft.Json.Utilities; |
|||
using UnityEngine; |
|||
|
|||
namespace Unity.Services.Relay.Http |
|||
{ |
|||
public class JsonObject |
|||
{ |
|||
internal JsonObject(object obj) |
|||
{ |
|||
this.obj = obj; |
|||
} |
|||
|
|||
internal object obj; |
|||
|
|||
public string GetAsString() |
|||
{ |
|||
try |
|||
{ |
|||
return JsonConvert.SerializeObject(obj); |
|||
} |
|||
catch (System.Exception) |
|||
{ |
|||
throw new System.Exception("Failed to convert JsonObject to string."); |
|||
} |
|||
} |
|||
|
|||
public T GetAs<T>(DeserializationSettings deserializationSettings = null) |
|||
{ |
|||
// Check if derializationSettings is null so we can use the default value.
|
|||
deserializationSettings = deserializationSettings ?? new DeserializationSettings(); |
|||
JsonSerializerSettings jsonSettings = new JsonSerializerSettings |
|||
{ |
|||
MissingMemberHandling = deserializationSettings.MissingMemberHandling == MissingMemberHandling.Error |
|||
? Newtonsoft.Json.MissingMemberHandling.Error |
|||
: Newtonsoft.Json.MissingMemberHandling.Ignore |
|||
}; |
|||
try |
|||
{ |
|||
return JsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(obj), jsonSettings); |
|||
} |
|||
catch (Newtonsoft.Json.JsonSerializationException e) |
|||
{ |
|||
throw new DeserializationException(e.Message); |
|||
} |
|||
catch (System.Exception) |
|||
{ |
|||
throw new DeserializationException("Unable to deserialize object."); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a60146f44cbeb488fbe04186676cc4fa |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using Newtonsoft.Json; |
|||
using Newtonsoft.Json.Converters; |
|||
using Newtonsoft.Json.Linq; |
|||
using Newtonsoft.Json.Utilities; |
|||
using UnityEngine; |
|||
|
|||
namespace Unity.Services.Relay.Http |
|||
{ |
|||
class JsonObjectConverter : JsonConverter |
|||
{ |
|||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) |
|||
{ |
|||
JsonObject jobj = (JsonObject) value; |
|||
JToken t = JToken.FromObject(jobj.obj); |
|||
t.WriteTo(writer); |
|||
} |
|||
|
|||
public override object ReadJson(JsonReader reader, System.Type objectType, object existingValue, JsonSerializer serializer) |
|||
{ |
|||
throw new System.NotImplementedException(); |
|||
} |
|||
|
|||
public override bool CanConvert(System.Type objectType) |
|||
{ |
|||
throw new System.NotImplementedException(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4ad4ebc6198cd46b1baa3e32d92e397f |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
|
|||
namespace Unity.Services.Relay.Http |
|||
{ |
|||
[Serializable] |
|||
public class ResponseDeserializationException : Exception |
|||
{ |
|||
public HttpClientResponse response; |
|||
|
|||
public ResponseDeserializationException() : base() |
|||
{ |
|||
} |
|||
|
|||
public ResponseDeserializationException(string message) : base(message) |
|||
{ |
|||
} |
|||
|
|||
ResponseDeserializationException(string message, Exception inner) : base(message, inner) |
|||
{ |
|||
} |
|||
|
|||
public ResponseDeserializationException(HttpClientResponse httpClientResponse) : base( |
|||
"Unable to Deserialize Http Client Response") |
|||
{ |
|||
response = httpClientResponse; |
|||
} |
|||
|
|||
public ResponseDeserializationException(HttpClientResponse httpClientResponse, string message) : base( |
|||
message) |
|||
{ |
|||
response = httpClientResponse; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 01df1d96af8bd43a29e815eaeff7078c |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine.Scripting; |
|||
using System.Runtime.Serialization; |
|||
using Newtonsoft.Json; |
|||
using Newtonsoft.Json.Converters; |
|||
using Unity.Services.Relay.Http; |
|||
|
|||
|
|||
|
|||
namespace Unity.Services.Relay.Models |
|||
{ |
|||
/// <summary>
|
|||
/// Region model
|
|||
/// <param name="id">The region id used in allocation requests</param>
|
|||
/// <param name="description">A human readable description of the region. May include geographical information, for example, city name, country.</param>
|
|||
/// </summary>
|
|||
|
|||
[Preserve] |
|||
[DataContract(Name = "Region")] |
|||
public class Region |
|||
{ |
|||
/// <summary>
|
|||
/// Creates an instance of Region.
|
|||
/// </summary>
|
|||
/// <param name="id">The region id used in allocation requests</param>
|
|||
/// <param name="description">A human readable description of the region. May include geographical information, for example, city name, country.</param>
|
|||
[Preserve] |
|||
public Region(string id, string description) |
|||
{ |
|||
Id = id; |
|||
Description = description; |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// The region id used in allocation requests
|
|||
/// </summary>
|
|||
[Preserve] |
|||
[DataMember(Name = "id", IsRequired = true, EmitDefaultValue = true)] |
|||
public string Id{ get; } |
|||
|
|||
/// <summary>
|
|||
/// A human readable description of the region. May include geographical information, for example, city name, country.
|
|||
/// </summary>
|
|||
[Preserve] |
|||
[DataMember(Name = "description", IsRequired = true, EmitDefaultValue = true)] |
|||
public string Description{ get; } |
|||
|
|||
} |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 98d7b6730e60f46d18f239388c08878f |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine.Scripting; |
|||
using System.Runtime.Serialization; |
|||
using Newtonsoft.Json; |
|||
using Newtonsoft.Json.Converters; |
|||
using Unity.Services.Relay.Http; |
|||
|
|||
|
|||
|
|||
namespace Unity.Services.Relay.Models |
|||
{ |
|||
/// <summary>
|
|||
/// RegionsData model
|
|||
/// <param name="regions">Regions where relay servers might be available</param>
|
|||
/// </summary>
|
|||
|
|||
[Preserve] |
|||
[DataContract(Name = "RegionsData")] |
|||
public class RegionsData |
|||
{ |
|||
/// <summary>
|
|||
/// Creates an instance of RegionsData.
|
|||
/// </summary>
|
|||
/// <param name="regions">Regions where relay servers might be available</param>
|
|||
[Preserve] |
|||
public RegionsData(List<Region> regions) |
|||
{ |
|||
Regions = regions; |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// Regions where relay servers might be available
|
|||
/// </summary>
|
|||
[Preserve] |
|||
[DataMember(Name = "regions", IsRequired = true, EmitDefaultValue = true)] |
|||
public List<Region> Regions{ get; } |
|||
|
|||
} |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: f091fa486ae964cd89ed99c055575d21 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine.Scripting; |
|||
using System.Runtime.Serialization; |
|||
using Newtonsoft.Json; |
|||
using Newtonsoft.Json.Converters; |
|||
using Unity.Services.Relay.Http; |
|||
|
|||
|
|||
|
|||
namespace Unity.Services.Relay.Models |
|||
{ |
|||
/// <summary>
|
|||
/// RegionsResponseBody model
|
|||
/// <param name="data">data param</param>
|
|||
/// </summary>
|
|||
|
|||
[Preserve] |
|||
[DataContract(Name = "RegionsResponseBody")] |
|||
public class RegionsResponseBody |
|||
{ |
|||
/// <summary>
|
|||
/// Creates an instance of RegionsResponseBody.
|
|||
/// </summary>
|
|||
/// <param name="data">data param</param>
|
|||
[Preserve] |
|||
public RegionsResponseBody(RegionsData data) |
|||
{ |
|||
Data = data; |
|||
} |
|||
|
|||
|
|||
[Preserve] |
|||
[DataMember(Name = "data", IsRequired = true, EmitDefaultValue = true)] |
|||
public RegionsData Data{ get; } |
|||
|
|||
} |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 013db46fafeb3453193d41d72005b408 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
This package contains third-party software components governed by the license(s) indicated below: |
|||
--------- |
|||
|
|||
Component Name: Newtonsoft.Json |
|||
|
|||
License Type: MIT |
|||
|
|||
The MIT License (MIT) |
|||
|
|||
Copyright (c) 2007 James Newton-King |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|||
|
|||
|
|||
<hr> |
|||
|
|||
|
|||
Component Name: Json.Net.Unity3D |
|||
|
|||
License Type: MIT |
|||
|
|||
The MIT License (MIT) |
|||
|
|||
Copyright (c) Copyright (c) 2016 SaladLab |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|||
|
|||
|
|||
<hr> |
|||
|
|||
|
|||
Component Name: Newtonsoft.Json-for-Unity |
|||
|
|||
License Type: MIT |
|||
|
|||
The MIT License (MIT) |
|||
|
|||
Copyright (c) Copyright (c) 2019 Kalle Jillheden (jilleJr) |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|||
|
|||
|
|||
<hr> |
|||
|
|||
|
|||
Component Name: com.newtonsoft.json |
|||
|
|||
License Type: MIT |
|||
|
|||
MIT License |
|||
|
|||
Copyright (c) 2019 Mike Wuetherick |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
of this software and associated documentation files (the "Software"), to deal |
|||
in the Software without restriction, including without limitation the rights |
|||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
copies of the Software, and to permit persons to whom the Software is |
|||
furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all |
|||
copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
|||
fileFormatVersion: 2 |
|||
guid: f125b46aaa0524bdfb7c96d3cf3c5f17 |
|||
TextScriptImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 9ada111e9bb0b9b40a4136e17c5b6003 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
{ |
|||
"displayName":"Hello World Sample", |
|||
"description": "This sample walks through using most of the Lobby APIs in a simple, linear way.", |
|||
"createSeparatePackage": false |
|||
} |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Newtonsoft.Json; |
|||
using UnityEngine; |
|||
using Unity.Services.Authentication; |
|||
using Unity.Services.Core; |
|||
using Unity.Services.Lobbies; |
|||
using Unity.Services.Lobbies.Http; |
|||
using Unity.Services.Lobbies.Models; |
|||
using Random = UnityEngine.Random; |
|||
|
|||
public class LobbyHelloWorld : MonoBehaviour |
|||
{ |
|||
// Inspector properties with initial values
|
|||
public string newLobbyName = Guid.NewGuid().ToString(); |
|||
public int maxPlayers = 8; |
|||
public bool isPrivate = false; |
|||
|
|||
// We'll only be in one lobby at once for this demo, so let's track it here
|
|||
private Lobby currentLobby; |
|||
|
|||
async void Start() |
|||
{ |
|||
try |
|||
{ |
|||
await ExecuteLobbyDemoAsync(); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Debug.LogException(ex); |
|||
} |
|||
finally |
|||
{ |
|||
await CleanupDemoLobbyAsync(); |
|||
} |
|||
} |
|||
|
|||
// Clean up the lobby we're in if we're the host
|
|||
async Task CleanupDemoLobbyAsync() |
|||
{ |
|||
var localPlayerId = AuthenticationService.Instance.PlayerId; |
|||
|
|||
// This is so that orphan lobbies aren't left around in case the demo fails partway through
|
|||
if (currentLobby != null && currentLobby.HostId.Equals(localPlayerId)) |
|||
{ |
|||
await DeleteLobbyAsync(currentLobby.Id); |
|||
} |
|||
} |
|||
|
|||
// A basic demo of lobby functionality
|
|||
async Task ExecuteLobbyDemoAsync() |
|||
{ |
|||
await UnityServices.Initialize(); |
|||
|
|||
// Log in a player for this game client
|
|||
Player loggedInPlayer = await GetPlayerFromAnonymousLoginAsync(); |
|||
|
|||
// Add some data to our player
|
|||
// This data will be included in a lobby under players -> player.data
|
|||
loggedInPlayer.Data.Add("Ready", new PlayerDataObject(PlayerDataObject.VisibilityOptions.Member, "No")); |
|||
|
|||
// Look for existing lobbies
|
|||
List<Lobby> foundLobbies = await QueryLobbiesAsync(new QueryRequest( |
|||
count: 10, // Return up to 10 results
|
|||
sampleResults: false, // Do not give random results
|
|||
filter: new List<QueryFilter> |
|||
{ |
|||
// Use filters to only return lobbies which match specific conditions
|
|||
// You can only filter on built-in properties (Ex: AvailableSlots) or indexed custom data (S1, N1, etc.)
|
|||
// Take a look at the API for other built-in fields you can filter on
|
|||
|
|||
// Let's search for games with open slots (AvailableSlots greater than 0)
|
|||
new QueryFilter( |
|||
field: QueryFilter.FieldOptions.AvailableSlots, |
|||
op: QueryFilter.OpOptions.GT, |
|||
value: "0"), |
|||
|
|||
// Let's add some filters for custom indexed fields
|
|||
new QueryFilter( |
|||
field: QueryFilter.FieldOptions.S1, // S1 = "Test"
|
|||
op: QueryFilter.OpOptions.EQ, |
|||
value: "true"), |
|||
|
|||
new QueryFilter( |
|||
field: QueryFilter.FieldOptions.S2, // S2 = "GameMode"
|
|||
op: QueryFilter.OpOptions.EQ, |
|||
value: "ctf"), |
|||
|
|||
// Example "skill" range filter (skill is a custom numeric field in this example)
|
|||
new QueryFilter( |
|||
field: QueryFilter.FieldOptions.N1, // N1 = "Skill"
|
|||
op: QueryFilter.OpOptions.GT, |
|||
value: "0"), |
|||
|
|||
new QueryFilter( |
|||
field: QueryFilter.FieldOptions.N1, // N1 = "Skill"
|
|||
op: QueryFilter.OpOptions.LT, |
|||
value: "51"), |
|||
}, |
|||
order: new List<QueryOrder> |
|||
{ |
|||
// Order results by available player slots (least first), then by lobby age, then by lobby name
|
|||
new QueryOrder(true, QueryOrder.FieldOptions.AvailableSlots), |
|||
new QueryOrder(false, QueryOrder.FieldOptions.Created), |
|||
new QueryOrder(false, QueryOrder.FieldOptions.Name), |
|||
})); |
|||
|
|||
if (foundLobbies.Any()) // Try to join a random lobby if one exists
|
|||
{ |
|||
// Let's print info about the lobbies we found
|
|||
Debug.Log("Found lobbies:\n" + JsonConvert.SerializeObject(foundLobbies)); |
|||
|
|||
// Let's pick a random lobby to join
|
|||
var randomLobby = foundLobbies[Random.Range(0, foundLobbies.Count)]; |
|||
|
|||
// Try to join the lobby
|
|||
// Player is optional because the service can pull the player data from the auth token
|
|||
currentLobby = await JoinLobbyAsync(lobbyId: randomLobby.Id, player: null); |
|||
|
|||
// You can also join via a Lobby Code instead of a lobby ID
|
|||
// Lobby Codes are a short, unique codes that map to a specific lobby Id
|
|||
// currentLobby = await JoinLobbyWithCodeAsync("MyLobbyCode");
|
|||
} |
|||
else // Didn't find any lobbies, create a new lobby
|
|||
{ |
|||
// Populate the new lobby with some data; use indexes so it's easy to search for
|
|||
var lobbyData = new Dictionary<string, DataObject>() |
|||
{ |
|||
["Test"] = new DataObject(DataObject.VisibilityOptions.Public, "true", DataObject.IndexOptions.S1), |
|||
["GameMode"] = new DataObject(DataObject.VisibilityOptions.Public, "ctf", DataObject.IndexOptions.S2), |
|||
["Skill"] = new DataObject(DataObject.VisibilityOptions.Public, Random.Range(1, 51).ToString(), DataObject.IndexOptions.N1), |
|||
["Rank"] = new DataObject(DataObject.VisibilityOptions.Public, Random.Range(1, 51).ToString()), |
|||
}; |
|||
|
|||
// Create a new lobby
|
|||
currentLobby = await CreateLobbyAsync(new CreateRequest( |
|||
name: newLobbyName, |
|||
player: loggedInPlayer, |
|||
maxPlayers: maxPlayers, |
|||
isPrivate: isPrivate, |
|||
data: lobbyData)); |
|||
} |
|||
|
|||
// Let's write a little info about the lobby we joined / created
|
|||
Debug.Log("Lobby info:\n" + JsonConvert.SerializeObject(currentLobby)); |
|||
|
|||
// Let's add some new data for our player and update the lobby state
|
|||
// Players can update their own data
|
|||
loggedInPlayer.Data.Add("ExamplePublicPlayerData", |
|||
new PlayerDataObject(PlayerDataObject.VisibilityOptions.Public, "Everyone can see this")); |
|||
|
|||
loggedInPlayer.Data.Add("ExamplePrivatePlayerData", |
|||
new PlayerDataObject(PlayerDataObject.VisibilityOptions.Private, "Only the host sees this")); |
|||
|
|||
loggedInPlayer.Data.Add("ExampleMemberPlayerData", |
|||
new PlayerDataObject(PlayerDataObject.VisibilityOptions.Member, "Only lobby members see this")); |
|||
|
|||
// Update the lobby
|
|||
currentLobby = await UpdateLobbyPlayerDataAsync(currentLobby.Id, loggedInPlayer); |
|||
Debug.Log("Updated lobby info:\n" + JsonConvert.SerializeObject(currentLobby)); |
|||
|
|||
// Let's poll for the lobby data again just to see what it looks like
|
|||
currentLobby = await GetLobbyAsync(currentLobby.Id); |
|||
Debug.Log("Updated lobby info:\n" + JsonConvert.SerializeObject(currentLobby)); |
|||
|
|||
if (!currentLobby.HostId.Equals(loggedInPlayer.Id)) |
|||
{ |
|||
// Since we're not the lobby host, let's just leave the lobby
|
|||
await RemovePlayerFromLobbyAsync(currentLobby.Id, loggedInPlayer.Id); |
|||
} |
|||
else |
|||
{ |
|||
// Only hosts can set lobby data, and we're the host, so let's set some
|
|||
// Note that lobby host can be passed around intentionally (by the current host updating the host id)
|
|||
// Host is randomly assigned if the previous host leaves
|
|||
|
|||
// Let's update some existing lobby data
|
|||
currentLobby.Data["GameMode"] = |
|||
new DataObject(DataObject.VisibilityOptions.Public, "deathmatch", DataObject.IndexOptions.S2); |
|||
|
|||
// Let's add some new data to the lobby
|
|||
currentLobby.Data.Add("ExamplePublicLobbyData", |
|||
new DataObject(DataObject.VisibilityOptions.Public, "Everyone can see this")); |
|||
|
|||
currentLobby.Data.Add("ExamplePrivateLobbyData", |
|||
new DataObject(DataObject.VisibilityOptions.Private, "Only the host sees this")); |
|||
|
|||
currentLobby.Data.Add("ExampleMemberLobbyData", |
|||
new DataObject(DataObject.VisibilityOptions.Member, "Only lobby members see this")); |
|||
|
|||
// OK, now let's try to push these local changes to the service
|
|||
currentLobby = await UpdateLobbyDataAsync(currentLobby); |
|||
|
|||
// Let's print the updated lobby
|
|||
Debug.Log("Updated lobby info:\n" + JsonConvert.SerializeObject(currentLobby)); |
|||
|
|||
// OK, we're done with the lobby - let's delete it
|
|||
await DeleteLobbyAsync(currentLobby.Id); |
|||
} |
|||
|
|||
// Now, let's try the QuickJoin API, which just puts our player in a matching lobby automatically
|
|||
// This is fast and reliable, but removes some user interactivity (can't choose from a list of lobbies)
|
|||
// You can use filters to specify which types of lobbies can be joined
|
|||
currentLobby = await QuickJoinLobbyAsync(loggedInPlayer, new List<QueryFilter> |
|||
{ |
|||
// Let's search for games with open slots (AvailableSlots greater than 0)
|
|||
new QueryFilter( |
|||
field: QueryFilter.FieldOptions.AvailableSlots, |
|||
op: QueryFilter.OpOptions.GT, |
|||
value: "0"), |
|||
|
|||
// You can add more filters here, such as filters on custom data fields
|
|||
}); |
|||
|
|||
// If we didn't find a lobby, abort run
|
|||
if (currentLobby == null) |
|||
{ |
|||
Debug.Log("Unable to find a lobby using Query and Join"); |
|||
return; |
|||
} |
|||
|
|||
// Let's write a little info about the lobby we quick-joined
|
|||
Debug.Log("Lobby info:\n" + JsonConvert.SerializeObject(currentLobby)); |
|||
|
|||
// There's not anything else we can really do here, so let's leave the lobby
|
|||
await RemovePlayerFromLobbyAsync(currentLobby.Id, loggedInPlayer.Id); |
|||
} |
|||
|
|||
// Log in a player using Unity's "Anonymous Login" API and construct a Player object for use with the Lobbies APIs
|
|||
static async Task<Player> GetPlayerFromAnonymousLoginAsync() |
|||
{ |
|||
if (!AuthenticationService.Instance.IsSignedIn) |
|||
{ |
|||
Debug.Log($"Trying to log in a player ..."); |
|||
|
|||
// Use Unity Authentication to log in
|
|||
await AuthenticationService.Instance.SignInAnonymouslyAsync(); |
|||
|
|||
if (!AuthenticationService.Instance.IsSignedIn) |
|||
{ |
|||
Debug.Log("Player was not signed in successfully?"); |
|||
throw new InvalidOperationException("Unable to continue with no logged in player"); |
|||
} |
|||
} |
|||
|
|||
Debug.Log("Player signed in as " + AuthenticationService.Instance.PlayerId); |
|||
|
|||
// Player objects have Get-only properties, so you need to initialize the data bag here if you want to use it
|
|||
return new Player(AuthenticationService.Instance.PlayerId, null, new Dictionary<string, PlayerDataObject>()); |
|||
} |
|||
|
|||
// Create a new lobby
|
|||
static async Task<Lobby> CreateLobbyAsync(CreateRequest createRequest) |
|||
{ |
|||
Debug.Log($"Trying to create a new lobby ..."); |
|||
Response<Lobby> response = await LobbyService.LobbyApiClient.CreateLobbyAsync(new CreateLobbyRequest(createRequest)); |
|||
Debug.Log($"Player {createRequest.Player.Id} created lobby {response.Result.Id}"); |
|||
return response.Result; |
|||
} |
|||
|
|||
// Get a list of existing lobbies (Optional: use a filter)
|
|||
static async Task<List<Lobby>> QueryLobbiesAsync(QueryRequest queryRequest) |
|||
{ |
|||
Debug.Log($"Trying to query compatible lobbies ..."); |
|||
Response<QueryResponse> response = await LobbyService.LobbyApiClient.QueryLobbiesAsync(new QueryLobbiesRequest(queryRequest)); |
|||
Debug.Log($"Found {response.Result.Results.Count} matching lobbies"); |
|||
return response.Result.Results; |
|||
} |
|||
|
|||
// Ask the service to join any available lobby; can provide a filter
|
|||
static async Task<Lobby> QuickJoinLobbyAsync(Player player, List<QueryFilter> filter = null) |
|||
{ |
|||
Debug.Log($"Trying to query and join a compatible lobby ..."); |
|||
|
|||
var request = new QuickJoinLobbyRequest(new QuickJoinRequest( |
|||
player: player, |
|||
filter: filter |
|||
)); |
|||
|
|||
// This is an example of how to handle some common errors when calling the service
|
|||
// 404s are expected if no lobby is found, and the API currently throws exceptions on 404
|
|||
try |
|||
{ |
|||
Response<Lobby> response = await LobbyService.LobbyApiClient.QuickJoinLobbyAsync(request); |
|||
Debug.Log($"Player {player.Id} joined lobby {response.Result.Id}"); |
|||
return response.Result; |
|||
} |
|||
catch (HttpException ex) |
|||
{ |
|||
if (TryGetErrorFromResponse(ex.Response, out var error)) |
|||
{ |
|||
// If we got a structured error we can deserialize, let's log it
|
|||
Debug.Log($"Lobby service error; Http Status {ex.Response.StatusCode}" + |
|||
$"\nResponse Error: {ex.Response.ErrorMessage}" + |
|||
$"\nLobby Error Status: {error.status}" + |
|||
$"\nLobby Error Title: {error.title}"); |
|||
} |
|||
else |
|||
{ |
|||
// For error we can't deserialize, log the exception + body for debugging
|
|||
Debug.Log($"Lobby service error; Http Status {ex.Response.StatusCode}" + |
|||
$"\nResponse Error: {ex.Response.ErrorMessage}" + |
|||
$"\nBody: {Encoding.UTF8.GetString(ex.Response.Data)}"); |
|||
|
|||
Debug.LogException(ex); |
|||
} |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
// Try to join a specific lobby
|
|||
static async Task<Lobby> JoinLobbyAsync(string lobbyId, Player player = null) |
|||
{ |
|||
Debug.Log($"Attempting to join lobby {lobbyId} ..."); |
|||
Response<Lobby> response = await LobbyService.LobbyApiClient.JoinLobbyByIdAsync( |
|||
new JoinLobbyByIdRequest(lobbyId, player)); |
|||
Debug.Log($"Joined lobby {response.Result.Id}"); |
|||
return response.Result; |
|||
} |
|||
|
|||
// Try to join a specific lobby; use a lobbyCode to join instead of a LobbyId
|
|||
static async Task<Lobby> JoinLobbyWithCodeAsync(string lobbyCode, Player player = null) |
|||
{ |
|||
Debug.Log($"Attempting to join lobby with lobby code {lobbyCode} ..."); |
|||
Response<Lobby> response = await LobbyService.LobbyApiClient.JoinLobbyByCodeAsync( |
|||
new JoinLobbyByCodeRequest(new JoinByCodeRequest(lobbyCode, player))); |
|||
Debug.Log($"Joined lobby {response.Result.Id}"); |
|||
return response.Result; |
|||
} |
|||
|
|||
// Get details about a specific lobby
|
|||
static async Task<Lobby> GetLobbyAsync(string lobbyId) |
|||
{ |
|||
Debug.Log($"Getting lobby {lobbyId} ..."); |
|||
Response<Lobby> response = await LobbyService.LobbyApiClient.GetLobbyAsync( |
|||
new GetLobbyRequest(lobbyId)); |
|||
return response.Result; |
|||
} |
|||
|
|||
// Delete an existing lobby; see API docs for access restrictions
|
|||
static async Task DeleteLobbyAsync(string lobbyId) |
|||
{ |
|||
Debug.Log($"Deleting lobby {lobbyId} ..."); |
|||
Response response = await LobbyService.LobbyApiClient.DeleteLobbyAsync( |
|||
new DeleteLobbyRequest(lobbyId)); |
|||
Debug.Log($"Lobby {lobbyId} deleted"); |
|||
} |
|||
|
|||
// Remove a player from a lobby; see API docs for access restrictions
|
|||
static async Task RemovePlayerFromLobbyAsync(string lobbyId, string playerId) |
|||
{ |
|||
Debug.Log($"Removing {playerId} from lobby {lobbyId} ..."); |
|||
var request = new RemovePlayerRequest(lobbyId, playerId); |
|||
Response response = await LobbyService.LobbyApiClient.RemovePlayerAsync(request); |
|||
Debug.Log($"Player {playerId} removed from lobby {lobbyId}"); |
|||
} |
|||
|
|||
// Set lobby data; see API docs for access restrictions
|
|||
static async Task<Lobby> UpdateLobbyDataAsync(Lobby lobby) |
|||
{ |
|||
Debug.Log($"Updating lobby data for lobby {lobby.Id} ..."); |
|||
|
|||
UpdateRequest updatedState = new UpdateRequest( |
|||
maxPlayers: lobby.MaxPlayers, |
|||
isPrivate: lobby.IsPrivate, |
|||
data: lobby.Data, |
|||
hostId: lobby.HostId, |
|||
name: lobby.Name); |
|||
|
|||
var updateReq = new UpdateLobbyRequest(lobby.Id, updatedState); |
|||
Response<Lobby> response = await LobbyService.LobbyApiClient.UpdateLobbyAsync(updateReq); |
|||
Debug.Log($"Lobby data for lobby {lobby.Id} updated"); |
|||
return response.Result; |
|||
} |
|||
|
|||
// Set player data in a lobby; see API docs for access restrictions
|
|||
static async Task<Lobby> UpdateLobbyPlayerDataAsync(string lobbyId, Player player) |
|||
{ |
|||
Debug.Log($"Updating player data for player {player.Id} in lobby {lobbyId} ..."); |
|||
|
|||
var newPlayerState = new PlayerUpdateRequest( |
|||
connectionInfo: player.ConnectionInfo, |
|||
data: player.Data, |
|||
allocationId: player.AllocationId); |
|||
|
|||
var updateReq = new UpdatePlayerRequest(lobbyId, player.Id, newPlayerState); |
|||
|
|||
Response<Lobby> response = await LobbyService.LobbyApiClient.UpdatePlayerAsync(updateReq); |
|||
Debug.Log($"Player data for player {player.Id} in lobby {lobbyId} updated"); |
|||
return response.Result; |
|||
} |
|||
|
|||
// A class for errors returned from the service on failures (4xx errors, etc.)
|
|||
class LobbyError |
|||
{ |
|||
public int status { get; set; } |
|||
public string title { get; set; } |
|||
public Detail[] details { get; set; } |
|||
} |
|||
|
|||
class Detail |
|||
{ |
|||
public string message { get; set; } |
|||
public string errorType { get; set; } |
|||
} |
|||
|
|||
static bool TryGetErrorFromResponse(HttpClientResponse response, out LobbyError error) |
|||
{ |
|||
var decodedJsonString = Encoding.UTF8.GetString(response.Data); |
|||
|
|||
var success = true; |
|||
|
|||
var settings = new JsonSerializerSettings |
|||
{ |
|||
Error = (sender, args) => |
|||
{ |
|||
success = false; |
|||
args.ErrorContext.Handled = true; |
|||
}, |
|||
MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore |
|||
}; |
|||
|
|||
error = JsonConvert.DeserializeObject<LobbyError>(decodedJsonString, settings); |
|||
return success; |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 36b1cdc3d10416a44ac98753d781b1c5 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
# Contributing |
|||
|
|||
## If you are interested in contributing, here are some ground rules: |
|||
* ... Define guidelines & rules for what contributors need to know to successfully make Pull requests against your repo ... |
|||
|
|||
## All contributions are subject to the [Unity Contribution Agreement(UCA)](https://unity3d.com/legal/licenses/Unity_Contribution_Agreement) |
|||
By making a pull request, you are confirming agreement to the terms and conditions of the UCA, including that your Contributions are your original creation and that you have complete right and authority to make your Contributions. |
|||
|
|||
## Once you have a change ready following these ground rules. Simply make a pull request |
|
|||
fileFormatVersion: 2 |
|||
guid: d997183ab5f3e4f1aabd60a9e9d99360 |
|||
TextScriptImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue