Started adding multiplayer
This commit is contained in:
15
Assets/Scripts/Extensions/MonoBehaviourExtensions.cs
Normal file
15
Assets/Scripts/Extensions/MonoBehaviourExtensions.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace PashaBibko.PenguinChase.Extensions
|
||||
{
|
||||
public static class MonoBehaviourExtensions
|
||||
{
|
||||
public static void DestroyAllChildren(this MonoBehaviour go)
|
||||
{
|
||||
foreach (Transform child in go.transform)
|
||||
{
|
||||
Object.Destroy(child.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b9109919a0b4b969424d31ac875d6bf
|
||||
timeCreated: 1779211792
|
||||
26
Assets/Scripts/Extensions/TaskExtensions.cs
Normal file
26
Assets/Scripts/Extensions/TaskExtensions.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections;
|
||||
|
||||
namespace PashaBibko.PenguinChase.Extensions
|
||||
{
|
||||
public sealed class Result<T>
|
||||
{
|
||||
public T Value { get; set; }
|
||||
}
|
||||
|
||||
public static class TaskExtensions
|
||||
{
|
||||
public static IEnumerator Await<T>(this Task<T> task, Result<T> result)
|
||||
where T : class
|
||||
{
|
||||
// Waits until the task is completed
|
||||
while (!task.IsCompleted)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// Has to return the value like this because of the wonders of C#
|
||||
result.Value = task.Result;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Extensions/TaskExtensions.cs.meta
Normal file
3
Assets/Scripts/Extensions/TaskExtensions.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf8f135562fd4650924729e686a5a815
|
||||
timeCreated: 1779206087
|
||||
33
Assets/Scripts/Extensions/UnityTransportExtensions.cs
Normal file
33
Assets/Scripts/Extensions/UnityTransportExtensions.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Unity.Netcode.Transports.UTP;
|
||||
using Unity.Services.Relay.Models;
|
||||
|
||||
namespace PashaBibko.PenguinChase.Extensions
|
||||
{
|
||||
public static class UnityTransportExtensions
|
||||
{
|
||||
public static void SetHostRelayData(this UnityTransport transport, Allocation allocation)
|
||||
{
|
||||
transport.SetHostRelayData
|
||||
(
|
||||
allocation.RelayServer.IpV4,
|
||||
(ushort)allocation.RelayServer.Port,
|
||||
allocation.AllocationIdBytes,
|
||||
allocation.Key,
|
||||
allocation.ConnectionData
|
||||
);
|
||||
}
|
||||
|
||||
public static void SetRelayServerData(this UnityTransport transport, JoinAllocation allocation)
|
||||
{
|
||||
transport.SetRelayServerData
|
||||
(
|
||||
allocation.RelayServer.IpV4,
|
||||
(ushort)allocation.RelayServer.Port,
|
||||
allocation.AllocationIdBytes,
|
||||
allocation.Key,
|
||||
allocation.ConnectionData,
|
||||
allocation.HostConnectionData
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c69f8839a8834857b6dc5df1627045df
|
||||
timeCreated: 1779207616
|
||||
Reference in New Issue
Block a user