浏览代码
Merge from the NGO minigame cleanup branch. This is partial but stable progress on that front.
/main/staging
Merge from the NGO minigame cleanup branch. This is partial but stable progress on that front.
/main/staging
nathaniel.buck@unity3d.com
3 年前
当前提交
cf118508
共有 27 个文件被更改,包括 338 次插入 和 270 次删除
-
3Assets/Prefabs/GameManager.prefab
-
181Assets/Prefabs/InGame/InGameLogic.prefab
-
1Assets/Prefabs/InGame/SymbolContainer.prefab
-
4Assets/Prefabs/InGame/SymbolObject.prefab
-
2Assets/Scripts/Game/GameManager.cs
-
13Assets/Scripts/Game/LocalLobby.cs
-
6Assets/Scripts/Infrastructure/Locator.cs
-
1Assets/Scripts/Lobby/LobbyContentHeartbeat.cs
-
1Assets/Scripts/Lobby/ToLocalLobby.cs
-
11Assets/Scripts/Relay/RelayUtpSetup.cs
-
3Assets/Scripts/UI/CreateMenuUI.cs
-
2Assets/Scripts/Netcode/SymbolObject.cs
-
2Assets/Scripts/Netcode/SymbolKillVolume.cs
-
2Assets/Scripts/Netcode/SymbolData.cs
-
58Assets/Scripts/Netcode/SymbolContainer.cs
-
62Assets/Scripts/Netcode/SetupInGame.cs
-
2Assets/Scripts/Netcode/SequenceSelector.cs
-
2Assets/Scripts/Netcode/Scorer.cs
-
3Assets/Scripts/Netcode/PlayerCursor.cs
-
26Assets/Scripts/Netcode/InGameRunner.cs
-
2Assets/Scripts/Netcode/IInGameInputHandler.cs
-
88Assets/Scripts/Netcode/RelayNGOUtpSetup.cs
-
11Assets/Scripts/Netcode/RelayNGOUtpSetup.cs.meta
-
115Assets/Prefabs/Runes/starfield_bg.prefab
-
7Assets/Prefabs/Runes/starfield_bg.prefab.meta
-
0/Assets/Scripts/Netcode.meta
-
0/Assets/Scripts/Netcode
|
|||
using System; |
|||
using Unity.Services.Relay.Models; |
|||
using UnityEngine; |
|||
using LobbyRelaySample.relay; |
|||
|
|||
namespace LobbyRelaySample.ngo |
|||
{ |
|||
/* |
|||
* When using the Relay adapter for UTP to connect the NetworkManager for Netcode for GameObjects (NGO), we need to provide the Allocation info without manually binding to it. |
|||
* In actual use, if you are using NGO for your game's networking, you would not also use the RelayUtpSetupHost/RelayUtpSetupClient at all, since their direct data transmission would be unnecessary. |
|||
* We keep both versions for this sample to demonstrate how each is set up, whether you want to just use Lobby + Relay or use NGO as well. |
|||
*/ |
|||
|
|||
/// <summary>
|
|||
/// Host logic: Request a new Allocation, and then pass its info to the UTP adapter for NGO.
|
|||
/// </summary>
|
|||
public class RelayUtpNGOSetupHost : MonoBehaviour // If this is a MonoBehaviour, it can be added to the InGameRunner object for easier cleanup on game end.
|
|||
{ |
|||
private SetupInGame m_setupInGame; |
|||
private LocalLobby m_localLobby; |
|||
private Action m_onJoin; |
|||
|
|||
public void Initialize(SetupInGame setupInGame, LocalLobby lobby, Action onJoin) |
|||
{ |
|||
m_setupInGame = setupInGame; |
|||
m_localLobby = lobby; |
|||
m_onJoin = onJoin; |
|||
|
|||
RelayAPIInterface.AllocateAsync(m_localLobby.MaxPlayerCount, OnAllocation); |
|||
} |
|||
|
|||
private void OnAllocation(Allocation allocation) |
|||
{ |
|||
RelayAPIInterface.GetJoinCodeAsync(allocation.AllocationId, OnRelayCode); |
|||
bool isSecure = false; |
|||
var endpoint = RelayUtpSetup.GetEndpointForAllocation(allocation.ServerEndpoints, allocation.RelayServer.IpV4, allocation.RelayServer.Port, out isSecure); |
|||
m_setupInGame.SetRelayServerData(RelayUtpSetup.AddressFromEndpoint(endpoint), endpoint.Port, allocation.AllocationIdBytes, allocation.Key, allocation.ConnectionData, allocation.ConnectionData, isSecure); |
|||
m_onJoin?.Invoke(); |
|||
} |
|||
|
|||
private void OnRelayCode(string relayCode) |
|||
{ |
|||
m_localLobby.RelayNGOCode = relayCode; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Client logic: Wait to receive the Relay code for NGO, and then pass the allocation info to the UTP adapter.
|
|||
/// </summary>
|
|||
public class RelayUtpNGOSetupClient : MonoBehaviour // This is also a MonoBehaviour for access to OnDestroy, to ensure unsubscription from the local lobby on game end.
|
|||
{ |
|||
private SetupInGame m_setupInGame; |
|||
private LocalLobby m_localLobby; |
|||
private Action m_onJoin; |
|||
|
|||
public void Initialize(SetupInGame setupInGame, LocalLobby lobby, Action onJoin) |
|||
{ |
|||
m_setupInGame = setupInGame; |
|||
m_localLobby = lobby; |
|||
m_onJoin = onJoin; |
|||
|
|||
m_localLobby.onChanged += OnLobbyChange; |
|||
} |
|||
public void OnDestroy() |
|||
{ |
|||
m_localLobby.onChanged -= OnLobbyChange; |
|||
} |
|||
|
|||
private void OnLobbyChange(LocalLobby lobby) |
|||
{ |
|||
if (m_localLobby.RelayNGOCode != null) |
|||
{ |
|||
RelayAPIInterface.JoinAsync(m_localLobby.RelayNGOCode, OnJoin); |
|||
m_localLobby.onChanged -= OnLobbyChange; |
|||
} |
|||
} |
|||
|
|||
private void OnJoin(JoinAllocation joinAllocation) |
|||
{ |
|||
if (joinAllocation == null || this == null) // The returned JoinAllocation is null if allocation failed. this would be destroyed already if you quit the lobby while Relay is connecting.
|
|||
return; |
|||
bool isSecure = false; |
|||
var endpoint = RelayUtpSetup.GetEndpointForAllocation(joinAllocation.ServerEndpoints, joinAllocation.RelayServer.IpV4, joinAllocation.RelayServer.Port, out isSecure); |
|||
m_setupInGame.SetRelayServerData(RelayUtpSetup.AddressFromEndpoint(endpoint), endpoint.Port, joinAllocation.AllocationIdBytes, joinAllocation.Key, joinAllocation.ConnectionData, joinAllocation.HostConnectionData, isSecure); |
|||
m_onJoin?.Invoke(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 90f27286cd4428d4c8487405d4141891 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!1 &5198038901144826249 |
|||
GameObject: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
serializedVersion: 6 |
|||
m_Component: |
|||
- component: {fileID: 4250384825297410415} |
|||
m_Layer: 0 |
|||
m_Name: starfield_bg |
|||
m_TagString: Untagged |
|||
m_Icon: {fileID: 0} |
|||
m_NavMeshLayer: 0 |
|||
m_StaticEditorFlags: 0 |
|||
m_IsActive: 1 |
|||
--- !u!4 &4250384825297410415 |
|||
Transform: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 5198038901144826249} |
|||
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_Children: |
|||
- {fileID: 5567900622042513664} |
|||
m_Father: {fileID: 0} |
|||
m_RootOrder: 0 |
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
|||
--- !u!1 &8612118632738538329 |
|||
GameObject: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
serializedVersion: 6 |
|||
m_Component: |
|||
- component: {fileID: 5567900622042513664} |
|||
- component: {fileID: 6831725540459504660} |
|||
m_Layer: 0 |
|||
m_Name: starfield_sprite |
|||
m_TagString: Untagged |
|||
m_Icon: {fileID: 0} |
|||
m_NavMeshLayer: 0 |
|||
m_StaticEditorFlags: 0 |
|||
m_IsActive: 1 |
|||
--- !u!4 &5567900622042513664 |
|||
Transform: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 8612118632738538329} |
|||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} |
|||
m_LocalPosition: {x: 0, y: 0, z: 0} |
|||
m_LocalScale: {x: 30, y: 30, z: 1} |
|||
m_Children: [] |
|||
m_Father: {fileID: 4250384825297410415} |
|||
m_RootOrder: 0 |
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
|||
--- !u!212 &6831725540459504660 |
|||
SpriteRenderer: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 8612118632738538329} |
|||
m_Enabled: 1 |
|||
m_CastShadows: 0 |
|||
m_ReceiveShadows: 0 |
|||
m_DynamicOccludee: 1 |
|||
m_MotionVectors: 1 |
|||
m_LightProbeUsage: 1 |
|||
m_ReflectionProbeUsage: 1 |
|||
m_RayTracingMode: 0 |
|||
m_RayTraceProcedural: 0 |
|||
m_RenderingLayerMask: 1 |
|||
m_RendererPriority: 0 |
|||
m_Materials: |
|||
- {fileID: 2100000, guid: 68d15da6f7b6a8c4a83a150375d3b735, type: 2} |
|||
m_StaticBatchInfo: |
|||
firstSubMesh: 0 |
|||
subMeshCount: 0 |
|||
m_StaticBatchRoot: {fileID: 0} |
|||
m_ProbeAnchor: {fileID: 0} |
|||
m_LightProbeVolumeOverride: {fileID: 0} |
|||
m_ScaleInLightmap: 1 |
|||
m_ReceiveGI: 1 |
|||
m_PreserveUVs: 0 |
|||
m_IgnoreNormalsForChartDetection: 0 |
|||
m_ImportantGI: 0 |
|||
m_StitchLightmapSeams: 1 |
|||
m_SelectedEditorRenderState: 0 |
|||
m_MinimumChartSize: 4 |
|||
m_AutoUVMaxDistance: 0.5 |
|||
m_AutoUVMaxAngle: 89 |
|||
m_LightmapParameters: {fileID: 0} |
|||
m_SortingLayerID: 0 |
|||
m_SortingLayer: 0 |
|||
m_SortingOrder: 0 |
|||
m_Sprite: {fileID: 7482667652216324306, guid: 48e93eef0688c4a259cb0eddcd8661f7, type: 3} |
|||
m_Color: {r: 1, g: 1, b: 1, a: 1} |
|||
m_FlipX: 0 |
|||
m_FlipY: 0 |
|||
m_DrawMode: 0 |
|||
m_Size: {x: 1, y: 1} |
|||
m_AdaptiveModeThreshold: 0.5 |
|||
m_SpriteTileMode: 0 |
|||
m_WasSpriteAssigned: 1 |
|||
m_MaskInteraction: 1 |
|||
m_SpriteSortPoint: 0 |
|
|||
fileFormatVersion: 2 |
|||
guid: 16a5f484d0695604ea71ba774d5194e5 |
|||
PrefabImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue