您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
56 行
2.0 KiB
56 行
2.0 KiB
using Unity.Entities;
|
|
using Unity.Jobs;
|
|
|
|
public class PlayerCharacterControl
|
|
{
|
|
public struct State : IComponentData
|
|
{
|
|
public int characterType;
|
|
public int requestedCharacterType;
|
|
}
|
|
|
|
[DisableAutoCreation]
|
|
[AlwaysSynchronizeSystem]
|
|
public class PlayerCharacterControlSystem : JobComponentSystem
|
|
{
|
|
protected override JobHandle OnUpdate(JobHandle inputDeps)
|
|
{
|
|
inputDeps.Complete();
|
|
|
|
var characterStateFromEntity = GetComponentDataFromEntity<Character.State>(false);
|
|
var characterSettingsFromEntity = GetComponentDataFromEntity<Character.Settings>(false);
|
|
var hitColliderOwnerStateFromEntity = GetComponentDataFromEntity<HitColliderOwner.State>(false);
|
|
|
|
Entities
|
|
.WithAll<State>()
|
|
.ForEach((ref Player.State playerState) =>
|
|
{
|
|
var controlledEntity = playerState.controlledEntity;
|
|
|
|
if (controlledEntity == Entity.Null || !characterStateFromEntity.HasComponent(controlledEntity))
|
|
return;
|
|
|
|
var charState = characterStateFromEntity[controlledEntity];
|
|
var charSettings = characterSettingsFromEntity[controlledEntity];
|
|
|
|
// Update character team
|
|
charState.teamId = playerState.teamIndex;
|
|
|
|
// Update hit collision
|
|
if (hitColliderOwnerStateFromEntity.HasComponent(controlledEntity))
|
|
{
|
|
var hitCollisionOwner = hitColliderOwnerStateFromEntity[controlledEntity];
|
|
hitCollisionOwner.colliderFlags = 1U << charState.teamId;
|
|
hitColliderOwnerStateFromEntity[controlledEntity] = hitCollisionOwner;
|
|
}
|
|
|
|
charSettings.characterName = playerState.playerName;
|
|
characterSettingsFromEntity[controlledEntity] = charSettings;
|
|
characterStateFromEntity[controlledEntity] = charState;
|
|
}).Run();
|
|
|
|
return default;
|
|
}
|
|
}
|
|
}
|
|
|