Created
March 25, 2020 22:49
-
-
Save JCBuck/7c65823462a93673d7976e99ffd717ce to your computer and use it in GitHub Desktop.
DOTSSample Upgrade Unity ECS packages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Refactored code to use new unity Networking/Transport api | |
Part1: | |
https://gist.github.com/JCBuck/53d970b22fac3b12218d1fee08444230 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Assets/Scripts/EditorTools/Editor/BuildManager.cs b/Assets/Scripts/EditorTools/Editor/BuildManager.cs | |
index bf2058f..8fb3ed7 100644 | |
--- a/Assets/Scripts/EditorTools/Editor/BuildManager.cs | |
+++ b/Assets/Scripts/EditorTools/Editor/BuildManager.cs | |
@@ -22,7 +22,7 @@ public class BuildManager | |
} | |
static Data m_Data = new Data(); | |
- private static BuildSettings m_currentBuildSettings; | |
+ private static BuildConfiguration m_currentBuildSettings; | |
private static bool m_assembliesReloading; | |
static BuildManager() | |
@@ -40,7 +40,7 @@ public class BuildManager | |
} | |
- public static void QueueBuild(BuildSettings buildSettings) | |
+ public static void QueueBuild(BuildConfiguration buildSettings) | |
{ | |
var path = AssetDatabase.GetAssetPath(buildSettings); | |
@@ -96,7 +96,7 @@ public class BuildManager | |
var str = JsonUtility.ToJson(m_Data); | |
SessionState.SetString(c_SessionStateKey,str); | |
- m_currentBuildSettings = AssetDatabase.LoadAssetAtPath<BuildSettings>(dataPath); | |
+ m_currentBuildSettings = AssetDatabase.LoadAssetAtPath<BuildConfiguration>(dataPath); | |
SendStatusEvent(); | |
EditorApplication.QueuePlayerLoopUpdate(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Assets/Scripts/Game/Main/ClientGameLoop.cs b/Assets/Scripts/Game/Main/ClientGameLoop.cs | |
index b210a8c..329ae25 100644 | |
--- a/Assets/Scripts/Game/Main/ClientGameLoop.cs | |
+++ b/Assets/Scripts/Game/Main/ClientGameLoop.cs | |
@@ -409,7 +409,7 @@ public class ClientGameLoopSystem : ComponentSystem | |
args = new string[0]; | |
} | |
- World.GetOrCreateSystem<SceneSystem>().BuildSettingsGUID = ClientBuildSettingsGUID; | |
+ World.GetOrCreateSystem<SceneSystem>().BuildConfigurationGUID = ClientBuildSettingsGUID; | |
netCodePrefabs = Entity.Null; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Assets/Scripts/Game/Main/ConfigureEditorSystem.cs b/Assets/Scripts/Game/Main/ConfigureEditorSystem.cs | |
index b8a0d27..7c2b6ec 100644 | |
--- a/Assets/Scripts/Game/Main/ConfigureEditorSystem.cs | |
+++ b/Assets/Scripts/Game/Main/ConfigureEditorSystem.cs | |
@@ -13,7 +13,7 @@ public class ConfigureEditorSystem : JobComponentSystem | |
{ | |
if (UnityEditor.EditorApplication.isPlaying) | |
return; | |
- World.GetOrCreateSystem<SceneSystem>().BuildSettingsGUID = ClientGameLoopSystem.ClientBuildSettingsGUID; | |
+ World.GetOrCreateSystem<SceneSystem>().BuildConfigurationGUID = ClientGameLoopSystem.ClientBuildSettingsGUID; | |
} | |
protected override JobHandle OnUpdate(JobHandle inputDeps) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Assets/Unity.Sample.Core.Authoring/Scripts/EditorTools/OpenScene.cs b/Assets/Unity.Sample.Core.Authoring/Scripts/EditorTools/OpenScene.cs | |
index 76758b3..c1010cd 100644 | |
--- a/Assets/Unity.Sample.Core.Authoring/Scripts/EditorTools/OpenScene.cs | |
+++ b/Assets/Unity.Sample.Core.Authoring/Scripts/EditorTools/OpenScene.cs | |
@@ -65,7 +65,7 @@ public class OpenScene | |
foreach (var guid in guids) | |
{ | |
var buildSettingsPath = AssetDatabase.GUIDToAssetPath(guid); | |
- var buildSettings = AssetDatabase.LoadAssetAtPath<BuildSettings>(buildSettingsPath); | |
+ var buildSettings = AssetDatabase.LoadAssetAtPath<BuildConfiguration>(buildSettingsPath); | |
var sceneList = buildSettings.GetComponent<SceneList>(); | |
foreach (var scenePath in sceneList.GetScenePathsForBuild()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Assets/Scripts/Game/Main/ServerGameLoop.cs b/Assets/Scripts/Game/Main/ServerGameLoop.cs | |
index 7ba0c10..baa1128 100644 | |
--- a/Assets/Scripts/Game/Main/ServerGameLoop.cs | |
+++ b/Assets/Scripts/Game/Main/ServerGameLoop.cs | |
@@ -370,7 +370,7 @@ public class ServerGameLoopSystem : JobComponentSystem | |
var args = ServerGameLoop.CurrentArgs; | |
if (args == null) | |
args = new string[0]; | |
- World.GetOrCreateSystem<SceneSystem>().BuildSettingsGUID = new Unity.Entities.Hash128("9635cffb5d7da422c922505e40219752"); | |
+ World.GetOrCreateSystem<SceneSystem>().BuildConfigurationGUID = new Unity.Entities.Hash128("9635cffb5d7da422c922505e40219752"); | |
var tickRate = EntityManager.CreateEntity(); | |
EntityManager.AddComponentData(tickRate, new ClientServerTickRate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Assets/Scripts/Networking/Socket/SocketTransport.cs b/Assets/Scripts/Networking/Socket/SocketTransport.cs | |
index 8bd7c2f..ac81be8 100644 | |
--- a/Assets/Scripts/Networking/Socket/SocketTransport.cs | |
+++ b/Assets/Scripts/Networking/Socket/SocketTransport.cs | |
@@ -1,4 +1,4 @@ | |
-using System.Net; | |
+using System.Net; | |
using Unity.Networking.Transport; | |
using Unity.Collections; | |
using Unity.Sample.Core; | |
@@ -14,9 +14,12 @@ public class SocketTransport : INetworkTransport | |
configParams.disconnectTimeoutMS = ServerGameLoop.serverDisconnectTimeout.IntValue; | |
configParams.connectTimeoutMS = NetworkParameterConstants.ConnectTimeoutMS; | |
configParams.maxConnectAttempts = NetworkParameterConstants.MaxConnectAttempts; | |
- m_Socket = new UdpNetworkDriver(configParams); | |
- m_Socket.Bind(NetworkEndPoint.CreateIpv4(0, (ushort)port)); | |
+ | |
+ m_Socket = new NetworkDriver(default(UDPNetworkInterface), configParams); | |
+ | |
+ NetworkDriver.Create(configParams); | |
+ m_Socket.Bind(NetworkEndPoint.Parse("0.0.0.0", (ushort)port)); | |
} | |
public int Connect(string ip, int port) | |
@@ -51,7 +54,7 @@ public class SocketTransport : INetworkTransport | |
} | |
DataStreamReader reader; | |
- var context = default(DataStreamReader.Context); | |
+ //var context = default(DataStreamReader.Context); | |
var ev = m_Socket.PopEvent(out connection, out reader); | |
if (ev == EventType.Empty) | |
@@ -61,7 +64,11 @@ public class SocketTransport : INetworkTransport | |
if (reader.IsCreated) | |
{ | |
GameDebug.Assert(m_Buffer.Length >= reader.Length); | |
- reader.ReadBytesIntoArray(ref context, ref m_Buffer, reader.Length); | |
+ NativeArray<byte> nbuf = new NativeArray<byte>(m_Buffer.Length, Allocator.Temp); | |
+ | |
+ reader.ReadBytes( nbuf); | |
+ nbuf.CopyTo(m_Buffer); | |
+ | |
size = reader.Length; | |
} | |
@@ -91,11 +98,14 @@ public class SocketTransport : INetworkTransport | |
public void SendData(int connectionId, byte[] data, int sendSize) | |
{ | |
- using (var sendStream = new DataStreamWriter(sendSize, Allocator.Persistent)) | |
- { | |
- sendStream.Write(data, sendSize); | |
- m_IdToConnection[connectionId].Send(m_Socket, sendStream); | |
- } | |
+ | |
+ | |
+ NativeArray<byte> narray = new NativeArray<byte>(data, Allocator.Temp); | |
+ | |
+ var datasend = m_Socket.BeginSend(m_IdToConnection[connectionId]); | |
+ datasend.WriteBytes(narray); | |
+ m_Socket.EndSend(datasend); | |
+ | |
} | |
public string GetConnectionDescription(int connectionId) | |
@@ -110,6 +120,8 @@ public class SocketTransport : INetworkTransport | |
} | |
byte[] m_Buffer = new byte[1024 * 8]; | |
- UdpNetworkDriver m_Socket; | |
+ // UdpNetworkDriver m_Socket; | |
+ NetworkDriver m_Socket; | |
+ | |
NativeArray<NetworkConnection> m_IdToConnection; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment