Browse Source

Cleaned up the project a bit and included the latest GameCore Unity package in the project itself

master
Nico de Poel 5 years ago
parent
commit
d49ae331a0
  1. 2
      Assets/Scenes/SampleScene.unity
  2. 21
      Assets/Scripts/EOSNativeHelper.cs
  3. 5
      Assets/Scripts/EOSVoiceChat.cs
  4. 19
      Assets/Scripts/EpicVoiceChatTest.cs
  5. 0
      Assets/Scripts/EpicVoiceChatTest.cs.meta
  6. 13
      Assets/Scripts/IProductUserMapper.cs
  7. 3
      Assets/Scripts/IProductUserMapper.cs.meta
  8. BIN
      Packages/gamecore/com.unity.gamecore-0.4.6-preview.tgz
  9. 1
      Packages/manifest.json
  10. 6
      Packages/packages-lock.json

2
Assets/Scenes/SampleScene.unity

@ -307,7 +307,7 @@ GameObject:
- component: {fileID: 1498573725}
- component: {fileID: 1498573724}
m_Layer: 0
m_Name: Magnificent Voice Chat
m_Name: Epic Voice Chat Test
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

21
Assets/Scripts/EOSNativeHelper.cs

@ -37,6 +37,7 @@ public static class EOSNativeHelper
public static IntPtr AllocateMemory(IntPtr size, IntPtr alignment)
{
return Marshal.AllocHGlobal(size);
//return HeapAlloc(GetProcessHeap(), 0, size);
}
[UnmanagedFunctionPointer(Config.LibraryCallingConvention)]
@ -45,10 +46,16 @@ public static class EOSNativeHelper
[MonoPInvokeCallback(typeof(ReallocateMemoryFunc))]
public static IntPtr ReallocateMemory(IntPtr pointer, IntPtr size, IntPtr alignment)
{
// EOS will sometimes request a reallocation for a null pointer, so we need to specifically handle that
if (pointer == IntPtr.Zero)
return Marshal.AllocHGlobal(size);
return Marshal.ReAllocHGlobal(pointer, size);
// if (pointer == IntPtr.Zero)
// return HeapAlloc(GetProcessHeap(), 0, size);
//
// return HeapReAlloc(GetProcessHeap(), 0, pointer, size);
}
[UnmanagedFunctionPointer(Config.LibraryCallingConvention)]
@ -58,5 +65,19 @@ public static class EOSNativeHelper
public static void ReleaseMemory(IntPtr pointer)
{
Marshal.FreeHGlobal(pointer);
// HeapFree(GetProcessHeap(), 0, pointer);
}
[DllImport("kernel32", SetLastError = true)]
private static extern IntPtr GetProcessHeap();
[DllImport("kernel32")]
private static extern IntPtr HeapAlloc(IntPtr hHeap, int dwFlags, IntPtr dwBytes);
[DllImport("kernel32")]
private static extern IntPtr HeapReAlloc(IntPtr hHeap, int dwFlags, IntPtr lpMem, IntPtr dwBytes);
[DllImport("kernel32")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool HeapFree(IntPtr hHeap, int dwFlags, IntPtr lpMem);
}

5
Assets/Scripts/EOSVoiceChat.cs

@ -63,7 +63,6 @@ public class EOSVoiceChat: IDisposable
/// <summary>
/// Join an existing chat lobby or create a new one.
/// The completion callback is invoked on both success and failure, and can be used to set up the chat lobby's initial parameters.
/// </summary>
public void ConnectToChat(string chatLobbyName, uint maxChatPlayers = DefaultMaxChatPlayers)
{
@ -330,10 +329,14 @@ public class EOSVoiceChat: IDisposable
// Update the default input device, so we know whether we can actually talk or not
uint inputDevicesCount = audioInterface.GetAudioInputDevicesCount(new GetAudioInputDevicesCountOptions());
Debug.Log($"Found {inputDevicesCount} input device(s)");
for (uint inputDeviceIndex = 0; inputDeviceIndex < inputDevicesCount; ++inputDeviceIndex)
{
var inputDeviceInfo = audioInterface.GetAudioInputDeviceByIndex(
new GetAudioInputDeviceByIndexOptions { DeviceInfoIndex = inputDeviceIndex });
Debug.Log($"Input device {inputDeviceIndex}: ID = {inputDeviceInfo.DeviceId}, Name = {inputDeviceInfo.DeviceName}, Default = {inputDeviceInfo.DefaultDevice}");
if (inputDeviceInfo.DefaultDevice)
{

19
Assets/Scripts/MagnificentVoiceChat.cs → Assets/Scripts/EpicVoiceChatTest.cs

@ -22,10 +22,12 @@ using Unity.GameCore;
using UnityEngine.GameCore;
#endif
public class MagnificentVoiceChat : MonoBehaviour
public class EpicVoiceChatTest : MonoBehaviour
{
// We intend to use predetermined lobby names generated from game-specific match/team/squad information,
// so to simulate this we use a static GUID here, as opposed to letting Epic's backend automatically generate a random lobby ID.
// This also allows multiple clients to connect to the same lobby without having to communicate the ID among each other.
private const string DebugLobbyId = "a0f6a51f-6b61-4c95-9ed8-a1d508fe4eb6";
private const string DebugBucketId = "foobar";
private readonly StringBuilder status = new StringBuilder("Status:\n");
@ -80,6 +82,7 @@ public class MagnificentVoiceChat : MonoBehaviour
Debug.Log("Xbox Live services initialized.");
// This delay is just here to give us some time to connect the debugger
yield return new WaitForSeconds(5f);
#endif
@ -88,6 +91,7 @@ public class MagnificentVoiceChat : MonoBehaviour
ProductName = "WW1Test",
ProductVersion = "1.0.0.0",
#if UNITY_GAMECORE
// EOS SDK on Game Core will not initialize without these memory management function pointers
AllocateMemoryFunction = Marshal.GetFunctionPointerForDelegate((EOSNativeHelper.AllocateMemoryFunc)EOSNativeHelper.AllocateMemory),
ReallocateMemoryFunction = Marshal.GetFunctionPointerForDelegate((EOSNativeHelper.ReallocateMemoryFunc)EOSNativeHelper.ReallocateMemory),
ReleaseMemoryFunction = Marshal.GetFunctionPointerForDelegate((EOSNativeHelper.ReleaseMemoryFunc)EOSNativeHelper.ReleaseMemory),
@ -368,12 +372,14 @@ public class MagnificentVoiceChat : MonoBehaviour
private void LoadLibrary()
{
// EOS SDK 1.13 uses dynamic library binding in the Editor but does not provide any system functions to actually load dynamic libraries,
// so we need to provide those ourselves.
eosLbraryHandle = EOSNativeHelper.LoadLibrary($@"Assets\Plugins\EpicOnlineServices\Bin\{Config.LibraryName}.dll");
if (eosLbraryHandle == IntPtr.Zero)
{
throw new Exception("Could not load EOS library!");
}
Bindings.Hook(eosLbraryHandle, EOSNativeHelper.GetProcAddress);
Debug.Log("Hooked EOS library bindings");
@ -413,7 +419,12 @@ public class MagnificentVoiceChat : MonoBehaviour
private void OnGUI()
{
GUI.matrix = Matrix4x4.Scale(new Vector3(2, 2, 1));
int screenHeight = Screen.currentResolution.height;
if (screenHeight == 0)
screenHeight = 1080;
float screenScale = screenHeight / 720f;
GUI.matrix = Matrix4x4.Scale(new Vector3(screenScale, screenScale, 1));
GUILayout.Label(status.ToString());
}

0
Assets/Scripts/MagnificentVoiceChat.cs.meta → Assets/Scripts/EpicVoiceChatTest.cs.meta

13
Assets/Scripts/IProductUserMapper.cs

@ -1,13 +0,0 @@
using System;
using Epic.OnlineServices;
/// <summary>
/// Generic interface for converting between EOS Product Users and platform-specific Player IDs.
/// The exact rules for mapping from one to the other may differ per platform, e.g. Steam and Epic will use different logic than Xbox and PlayStation.
/// The methods in this interface are asynchronous, though implementations may choose to pre-cache mappings to speed up the process.
/// </summary>
public interface IProductUserMapper
{
void MapProductUserToPlatformId(ProductUserId productUserId, Action<string> platformIdCallback);
void MapPlatformIdToProductUser(string platformId, Action<ProductUserId> productUserCallback);
}

3
Assets/Scripts/IProductUserMapper.cs.meta

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: d8a80c90c491474dbe97eba62578254f
timeCreated: 1625665094

BIN
Packages/gamecore/com.unity.gamecore-0.4.6-preview.tgz

1
Packages/manifest.json

@ -1,6 +1,7 @@
{
"dependencies": {
"com.unity.collab-proxy": "1.2.16",
"com.unity.gamecore": "file:gamecore/com.unity.gamecore-0.4.6-preview.tgz",
"com.unity.ide.rider": "1.2.1",
"com.unity.ide.vscode": "1.2.3",
"com.unity.test-framework": "1.1.24",

6
Packages/packages-lock.json

@ -14,6 +14,12 @@
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.gamecore": {
"version": "file:gamecore/com.unity.gamecore-0.4.6-preview.tgz",
"depth": 0,
"source": "local-tarball",
"dependencies": {}
},
"com.unity.ide.rider": {
"version": "1.2.1",
"depth": 0,

Loading…
Cancel
Save