您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
59 行
1.6 KiB
59 行
1.6 KiB
using System.Collections.Generic;
|
|
using Unity.Collections;
|
|
using UnityEngine;
|
|
using Unity.Entities;
|
|
using UnityEngine.Profiling;
|
|
|
|
[DisableAutoCreation]
|
|
public class HandleServerProjectileRequests : BaseComponentSystem
|
|
{
|
|
public struct Reqests
|
|
{
|
|
[ReadOnly] public EntityArray entities;
|
|
[ReadOnly] public ComponentDataArray<ProjectileRequest> requests;
|
|
}
|
|
|
|
[Inject]
|
|
public Reqests Group;
|
|
|
|
public HandleServerProjectileRequests(GameWorld world, BundledResourceManager resourceSystem) : base(world)
|
|
{
|
|
m_resourceSystem = resourceSystem;
|
|
|
|
m_settings = Resources.Load<ProjectileModuleSettings>("ProjectileModuleSettings");
|
|
}
|
|
|
|
protected override void OnDestroyManager()
|
|
{
|
|
base.OnDestroyManager();
|
|
Resources.UnloadAsset(m_settings);
|
|
}
|
|
|
|
protected override void OnUpdate()
|
|
{
|
|
// Copy requests as spawning will invalidate Group
|
|
var requests = new ProjectileRequest[Group.requests.Length];
|
|
for (var i = 0; i < Group.requests.Length; i++)
|
|
{
|
|
requests[i] = Group.requests[i];
|
|
PostUpdateCommands.DestroyEntity(Group.entities[i]);
|
|
}
|
|
|
|
// Handle requests
|
|
foreach (var request in requests)
|
|
{
|
|
var projectileEntity = m_settings.projectileFactory.Create(EntityManager);
|
|
|
|
var projectileData = EntityManager.GetComponentData<ProjectileData>(projectileEntity);
|
|
|
|
projectileData.Initialize(request);
|
|
projectileData.LoadSettings(m_resourceSystem);
|
|
|
|
PostUpdateCommands.SetComponent(projectileEntity, projectileData);
|
|
PostUpdateCommands.AddComponent(projectileEntity, new ServerEntity());
|
|
}
|
|
}
|
|
|
|
BundledResourceManager m_resourceSystem;
|
|
ProjectileModuleSettings m_settings;
|
|
}
|