浏览代码

Customer Test Branch

/main/staging/2021_Upgrade/custmer_test
当前提交
4a58c102
共有 17 个文件被更改,包括 765 次插入98 次删除
  1. 4
      Assets/Scripts/GameLobby/Auth/SubIdentity_Authentication.cs
  2. 5
      Assets/Scripts/GameLobby/Tests/PlayMode/Tests.Play.asmdef
  3. 5
      Assets/Scripts/GameLobby/Tests/PlayMode/UtpTests.cs
  4. 2
      Assets/Scripts/GameLobby/Tests/PlayMode/LobbyRelayIntegrationTests.cs.meta
  5. 6
      Packages/packages-lock.json
  6. 3
      ProjectSettings/EditorBuildSettings.asset
  7. 8
      Assets/Resources.meta
  8. 344
      Assets/Scenes/testServices.unity
  9. 7
      Assets/Scenes/testServices.unity.meta
  10. 154
      Assets/Scripts/GameLobby/Tests/PlayMode/LobbyRelayIntegrationTests.cs
  11. 154
      Assets/TestMono.cs
  12. 11
      Assets/TestMono.cs.meta
  13. 59
      Assets/Resources/TestNetworkManager.prefab
  14. 7
      Assets/Resources/TestNetworkManager.prefab.meta
  15. 94
      Assets/Scripts/GameLobby/Tests/PlayMode/AsyncLobbyTest.cs
  16. 0
      /Assets/Scripts/GameLobby/Tests/PlayMode/LobbyRelayIntegrationTests.cs.meta

4
Assets/Scripts/GameLobby/Auth/SubIdentity_Authentication.cs


{
DoSignIn(onSigninComplete);
}
~SubIdentity_Authentication()
{
Dispose();

m_hasDisposed = true;
}
}
public string ID => GetContent("id");
private async void DoSignIn(Action onSigninComplete)
{

5
Assets/Scripts/GameLobby/Tests/PlayMode/Tests.Play.asmdef


"LobbyRelaySample",
"Unity.Services.Lobbies",
"Unity.Services.Relay",
"Unity.Networking.Transport"
"Unity.Networking.Transport",
"Unity.Netcode.Runtime",
"Unity.Services.Authentication",
"Unity.Services.Core"
],
"includePlatforms": [],
"excludePlatforms": [],

5
Assets/Scripts/GameLobby/Tests/PlayMode/UtpTests.cs


void OnAllocation(Allocation allocation)
{
bool isSecure = false;
NetworkEndPoint endpoint = GetEndpointForAllocation(allocation.ServerEndpoints, allocation.RelayServer.IpV4, allocation.RelayServer.Port, out isSecure);
NetworkEndPoint endpoint = GetEndpointForAllocation(allocation.ServerEndpoints, allocation.RelayServer.IpV4, allocation.RelayServer.Port, out var isSecure);
OnGetEndpoint?.Invoke(endpoint, isSecure);
// The allocation will be cleaned up automatically, since we won't be pinging it regularly.
}

#endif
}
}
}

2
Assets/Scripts/GameLobby/Tests/PlayMode/LobbyRelayIntegrationTests.cs.meta


fileFormatVersion: 2
guid: adc002dd7627a40afac107b97fcc05a0
guid: bb24fc4a58b307a48b32f52faea91fac
MonoImporter:
externalObjects: {}
serializedVersion: 2

6
Packages/packages-lock.json


"com.unity.modules.imgui": "1.0.0"
}
},
"com.veriorpies.parrelsync": {
"version": "file:ParrelSync",
"depth": 0,
"source": "embedded",
"dependencies": {}
},
"com.unity.modules.ai": {
"version": "1.0.0",
"depth": 0,

3
ProjectSettings/EditorBuildSettings.asset


- enabled: 1
path: Assets/Scenes/mainScene.unity
guid: ac99f707ce93cff419a804de3a2cc937
- enabled: 1
path: Assets/Scenes/testServices.unity
guid: 194caf01b5f07264ca60aedd07e5e8cc
m_configObjects: {}

8
Assets/Resources.meta


fileFormatVersion: 2
guid: 0a1a8d100347e7b4e8cedb406b0279a4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

344
Assets/Scenes/testServices.unity


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 9
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 3
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 12
m_GIWorkflowMode: 1
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 0
m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings:
serializedVersion: 12
m_Resolution: 2
m_BakeResolution: 40
m_AtlasSize: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_ExtractAmbientOcclusion: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_MixedBakeMode: 2
m_BakeBackend: 1
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 512
m_PVRBounces: 2
m_PVREnvironmentSampleCount: 256
m_PVREnvironmentReferencePointCount: 2048
m_PVRFilteringMode: 1
m_PVRDenoiserTypeDirect: 1
m_PVRDenoiserTypeIndirect: 1
m_PVRDenoiserTypeAO: 1
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVREnvironmentMIS: 1
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ExportTrainingData: 0
m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4
m_LightingDataAsset: {fileID: 0}
m_LightingSettings: {fileID: 0}
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
maxJobWorkers: 0
preserveTilesOutsideBounds: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &192154239
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 192154242}
- component: {fileID: 192154241}
- component: {fileID: 192154240}
- component: {fileID: 192154243}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &192154240
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 192154239}
m_Enabled: 1
--- !u!20 &192154241
Camera:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 192154239}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_FocalLength: 50
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!4 &192154242
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 192154239}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &192154243
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 192154239}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a79441f348de89743a2939f4d699eac1, type: 3}
m_Name:
m_EditorClassIdentifier:
m_RenderShadows: 1
m_RequiresDepthTextureOption: 2
m_RequiresOpaqueTextureOption: 2
m_CameraType: 0
m_Cameras: []
m_RendererIndex: -1
m_VolumeLayerMask:
serializedVersion: 2
m_Bits: 1
m_VolumeTrigger: {fileID: 0}
m_VolumeFrameworkUpdateModeOption: 2
m_RenderPostProcessing: 0
m_Antialiasing: 0
m_AntialiasingQuality: 2
m_StopNaN: 0
m_Dithering: 0
m_ClearDepth: 1
m_AllowXRRendering: 1
m_RequiresDepthTexture: 0
m_RequiresColorTexture: 0
m_Version: 2
--- !u!1001 &944903343
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 1163142661017035433, guid: 1640979fa1abc984d994b499738a933d, type: 3}
propertyPath: m_RootOrder
value: 2
objectReference: {fileID: 0}
- target: {fileID: 1163142661017035433, guid: 1640979fa1abc984d994b499738a933d, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1163142661017035433, guid: 1640979fa1abc984d994b499738a933d, type: 3}
propertyPath: m_LocalPosition.y
value: 52.01943
objectReference: {fileID: 0}
- target: {fileID: 1163142661017035433, guid: 1640979fa1abc984d994b499738a933d, type: 3}
propertyPath: m_LocalPosition.z
value: -6
objectReference: {fileID: 0}
- target: {fileID: 1163142661017035433, guid: 1640979fa1abc984d994b499738a933d, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1163142661017035433, guid: 1640979fa1abc984d994b499738a933d, type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 1163142661017035433, guid: 1640979fa1abc984d994b499738a933d, type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 1163142661017035433, guid: 1640979fa1abc984d994b499738a933d, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 1163142661017035433, guid: 1640979fa1abc984d994b499738a933d, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1163142661017035433, guid: 1640979fa1abc984d994b499738a933d, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1163142661017035433, guid: 1640979fa1abc984d994b499738a933d, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1345118566294570493, guid: 1640979fa1abc984d994b499738a933d, type: 3}
propertyPath: m_Name
value: TestNetworkManager
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 1640979fa1abc984d994b499738a933d, type: 3}
--- !u!1 &1471019970
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1471019972}
- component: {fileID: 1471019971}
m_Layer: 0
m_Name: TestMono
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1471019971
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1471019970}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 38ce1ea741f8a5741b92bfec4a9a76d4, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!4 &1471019972
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1471019970}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

7
Assets/Scenes/testServices.unity.meta


fileFormatVersion: 2
guid: 194caf01b5f07264ca60aedd07e5e8cc
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

154
Assets/Scripts/GameLobby/Tests/PlayMode/LobbyRelayIntegrationTests.cs


using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using NUnit.Framework;
using Unity.Netcode;
using Unity.Netcode.Transports.UTP;
using Unity.Services.Lobbies;
using Unity.Services.Lobbies.Models;
using Unity.Services.Relay;
using UnityEngine;
using UnityEngine.TestTools;
namespace Test
{
public class LobbyRelayIntegrationTests
{
string m_WorkingLobbyId;
LobbyRelaySample.Auth.SubIdentity_Authentication m_Auth;
bool m_DidSigninComplete = false;
// This is handled in the LobbyAsyncRequest calls normally, but we need to supply this for the dir
Dictionary<string, PlayerDataObject> m_MockUserData;
UnityTransport m_UnityTransport;
NetworkManager m_NetworkManager;
[OneTimeSetUp]
public void Setup()
{
m_MockUserData = new Dictionary<string, PlayerDataObject>();
m_MockUserData.Add("DisplayName",
new PlayerDataObject(PlayerDataObject.VisibilityOptions.Member, "TestUser123"));
m_NetworkManager = GameObject.Instantiate(Resources.Load<NetworkManager>("TestNetworkManager"));
m_UnityTransport = m_NetworkManager.GetComponent<UnityTransport>();
}
[OneTimeTearDown]
public void Teardown()
{
m_Auth?.Dispose();
}
[UnityTest]
public IEnumerator Lobby_Relay_Disconnect_Link()
{
m_Auth = new LobbyRelaySample.Auth.SubIdentity_Authentication(() => { m_DidSigninComplete = true; });
var task = Task.Run(async () =>
{
await Lobby_Relay_Disconnect_Async();
});
while (!task.IsCompleted) { yield return null; }
if (task.IsFaulted)
{
Debug.LogError($"Error while Running task:{task.Exception}");
}
}
async Task Lobby_Relay_Disconnect_Async()
{
await WaitForLogin();
var lobby = await Create();
Assert.AreEqual(1, lobby.Players.Count);
var kicked = false;
var callbacks = new LobbyEventCallbacks();
await LobbyService.Instance.SubscribeToLobbyEventsAsync(lobby.Id, callbacks);
callbacks.KickedFromLobby += () =>
{
Debug.Log("GOT KICKED!");
kicked = true;
};
NetworkManager.Singleton.Shutdown();
await Task.WhenAny(Task.Delay(10000), WaitForKicked());
async Task WaitForKicked()
{
while (!kicked)
{
await Task.Delay(50);
}
}
var getLobbyData = await LobbyService.Instance.GetLobbyAsync(lobby.Id);
foreach (var player in getLobbyData.Players)
{
Debug.Log(player.Id);
}
Assert.AreEqual(0, getLobbyData.Players.Count);
}
async Task WaitForLogin()
{
while (!m_DidSigninComplete)
{
await Task.Delay(50);
}
}
public async Task<Lobby> Create()
{
// Allocate Relay
var allocation = await Relay.Instance.CreateAllocationAsync(2);
m_UnityTransport.SetHostRelayData(allocation.RelayServer.IpV4, (ushort)allocation.RelayServer.Port,
allocation.AllocationIdBytes, allocation.Key, allocation.ConnectionData, true);
// Generate Join Code
var joinCode = await Relay.Instance.GetJoinCodeAsync(allocation.AllocationId);
// Create Lobby
var options = new CreateLobbyOptions()
{
Data = new Dictionary<string, DataObject>()
{
{ "joinCode", new DataObject(DataObject.VisibilityOptions.Public, joinCode) },
},
Player = new Player(m_Auth.ID, allocationId: allocation.AllocationId.ToString())
};
var lobby = await LobbyService.Instance.CreateLobbyAsync("testLobby", 2, options);
// Start Host
m_NetworkManager.StartHost();
return lobby;
}
public async Task<Lobby> Join(string lobbyId, string password = "")
{
var player = new Player(m_Auth.ID);
var options = new JoinLobbyByIdOptions()
{
Player = player,
};
var lobby = await LobbyService.Instance.JoinLobbyByIdAsync(lobbyId, options);
// Join Relay
var joinCode = lobby.Data["joinCode"].Value;
var join = await Relay.Instance.JoinAllocationAsync(joinCode);
await Lobbies.Instance.UpdatePlayerAsync(lobby.Id, player.Id, new UpdatePlayerOptions
{
AllocationId = join.AllocationId.ToString(),
ConnectionInfo = joinCode
});
m_UnityTransport.SetClientRelayData(join.RelayServer.IpV4, (ushort)join.RelayServer.Port,
join.AllocationIdBytes, join.Key, join.ConnectionData, join.HostConnectionData, true);
m_NetworkManager.StartClient();
return lobby;
}
}
}

154
Assets/TestMono.cs


using System;
using Unity.Services.Authentication;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Unity.Netcode;
using Unity.Netcode.Transports.UTP;
using Unity.Services.Core;
using Unity.Services.Lobbies;
using Unity.Services.Lobbies.Models;
using Unity.Services.Relay;
using UnityEngine;
public class TestMono : MonoBehaviour
{
string m_WorkingLobbyId;
string playerID;
bool m_DidSigninComplete = false;
// This is handled in the LobbyAsyncRequest calls normally, but we need to supply this for the dir
Dictionary<string, PlayerDataObject> m_MockUserData;
UnityTransport m_UnityTransport;
NetworkManager m_NetworkManager;
// Start is called before the first frame update
public async void Start()
{
await UnityServices.InitializeAsync();
await AuthenticationService.Instance.SignInAnonymouslyAsync();
m_NetworkManager = NetworkManager.Singleton;
m_UnityTransport = m_NetworkManager.GetComponent<UnityTransport>();
playerID = AuthenticationService.Instance.PlayerId;
await Lobby_Relay_Disconnect_Async_Test();
}
async Task Lobby_Relay_Disconnect_Async_Test()
{
var lobby = await Create_Relay_And_Lobby();
Debug.Log($"Created Lobby {lobby.Players.Count}");
var kicked = false;
var callbacks = new LobbyEventCallbacks();
callbacks.KickedFromLobby += () =>
{
Debug.Log("GOT KICKED!");
kicked = true;
};
await LobbyService.Instance.SubscribeToLobbyEventsAsync(lobby.Id, callbacks);
await Task.Delay(5000); // Give it a moment
//Local Disconnect
NetworkManager.Singleton.Shutdown();
//Wait for either the Lobby to signal that we were kicked, or for the time to run out. (Tested with up to 30s, still
await Task.WhenAny(Task.Delay(10000), WaitForKicked());
async Task WaitForKicked()
{
while (!kicked)
{
await Task.Delay(50);
}
}
var getPostKickLobbyData = await LobbyService.Instance.GetLobbyAsync(lobby.Id);
try
{
var getRelay = await Relay.Instance.JoinAllocationAsync(getPostKickLobbyData.Data["joinCode"].Value);
Debug.Log($"RelayAllocation : {getRelay.AllocationId} - {getRelay.RelayServer.IpV4} : {getRelay.RelayServer.Port}");
StringBuilder sb = new StringBuilder("Endpoints: \n");
foreach (var endpoint in getRelay.ServerEndpoints)
{
sb.AppendLine($"Host: {endpoint.Host} - ConnectionType: {endpoint.ConnectionType} -Port: {endpoint.Port} - Secure?:{endpoint.Secure}");
}
}
catch(Exception ex)
{
Debug.Log($"Error getting Relay after disconnect: {ex}.");
}
Debug.Log($"Was {playerID} kicked? Lobby has {getPostKickLobbyData.Players.Count} player(s)");
foreach (var player in getPostKickLobbyData.Players)
{
Debug.Log($"Player: {player.Id}");
}
}
public async Task<Lobby> Create_Relay_And_Lobby()
{
// Allocate Relay
var allocation = await Relay.Instance.CreateAllocationAsync(2, null);
try
{
Debug.Log($"RelayAllocation : {allocation.AllocationId} - {allocation.RelayServer.IpV4} : {allocation.RelayServer.Port}");
StringBuilder sb = new StringBuilder("Endpoints: \n");
foreach (var endpoint in allocation.ServerEndpoints)
{
sb.AppendLine($"Host: {endpoint.Host} - ConnectionType: {endpoint.ConnectionType} -Port: {endpoint.Port} - Secure?:{endpoint.Secure}");
}
}
catch(Exception ex)
{
Debug.Log("Error getting Relay after disconnect: {ex}.");
}
// Generate Join Code
var joinCode = await Relay.Instance.GetJoinCodeAsync(allocation.AllocationId);
// Create Lobby
var options = new CreateLobbyOptions
{
Data = new Dictionary<string, DataObject>
{
{ "joinCode", new DataObject(DataObject.VisibilityOptions.Public, joinCode) },
},
Player = new Player(playerID, allocationId: allocation.AllocationId.ToString())
};
var lobby = await LobbyService.Instance.CreateLobbyAsync("testLobby", 2, options);
m_UnityTransport.SetHostRelayData(allocation.RelayServer.IpV4, (ushort)allocation.RelayServer.Port,
allocation.AllocationIdBytes, allocation.Key, allocation.ConnectionData, true);
// Start Host
m_NetworkManager.StartHost();
return lobby;
}
public async Task<Lobby> Join(string lobbyId, string password = "")
{
var player = new Player(playerID);
var options = new JoinLobbyByIdOptions()
{
Player = player,
};
var lobby = await LobbyService.Instance.JoinLobbyByIdAsync(lobbyId, options);
// Join Relay
var joinCode = lobby.Data["joinCode"].Value;
var join = await Relay.Instance.JoinAllocationAsync(joinCode);
await Lobbies.Instance.UpdatePlayerAsync(lobby.Id, player.Id, new UpdatePlayerOptions
{
AllocationId = join.AllocationId.ToString(),
ConnectionInfo = joinCode
});
m_UnityTransport.SetClientRelayData(join.RelayServer.IpV4, (ushort)join.RelayServer.Port,
join.AllocationIdBytes, join.Key, join.ConnectionData, join.HostConnectionData, true);
m_NetworkManager.StartClient();
return lobby;
}
}

11
Assets/TestMono.cs.meta


fileFormatVersion: 2
guid: 38ce1ea741f8a5741b92bfec4a9a76d4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

59
Assets/Resources/TestNetworkManager.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &6826244093063387043
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 5481270937743757918, guid: b963f71e4874d4066bc72b9224e3ffce, type: 3}
propertyPath: m_Name
value: NetworkManager
objectReference: {fileID: 0}
- target: {fileID: 5665493986528408842, guid: b963f71e4874d4066bc72b9224e3ffce, type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5665493986528408842, guid: b963f71e4874d4066bc72b9224e3ffce, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5665493986528408842, guid: b963f71e4874d4066bc72b9224e3ffce, type: 3}
propertyPath: m_LocalPosition.y
value: 52.01943
objectReference: {fileID: 0}
- target: {fileID: 5665493986528408842, guid: b963f71e4874d4066bc72b9224e3ffce, type: 3}
propertyPath: m_LocalPosition.z
value: -6
objectReference: {fileID: 0}
- target: {fileID: 5665493986528408842, guid: b963f71e4874d4066bc72b9224e3ffce, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5665493986528408842, guid: b963f71e4874d4066bc72b9224e3ffce, type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 5665493986528408842, guid: b963f71e4874d4066bc72b9224e3ffce, type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 5665493986528408842, guid: b963f71e4874d4066bc72b9224e3ffce, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 5665493986528408842, guid: b963f71e4874d4066bc72b9224e3ffce, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5665493986528408842, guid: b963f71e4874d4066bc72b9224e3ffce, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5665493986528408842, guid: b963f71e4874d4066bc72b9224e3ffce, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: b963f71e4874d4066bc72b9224e3ffce, type: 3}

7
Assets/Resources/TestNetworkManager.prefab.meta


fileFormatVersion: 2
guid: 1640979fa1abc984d994b499738a933d
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

94
Assets/Scripts/GameLobby/Tests/PlayMode/AsyncLobbyTest.cs


using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using Unity.Services.Lobbies;
using Unity.Services.Lobbies.Models;
using Unity.Services.Relay;
using Unity.Services.Relay.Models;
using UnityEngine;
namespace LobbyAsync
{
public class LobbyRelayTest
{
public async Task Join(string lobbyId, string password = "")
{
try
{/*
// Authenticate
await AuthenticationService.Instance.SignInAnonymouslyAsync();
// Join Lobby
LobbyPlayer player = new LobbyPlayer(AuthenticationService.Instance.PlayerId);
JoinLobbyByIdOptions options = new JoinLobbyByIdOptions()
{
Player = player
};
Lobby lobby = = await LobbyHelper.Instance.JoinLobbyByIdAsync(lobbyId, options);
// Join Relay
string joinCode = lobby.Data["joinCode"].Value;
JoinAllocation join = await Relay.Instance.JoinAllocationAsync(joinCode);
await Lobbies.Instance.UpdatePlayerAsync(lobby.Id, player.Id, new UpdatePlayerOptions()
{
AllocationId = join.AllocationId.ToString(),
ConnectionInfo = joinCode
});
relayTransport.SetClientRelayData(join.RelayServer.IpV4, (ushort) join.RelayServer.Port,
join.AllocationIdBytes, join.Key, join.ConnectionData, join.HostConnectionData, true);
// Start Client
NetworkManager.Singleton.StartClient();*/
}
catch (Exception e)
{
Debug.LogError(e);
}
}
public async Task Create()
{
try
{
/*
// Authenticate
await Authenticate();
// Allocate Relay
Allocation allocation = await Relay.Instance.CreateAllocationAsync(maxPlayers);
relayTransport.SetHostRelayData(allocation.RelayServer.IpV4, (ushort)allocation.RelayServer.Port, allocation.AllocationIdBytes, allocation.Key, allocation.ConnectionData, true);
// Generate Join Code
string joinCode = await Relay.Instance.GetJoinCodeAsync(allocation.AllocationId);
// Create Lobby
CreateLobbyOptions options = new CreateLobbyOptions()
{
IsPrivate = isPrivate,
Data = new Dictionary<string, DataObject>()
{
{ "joinCode", new DataObject(DataObject.VisibilityOptions.Public, joinCode) },
},
Player = new LobbyPlayer(AuthenticationService.Instance.PlayerId, joinCode, null, allocation.AllocationId.ToString())
};
Lobby lobby = await LobbyHelper.Instance.CreateLobbyAsync(worldNameInputField.text, maxPlayers, options);
// Start Host
NetworkManager.Singleton.StartHost();*/
}
catch (Exception e)
{
Debug.LogError(e);
}
}
}
}

/Assets/Scripts/GameLobby/Tests/PlayMode/AsyncLobbyTest.cs.meta → /Assets/Scripts/GameLobby/Tests/PlayMode/LobbyRelayIntegrationTests.cs.meta

正在加载...
取消
保存