Start FPS controls
This commit is contained in:
1 parent
be5a424911
commit
08e27ca2f1
16 files changed
+634
-25
No files matched your search
@@ -0,0 +1,33 @@
|
||||
using RpcComponents;
|
||||
using Unity.Burst;
|
||||
using Unity.Collections;
|
||||
using Unity.Entities;
|
||||
using Unity.NetCode;
|
||||
|
||||
partial struct InitializeLocallySystem : ISystem
|
||||
{
|
||||
[BurstCompile]
|
||||
public void OnCreate(ref SystemState state)
|
||||
{
|
||||
var builder = new EntityQueryBuilder(Allocator.Temp).WithAll<GhostOwnerIsLocal>().WithNone<InitializedLocallyTag>();
|
||||
state.RequireForUpdate(state.GetEntityQuery(builder));
|
||||
}
|
||||
|
||||
[BurstCompile]
|
||||
public void OnUpdate(ref SystemState state)
|
||||
{
|
||||
EntityCommandBuffer ecb = SystemAPI.GetSingletonRW<EndSimulationEntityCommandBufferSystem.Singleton>().ValueRW.CreateCommandBuffer(state.WorldUnmanaged);
|
||||
|
||||
foreach (var (character, entity) in SystemAPI.Query<FirstPersonCharacterComponent>().WithAll<GhostOwnerIsLocal>().WithNone<InitializedLocallyTag>().WithEntityAccess())
|
||||
{
|
||||
ecb.AddComponent(character.ViewEntity, new MainEntityCamera());
|
||||
ecb.AddComponent(entity, new InitializedLocallyTag());
|
||||
}
|
||||
}
|
||||
|
||||
[BurstCompile]
|
||||
public void OnDestroy(ref SystemState state)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b3232746997cb344a18d3986cc1e107
|
||||
@@ -0,0 +1,6 @@
|
||||
using Unity.Entities;
|
||||
|
||||
public struct InitializedLocallyTag : IComponentData
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe8481b72fe69a249ab201f73028655f
|
||||
@@ -7,6 +7,7 @@ namespace Common
|
||||
{
|
||||
// public GameObject PrefabController;
|
||||
public GameObject PrefabCharacter;
|
||||
public GameObject PrefabFPSPlayer;
|
||||
|
||||
public class TdPrefabsAuthoringBaker : Baker<TDPrefabsAuthoring>
|
||||
{
|
||||
@@ -16,7 +17,7 @@ namespace Common
|
||||
AddComponent(entity, new TdPrefabs()
|
||||
{
|
||||
Character = GetEntity(authoring.PrefabCharacter, TransformUsageFlags.Dynamic),
|
||||
// Controller = GetEntity(authoring.PrefabController, TransformUsageFlags.Dynamic)
|
||||
FPSPlayer = GetEntity(authoring.PrefabFPSPlayer, TransformUsageFlags.Dynamic)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,6 @@ namespace Common
|
||||
public struct TdPrefabs : IComponentData
|
||||
{
|
||||
public Entity Character;
|
||||
// public Entity Controller;
|
||||
public Entity FPSPlayer;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,9 @@ namespace Server
|
||||
public void OnUpdate(ref SystemState state)
|
||||
{
|
||||
var ecb = new EntityCommandBuffer(Allocator.Temp);
|
||||
var characterPrefab = SystemAPI.GetSingleton<TdPrefabs>().Character;
|
||||
var tdPrefabs = SystemAPI.GetSingleton<TdPrefabs>();
|
||||
var characterPrefab = tdPrefabs.Character;
|
||||
var fpsPlayerPrefab = tdPrefabs.FPSPlayer;
|
||||
|
||||
foreach (var (teamRequest, requestSource, requestEntity) in SystemAPI.Query<TdTeamRequest, ReceiveRpcCommandRequest>().WithEntityAccess())
|
||||
{
|
||||
@@ -55,12 +57,16 @@ namespace Server
|
||||
Debug.Log($"Server is assigning ClientId {clientId} to team {requestedTeam}");
|
||||
|
||||
var newCharacter = ecb.Instantiate(characterPrefab);
|
||||
var newFPSPlayer = ecb.Instantiate(fpsPlayerPrefab);
|
||||
|
||||
ecb.SetName(newCharacter, "Character");
|
||||
|
||||
var newTransform = LocalTransform.FromPosition(spawnPosition);
|
||||
ecb.SetComponent(newCharacter, newTransform);
|
||||
|
||||
ecb.SetComponent(newCharacter, new GhostOwner { NetworkId = clientId});
|
||||
ecb.SetComponent(newFPSPlayer, new GhostOwner { NetworkId = clientId});
|
||||
|
||||
ecb.SetComponent(newCharacter, new TdTeam { Value = requestedTeam });
|
||||
|
||||
ecb.SetComponent(newCharacter, new CharacterConfig
|
||||
@@ -68,8 +74,14 @@ namespace Server
|
||||
Color = requestedColor
|
||||
});
|
||||
|
||||
//Setup connection
|
||||
FirstPersonPlayer playerComponent = SystemAPI.GetComponent<FirstPersonPlayer>(tdPrefabs.FPSPlayer);
|
||||
playerComponent.ControlledCharacter = newCharacter;
|
||||
ecb.SetComponent(newFPSPlayer, playerComponent);
|
||||
|
||||
//Destroy character prefab, when client disconnects
|
||||
ecb.AppendToBuffer(requestSource.SourceConnection, new LinkedEntityGroup{Value = newCharacter});
|
||||
ecb.AppendToBuffer(requestSource.SourceConnection, new LinkedEntityGroup{Value = newFPSPlayer});
|
||||
}
|
||||
|
||||
ecb.Playback(state.EntityManager);
|
||||
|
||||
Reference in new issue
Block a user