// Start is called before the first frame update void Start() { //We set the initial client data we already have as part of ClientDataComponent m_GameIp.text = ClientServerInfo.ConnectToServerIp; m_PlayerName.text = ClientServerInfo.PlayerName; //If it is not the client, stop running this script (unnecessary) if (!ClientServerInfo.IsClient) { this.enabled = false; } //Now we search for the client world and the client simulation system group //so we can communicated with ECS in this MonoBehaviour foreach (var world in World.All) { if (world.GetExistingSystem <ClientSimulationSystemGroup>() != null) { m_ClientWorld = world; m_ClientWorldSimulationSystemGroup = world.GetExistingSystem <ClientSimulationSystemGroup>(); m_GameNameComponentQuery = world.EntityManager.CreateEntityQuery(ComponentType.ReadOnly <GameNameComponent>()); //Grabbing the queries we need for updating scores m_NetworkConnectionEntityQuery = world.EntityManager.CreateEntityQuery(ComponentType.ReadOnly <NetworkIdComponent>()); m_PlayerScoresQuery = world.EntityManager.CreateEntityQuery(ComponentType.ReadOnly <PlayerScoreComponent>()); m_HighestScoreQuery = world.EntityManager.CreateEntityQuery(ComponentType.ReadOnly <HighestScoreComponent>()); } } }
protected override void OnCreate() { m_GhostUpdateSystemGroup = World.GetOrCreateSystem <GhostUpdateSystemGroup>(); m_ghostEntityMap = m_GhostUpdateSystemGroup.GhostEntityMap; #if UNITY_EDITOR || DEVELOPMENT_BUILD m_ghostMinMaxSnapshotTick = m_GhostUpdateSystemGroup.GhostSnapshotTickMinMax; #endif m_ClientSimulationSystemGroup = World.GetOrCreateSystem <ClientSimulationSystemGroup>(); m_GhostPredictionSystemGroup = World.GetOrCreateSystem <GhostPredictionSystemGroup>(); m_interpolatedQuery = GetEntityQuery(new EntityQueryDesc { All = new [] { ComponentType.ReadWrite <LagCompensationTestPlayerSnapshotData>(), ComponentType.ReadOnly <GhostComponent>(), ComponentType.ReadWrite <LagCompensationTestPlayer>(), ComponentType.ReadWrite <Rotation>(), ComponentType.ReadWrite <Translation>(), }, None = new [] { ComponentType.ReadWrite <PredictedGhostComponent>() } }); m_predictedQuery = GetEntityQuery(new EntityQueryDesc { All = new [] { ComponentType.ReadOnly <LagCompensationTestPlayerSnapshotData>(), ComponentType.ReadOnly <GhostComponent>(), ComponentType.ReadOnly <PredictedGhostComponent>(), ComponentType.ReadWrite <LagCompensationTestPlayer>(), ComponentType.ReadWrite <Rotation>(), ComponentType.ReadWrite <Translation>(), } }); RequireForUpdate(GetEntityQuery(ComponentType.ReadWrite <LagCompensationTestPlayerSnapshotData>(), ComponentType.ReadOnly <GhostComponent>())); }
protected override void OnCreate() { m_GhostUpdateSystemGroup = World.GetOrCreateSystem <GhostUpdateSystemGroup>(); m_ClientSimulationSystemGroup = World.GetOrCreateSystem <ClientSimulationSystemGroup>(); m_GhostPredictionSystemGroup = World.GetOrCreateSystem <GhostPredictionSystemGroup>(); m_interpolatedQuery = GetEntityQuery(new EntityQueryDesc { All = new [] { ComponentType.ReadWrite <CharacterSnapshotData>(), ComponentType.ReadOnly <GhostComponent>(), ComponentType.ReadWrite <Attack>(), ComponentType.ReadWrite <Damage>(), ComponentType.ReadWrite <MovableCharacterComponent>(), ComponentType.ReadWrite <PlayerData>(), ComponentType.ReadWrite <PrefabCreator>(), ComponentType.ReadWrite <Translation>(), }, None = new [] { ComponentType.ReadWrite <PredictedGhostComponent>() } }); m_predictedQuery = GetEntityQuery(new EntityQueryDesc { All = new [] { ComponentType.ReadOnly <CharacterSnapshotData>(), ComponentType.ReadOnly <GhostComponent>(), ComponentType.ReadOnly <PredictedGhostComponent>(), } }); RequireForUpdate(GetEntityQuery(ComponentType.ReadWrite <CharacterSnapshotData>(), ComponentType.ReadOnly <GhostComponent>())); }
protected override void OnCreate() { m_GhostUpdateSystemGroup = World.GetOrCreateSystem <GhostUpdateSystemGroup>(); m_ClientSimulationSystemGroup = World.GetOrCreateSystem <ClientSimulationSystemGroup>(); m_GhostPredictionSystemGroup = World.GetOrCreateSystem <GhostPredictionSystemGroup>(); m_interpolatedQuery = GetEntityQuery(new EntityQueryDesc { All = new [] { ComponentType.ReadWrite <ExtraBlockSnapshotData>(), ComponentType.ReadOnly <GhostComponent>(), ComponentType.ReadWrite <Rotation>(), ComponentType.ReadWrite <Translation>(), }, None = new [] { ComponentType.ReadWrite <PredictedGhostComponent>() } }); m_predictedQuery = GetEntityQuery(new EntityQueryDesc { All = new [] { ComponentType.ReadOnly <ExtraBlockSnapshotData>(), ComponentType.ReadOnly <GhostComponent>(), ComponentType.ReadOnly <PredictedGhostComponent>(), ComponentType.ReadWrite <Rotation>(), ComponentType.ReadWrite <Translation>(), } }); RequireForUpdate(GetEntityQuery(ComponentType.ReadWrite <ExtraBlockSnapshotData>(), ComponentType.ReadOnly <GhostComponent>())); }
protected override void OnCreate() { m_ClientSimulationSystemGroup = World.GetOrCreateSystem <ClientSimulationSystemGroup>(); m_Barrier = World.GetOrCreateSystem <BeginSimulationEntityCommandBufferSystem>(); RequireSingletonForUpdate <NetworkStreamInGame>(); // Just to make sure this system does not run in other scenes RequireSingletonForUpdate <LevelComponent>(); }
protected override void OnCreate() { //We set our variables m_ClientSimulationSystemGroup = World.GetOrCreateSystem <ClientSimulationSystemGroup>(); m_BeginSimEcb = World.GetOrCreateSystem <BeginSimulationEntityCommandBufferSystem>(); //We will only run this system if the player is in game and if the palyer is an AR player RequireSingletonForUpdate <NetworkStreamInGame>(); RequireSingletonForUpdate <IsARPlayerComponent>(); }
protected override void OnCreate( ) { m_validatePhysicEntitySnapshots = World.GetExistingSystem <ValidatePhysicEntitySnapshots>( ); m_clientSimulationSystemGroup = World.GetExistingSystem <ClientSimulationSystemGroup>( ); m_serverSimulationSystemGroup = World.GetExistingSystem <ServerSimulationSystemGroup>( ); m_barrier = World.GetExistingSystem <EndSimulationEntityCommandBufferSystem>( ); m_ghostLookupSystem = World.GetExistingSystem <GhostLookupSystem>( ); m_isServer = m_serverSimulationSystemGroup != null; }
protected override void OnCreate() { //This will grab the BeginSimulationEntityCommandBuffer system to be used in OnUpdate m_BeginSimEcb = World.GetOrCreateSystem <BeginSimulationEntityCommandBufferSystem>(); //We set our ClientSimulationSystemGroup who will provide its ServerTick needed for the Commands m_ClientSimulationSystemGroup = World.GetOrCreateSystem <ClientSimulationSystemGroup>(); //The client must have loaded the game to spawn a player so we wait for the //NetworkStreamInGame component added during the load game flow RequireSingletonForUpdate <NetworkStreamInGame>(); }
protected override void OnCreate() { base.OnCreate(); _ = this; #if !UNITY_CLIENT m_ServerComponentGroup = World.GetExistingSystem <ServerSimulationSystemGroup>(); #endif #if !UNITY_SERVER m_ClientPresentationGroup = World.GetExistingSystem <ClientPresentationSystemGroup>(); m_ClientComponentGroup = World.GetExistingSystem <ClientSimulationSystemGroup>(); #endif }
protected override void OnCreate() { m_GhostUpdateSystemGroup = World.GetOrCreateSystem <GhostUpdateSystemGroup>(); m_ghostEntityMap = m_GhostUpdateSystemGroup.GhostEntityMap; #if UNITY_EDITOR || DEVELOPMENT_BUILD m_ghostMinMaxSnapshotTick = m_GhostUpdateSystemGroup.GhostSnapshotTickMinMax; #endif m_ClientSimulationSystemGroup = World.GetOrCreateSystem <ClientSimulationSystemGroup>(); m_GhostPredictionSystemGroup = World.GetOrCreateSystem <GhostPredictionSystemGroup>(); m_interpolatedQuery = GetEntityQuery(new EntityQueryDesc { All = new [] { ComponentType.ReadWrite <Char_TerraformerSnapshotData>(), ComponentType.ReadOnly <GhostComponent>(), ComponentType.ReadWrite <Character.InterpolatedData>(), ComponentType.ReadWrite <Character.ReplicatedData>(), ComponentType.ReadWrite <CharacterControllerGroundSupportData>(), ComponentType.ReadWrite <CharacterControllerMoveResult>(), ComponentType.ReadWrite <CharacterControllerVelocity>(), ComponentType.ReadWrite <HealthStateData>(), ComponentType.ReadWrite <Inventory.State>(), ComponentType.ReadWrite <Player.OwnerPlayerId>(), ComponentType.ReadWrite <PlayerControlled.State>(), ComponentType.ReadOnly <LinkedEntityGroup>(), }, None = new [] { ComponentType.ReadWrite <PredictedGhostComponent>() } }); m_predictedQuery = GetEntityQuery(new EntityQueryDesc { All = new [] { ComponentType.ReadOnly <Char_TerraformerSnapshotData>(), ComponentType.ReadOnly <GhostComponent>(), ComponentType.ReadOnly <PredictedGhostComponent>(), ComponentType.ReadWrite <Character.PredictedData>(), ComponentType.ReadWrite <Character.ReplicatedData>(), ComponentType.ReadWrite <CharacterControllerGroundSupportData>(), ComponentType.ReadWrite <CharacterControllerMoveResult>(), ComponentType.ReadWrite <CharacterControllerVelocity>(), ComponentType.ReadWrite <HealthStateData>(), ComponentType.ReadWrite <Inventory.State>(), ComponentType.ReadWrite <Player.OwnerPlayerId>(), ComponentType.ReadWrite <PlayerControlled.State>(), ComponentType.ReadOnly <LinkedEntityGroup>(), } }); RequireForUpdate(GetEntityQuery(ComponentType.ReadWrite <Char_TerraformerSnapshotData>(), ComponentType.ReadOnly <GhostComponent>())); }
private quaternion m_LastRotation = new quaternion(0, 0, 0, 1); //We set the initial value to the identity void Start() { //We grab ClientSimulationSystemGroup to update ARPoseComponent in our Update loop foreach (var world in World.All) { if (world.GetExistingSystem <ClientSimulationSystemGroup>() != null) { //Set our world m_ClientWorld = world; //We create the ARPoseComponent that we will update with new data world.EntityManager.CreateEntity(typeof(ARPoseComponent)); //We grab the ClientSimulationSystemGroup for our Update loop m_ClientSimGroup = world.GetExistingSystem <ClientSimulationSystemGroup>(); //Now we set our query for SpawnPositionForARComponent m_SpawnPositionQuery = world.EntityManager.CreateEntityQuery(ComponentType.ReadWrite <SpawnPositionForARComponent>()); } } }
public static void InitClientSystems() { clientWorld = new World("ClientWorld"); clientSimulationSystemGroup = clientWorld.GetOrCreateSystem <ClientSimulationSystemGroup>(); clientPresentationSystemGroup = clientWorld.GetOrCreateSystem <ClientPresentationSystemGroup>(); foreach (var sys in allSystems) { var groups = sys.GetCustomAttributes(typeof(UpdateInGroupAttribute), true); foreach (var grp in groups) { var group = grp as UpdateInGroupAttribute; if (group.GroupType == typeof(ClientSimulationSystemGroup) || group.GroupType == typeof(ClientAndServerSimulationSystemGroup)) { clientSimulationSystemGroup.AddSystemToUpdateList(clientWorld.GetOrCreateSystem(sys) as ComponentSystemBase); } else if (group.GroupType == typeof(ClientPresentationSystemGroup)) { clientPresentationSystemGroup.AddSystemToUpdateList(clientWorld.GetOrCreateSystem(sys) as ComponentSystemBase); } else if (group.GroupType == typeof(ServerSimulationSystemGroup)) { // do nothing } else { var mask = GetTopLevelWorldMask(group.GroupType); if ((mask & WorldType.ClientWorld) != 0) { var groupSys = clientWorld.GetOrCreateSystem(group.GroupType) as ComponentSystemGroup; groupSys.AddSystemToUpdateList(clientWorld.GetOrCreateSystem(sys) as ComponentSystemBase); } } } } clientSimulationSystemGroup.SortSystemUpdateList(); clientPresentationSystemGroup.SortSystemUpdateList(); World.Active.GetOrCreateSystem <TickClientSimulationSystem>().AddSystemToUpdateList(clientSimulationSystemGroup); World.Active.GetOrCreateSystem <TickClientPresentationSystem>().AddSystemToUpdateList(clientPresentationSystemGroup); }
protected override void OnCreate() { m_GhostUpdateSystemGroup = World.GetOrCreateSystem <GhostUpdateSystemGroup>(); m_ghostEntityMap = m_GhostUpdateSystemGroup.GhostEntityMap; #if UNITY_EDITOR || DEVELOPMENT_BUILD m_ghostMinMaxSnapshotTick = m_GhostUpdateSystemGroup.GhostSnapshotTickMinMax; #endif m_ClientSimulationSystemGroup = World.GetOrCreateSystem <ClientSimulationSystemGroup>(); m_GhostPredictionSystemGroup = World.GetOrCreateSystem <GhostPredictionSystemGroup>(); m_interpolatedQuery = GetEntityQuery(new EntityQueryDesc { All = new [] { ComponentType.ReadWrite <__GHOST_NAME__SnapshotData>(), ComponentType.ReadOnly <GhostComponent>(), #region __GHOST_INTERPOLATED_COMPONENT_TYPE__ ComponentType.ReadWrite <__GHOST_COMPONENT_TYPE__>(), #endregion #region __GHOST_INTERPOLATED_READ_ONLY_COMPONENT_TYPE__ ComponentType.ReadOnly <__GHOST_COMPONENT_TYPE__>(), #endregion }, None = new [] { ComponentType.ReadWrite <PredictedGhostComponent>() } }); m_predictedQuery = GetEntityQuery(new EntityQueryDesc { All = new [] { ComponentType.ReadOnly <__GHOST_NAME__SnapshotData>(), ComponentType.ReadOnly <GhostComponent>(), ComponentType.ReadOnly <PredictedGhostComponent>(), #region __GHOST_PREDICTED_COMPONENT_TYPE__ ComponentType.ReadWrite <__GHOST_COMPONENT_TYPE__>(), #endregion #region __GHOST_PREDICTED_READ_ONLY_COMPONENT_TYPE__ ComponentType.ReadOnly <__GHOST_COMPONENT_TYPE__>(), #endregion } }); RequireForUpdate(GetEntityQuery(ComponentType.ReadWrite <__GHOST_NAME__SnapshotData>(), ComponentType.ReadOnly <GhostComponent>())); }
public void Initialize() { foreach (var world in World.All) { if (world.GetExistingSystem <ClientSimulationSystemGroup>() != null) { m_clientSimulationSystemGroup = world.GetExistingSystem <ClientSimulationSystemGroup>(); Client = world; HasClientWorld = true; } else if (world.GetExistingSystem <ServerSimulationSystemGroup>() != null) { m_serverSimulationSystemGroup = world.GetExistingSystem <ServerSimulationSystemGroup>(); Server = world; HasServerWorld = true; } if (world.GetExistingSystem <TransformSystemGroup>() != null) { Default = world; } } }
protected override void OnUpdate() { if (PresentedClient == null) { foreach (var world in World.AllWorlds) { var simulationGroup = world.GetExistingSystem <ClientSimulationSystemGroup>(); if (simulationGroup != null && PresentedClient == null) { m_currentPresentedClient = PresentedClient = simulationGroup; } else if (simulationGroup != null) { world.GetExistingSystem <ClientPresentationSystemGroup>().Enabled = false; } } } if (PresentedClient != m_currentPresentedClient) { // Change active client for presentation foreach (var world in World.AllWorlds) { var simulationGroup = world.GetExistingSystem <ClientSimulationSystemGroup>(); if (simulationGroup != null && simulationGroup == m_currentPresentedClient) { world.GetExistingSystem <ClientPresentationSystemGroup>().Enabled = false; } if (simulationGroup != null && simulationGroup == PresentedClient) { world.GetExistingSystem <ClientPresentationSystemGroup>().Enabled = true; } } m_currentPresentedClient = PresentedClient; } }
protected override void OnCreate() { PresentedClient = null; m_currentPresentedClient = null; }
public List <Type> Initialize(List <Type> systems) { // Workaround for initialization being called multiple times when using game object conversion #if !UNITY_SERVER if (clientWorld != null) { return(systems); } #endif #if !UNITY_CLIENT || UNITY_SERVER || UNITY_EDITOR if (serverWorld != null) { return(systems); } #endif #if !UNITY_SERVER #if UNITY_EDITOR int numClientWorlds = UnityEditor.EditorPrefs.GetInt("MultiplayerPlayMode_" + UnityEngine.Application.productName + "_NumClients"); if (numClientWorlds < 1) { numClientWorlds = 1; } if (numClientWorlds > 8) { numClientWorlds = 8; } int playModeType = UnityEditor.EditorPrefs.GetInt("MultiplayerPlayMode_" + UnityEngine.Application.productName + "_Type"); #else int numClientWorlds = 1; #endif #endif var defaultBootstrap = new List <Type>(); #if !UNITY_SERVER clientWorld = null; ClientInitializationSystemGroup[] clientInitializationSystemGroup = null; ClientSimulationSystemGroup[] clientSimulationSystemGroup = null; ClientPresentationSystemGroup[] clientPresentationSystemGroup = null; #if UNITY_EDITOR if (playModeType != 2) #endif { clientWorld = new World[numClientWorlds]; clientInitializationSystemGroup = new ClientInitializationSystemGroup[clientWorld.Length]; clientSimulationSystemGroup = new ClientSimulationSystemGroup[clientWorld.Length]; clientPresentationSystemGroup = new ClientPresentationSystemGroup[clientWorld.Length]; for (int i = 0; i < clientWorld.Length; ++i) { clientWorld[i] = new World("ClientWorld" + i); clientInitializationSystemGroup[i] = clientWorld[i].GetOrCreateSystem <ClientInitializationSystemGroup>(); clientSimulationSystemGroup[i] = clientWorld[i].GetOrCreateSystem <ClientSimulationSystemGroup>(); #if UNITY_EDITOR clientSimulationSystemGroup[i].ClientWorldIndex = i; #endif clientPresentationSystemGroup[i] = clientWorld[i].GetOrCreateSystem <ClientPresentationSystemGroup>(); } } #endif #if !UNITY_CLIENT || UNITY_SERVER || UNITY_EDITOR serverWorld = null; ServerInitializationSystemGroup serverInitializationSystemGroup = null; ServerSimulationSystemGroup serverSimulationSystemGroup = null; #if UNITY_EDITOR if (playModeType != 1) #endif { serverWorld = new World("ServerWorld"); serverInitializationSystemGroup = serverWorld.GetOrCreateSystem <ServerInitializationSystemGroup>(); serverSimulationSystemGroup = serverWorld.GetOrCreateSystem <ServerSimulationSystemGroup>(); } #endif foreach (var type in systems) { if (type.GetCustomAttributes(typeof(NotClientServerSystemAttribute), true).Length > 0 || type == typeof(InitializationSystemGroup) || type == typeof(SimulationSystemGroup) || type == typeof(PresentationSystemGroup)) { defaultBootstrap.Add(type); continue; } var groups = type.GetCustomAttributes(typeof(UpdateInGroupAttribute), true); if (groups.Length == 0) { defaultBootstrap.Add(type); // Treat the default group as both client and server groups = new object[] { new UpdateInGroupAttribute(typeof(ClientAndServerSimulationSystemGroup)) }; } foreach (var grp in groups) { var group = grp as UpdateInGroupAttribute; if (group.GroupType == typeof(ClientAndServerSimulationSystemGroup) || group.GroupType == typeof(SimulationSystemGroup)) { if (group.GroupType == typeof(SimulationSystemGroup)) { defaultBootstrap.Add(type); } #if !UNITY_CLIENT || UNITY_SERVER || UNITY_EDITOR if (serverWorld != null) { var defaultWorld = World.Active; World.Active = serverWorld; serverSimulationSystemGroup.AddSystemToUpdateList( serverWorld.GetOrCreateSystem(type)); World.Active = defaultWorld; } #endif #if !UNITY_SERVER if (clientWorld != null) { var defaultWorld = World.Active; for (int i = 0; i < clientSimulationSystemGroup.Length; ++i) { World.Active = clientWorld[i]; clientSimulationSystemGroup[i] .AddSystemToUpdateList(clientWorld[i].GetOrCreateSystem(type)); } World.Active = defaultWorld; } #endif } else if (group.GroupType == typeof(ClientAndServerInitializationSystemGroup) || group.GroupType == typeof(InitializationSystemGroup)) { if (group.GroupType == typeof(InitializationSystemGroup)) { defaultBootstrap.Add(type); } #if !UNITY_CLIENT || UNITY_SERVER || UNITY_EDITOR if (serverWorld != null) { var defaultWorld = World.Active; World.Active = serverWorld; serverInitializationSystemGroup.AddSystemToUpdateList( serverWorld.GetOrCreateSystem(type)); World.Active = defaultWorld; } #endif #if !UNITY_SERVER if (clientWorld != null) { var defaultWorld = World.Active; for (int i = 0; i < clientInitializationSystemGroup.Length; ++i) { World.Active = clientWorld[i]; clientInitializationSystemGroup[i] .AddSystemToUpdateList(clientWorld[i].GetOrCreateSystem(type)); } World.Active = defaultWorld; } #endif } else if (group.GroupType == typeof(ServerInitializationSystemGroup)) { #if !UNITY_CLIENT || UNITY_SERVER || UNITY_EDITOR if (serverWorld != null) { var defaultWorld = World.Active; World.Active = serverWorld; serverInitializationSystemGroup.AddSystemToUpdateList( serverWorld.GetOrCreateSystem(type)); World.Active = defaultWorld; } #endif } else if (group.GroupType == typeof(ClientInitializationSystemGroup)) { #if !UNITY_SERVER if (clientWorld != null) { var defaultWorld = World.Active; for (int i = 0; i < clientInitializationSystemGroup.Length; ++i) { World.Active = clientWorld[i]; clientInitializationSystemGroup[i] .AddSystemToUpdateList(clientWorld[i].GetOrCreateSystem(type)); } World.Active = defaultWorld; } #endif } else if (group.GroupType == typeof(ServerSimulationSystemGroup)) { #if !UNITY_CLIENT || UNITY_SERVER || UNITY_EDITOR if (serverWorld != null) { var defaultWorld = World.Active; World.Active = serverWorld; serverSimulationSystemGroup.AddSystemToUpdateList( serverWorld.GetOrCreateSystem(type)); World.Active = defaultWorld; } #endif } else if (group.GroupType == typeof(ClientSimulationSystemGroup)) { #if !UNITY_SERVER if (clientWorld != null) { var defaultWorld = World.Active; for (int i = 0; i < clientSimulationSystemGroup.Length; ++i) { World.Active = clientWorld[i]; clientSimulationSystemGroup[i] .AddSystemToUpdateList(clientWorld[i].GetOrCreateSystem(type)); } World.Active = defaultWorld; } #endif } else if (group.GroupType == typeof(ClientPresentationSystemGroup) || group.GroupType == typeof(PresentationSystemGroup)) { if (group.GroupType == typeof(PresentationSystemGroup)) { defaultBootstrap.Add(type); } #if !UNITY_SERVER if (clientWorld != null) { var defaultWorld = World.Active; for (int i = 0; i < clientPresentationSystemGroup.Length; ++i) { World.Active = clientWorld[i]; clientPresentationSystemGroup[i] .AddSystemToUpdateList(clientWorld[i].GetOrCreateSystem(type)); } World.Active = defaultWorld; } #endif } else { var mask = GetTopLevelWorldMask(group.GroupType); if ((mask & WorldType.DefaultWorld) != 0) { defaultBootstrap.Add(type); } #if !UNITY_SERVER if ((mask & WorldType.ClientWorld) != 0 && clientWorld != null) { var defaultWorld = World.Active; for (int i = 0; i < clientWorld.Length; ++i) { World.Active = clientWorld[i]; var groupSys = clientWorld[i].GetOrCreateSystem(group.GroupType) as ComponentSystemGroup; groupSys.AddSystemToUpdateList(clientWorld[i].GetOrCreateSystem(type)); } World.Active = defaultWorld; } #endif #if !UNITY_CLIENT || UNITY_SERVER || UNITY_EDITOR if ((mask & WorldType.ServerWorld) != 0 && serverWorld != null) { var defaultWorld = World.Active; World.Active = serverWorld; var groupSys = serverWorld.GetOrCreateSystem(group.GroupType) as ComponentSystemGroup; groupSys.AddSystemToUpdateList(serverWorld.GetOrCreateSystem(type)); World.Active = defaultWorld; } #endif } } } #if !UNITY_CLIENT || UNITY_SERVER || UNITY_EDITOR if (serverWorld != null) { serverInitializationSystemGroup.SortSystemUpdateList(); serverSimulationSystemGroup.SortSystemUpdateList(); World.Active.GetOrCreateSystem <TickServerInitializationSystem>().AddSystemToUpdateList(serverInitializationSystemGroup); World.Active.GetOrCreateSystem <TickServerSimulationSystem>().AddSystemToUpdateList(serverSimulationSystemGroup); } #endif #if !UNITY_SERVER if (clientWorld != null) { for (int i = 0; i < clientWorld.Length; ++i) { clientInitializationSystemGroup[i].SortSystemUpdateList(); clientSimulationSystemGroup[i].SortSystemUpdateList(); clientPresentationSystemGroup[i].SortSystemUpdateList(); World.Active.GetOrCreateSystem <TickClientInitializationSystem>().AddSystemToUpdateList(clientInitializationSystemGroup[i]); World.Active.GetOrCreateSystem <TickClientSimulationSystem>().AddSystemToUpdateList(clientSimulationSystemGroup[i]); World.Active.GetOrCreateSystem <TickClientPresentationSystem>().AddSystemToUpdateList(clientPresentationSystemGroup[i]); } } #endif return(defaultBootstrap); }
protected override void OnCreate() { m_ClientSimulationSystemGroup = World.GetOrCreateSystem <ClientSimulationSystemGroup>(); m_Barrier = World.GetOrCreateSystem <BeginSimulationEntityCommandBufferSystem>(); RequireSingletonForUpdate <NetworkStreamInGame>(); }
protected override void OnCreate() { RequireSingletonForUpdate <NetworkIdComponent>(); RequireSingletonForUpdate <EnableNetCubeGame>(); m_ClientSimulationSystemGroup = World.GetExistingSystem <ClientSimulationSystemGroup>(); }
protected override void OnCreate() { RequireSingletonForUpdate <EnableLagCompensationGhostReceiveSystemComponent>(); RequireSingletonForUpdate <CommandTargetComponent>(); m_systemGroup = World.GetExistingSystem <ClientSimulationSystemGroup>(); }
protected override void OnCreate() { RequireSingletonForUpdate <CommandTargetComponent>(); m_systemGroup = World.GetExistingSystem <ClientSimulationSystemGroup>(); }
protected override void OnCreate() { m_ClientSimulationSystemGroup = World.GetExistingSystem <ClientSimulationSystemGroup>(); }
void Awake() { launchObjects = GameObject.FindGameObjectsWithTag("LaunchObject"); foreach (GameObject launchObject in launchObjects) { /// //Checks for server launch object //If it exists it creates ServerDataComponent InitializeServerComponent and //passes through server data to ClientServerInfo // if (launchObject.GetComponent <ServerLaunchObjectData>() != null) { //This sets the gameobject server data in ClientServerInfo (mono) ClientServerInfo.IsServer = true; ClientServerInfo.GameName = launchObject.GetComponent <ServerLaunchObjectData>().GameName; ClientServerInfo.BroadcastIpAddress = launchObject.GetComponent <ServerLaunchObjectData>().BroadcastIpAddress; ClientServerInfo.BroadcastPort = launchObject.GetComponent <ServerLaunchObjectData>().BroadcastPort; //This sets the component server data in server world(dots) //ClientServerConnectionControl (server) will run in server world //it will pick up this component and use it to listen on the port foreach (var world in World.All) { //we cycle through all the worlds, and if the world has ServerSimulationSystemGroup //we move forward (because that is the server world) if (world.GetExistingSystem <ServerSimulationSystemGroup>() != null) { var ServerDataEntity = world.EntityManager.CreateEntity(); world.EntityManager.AddComponentData(ServerDataEntity, new ServerDataComponent { GameName = ClientServerInfo.GameName, GamePort = ClientServerInfo.GamePort }); //Create component that allows server initialization to run world.EntityManager.CreateEntity(typeof(InitializeServerComponent)); //For handling server disconnecting by hitting the quit button m_ServerWorld = world; m_ServerNetworkIdComponentQuery = world.EntityManager.CreateEntityQuery(ComponentType.ReadOnly <NetworkIdComponent>()); } } } // //Checks for client launch object //If it exists it creates ClientDataComponent, InitializeServerComponent and // passes through client data to ClientServerInfo // if (launchObject.GetComponent <ClientLaunchObjectData>() != null) { //This sets the gameobject data in ClientServerInfo (mono) ClientServerInfo.IsClient = true; ClientServerInfo.ConnectToServerIp = launchObject.GetComponent <ClientLaunchObjectData>().IPAddress; ClientServerInfo.PlayerName = launchObject.GetComponent <ClientLaunchObjectData>().PlayerName; //This sets the component client data in server world (dots) //ClientServerConnectionControl (client) will run in client world //it will pick up this component and use it connect to IP and port foreach (var world in World.All) { //We cycle through all the worlds, and if the world has ClientSimulationSystemGroup //we move forward (because that is the client world) if (world.GetExistingSystem <ClientSimulationSystemGroup>() != null) { var ClientDataEntity = world.EntityManager.CreateEntity(); world.EntityManager.AddComponentData(ClientDataEntity, new ClientDataComponent { PlayerName = ClientServerInfo.PlayerName, ConnectToServerIp = ClientServerInfo.ConnectToServerIp, GamePort = ClientServerInfo.GamePort }); //Create component that allows client initialization to run world.EntityManager.CreateEntity(typeof(InitializeClientComponent)); //We will now set the variables we need to clean up during QuitGame() m_ClientWorld = world; m_ClientSimulationSystemGroup = world.GetExistingSystem <ClientSimulationSystemGroup>(); m_ClientNetworkIdComponentQuery = world.EntityManager.CreateEntityQuery(ComponentType.ReadOnly <NetworkIdComponent>()); //This variable is used to check if the server disconnected m_ClientDisconnectedNCEQuery = world.EntityManager.CreateEntityQuery(ComponentType.ReadWrite <NetworkStreamDisconnected>()); } } } } }