Я пытаюсь начать работу с чистым ECS в Unity 2018.3.6f1, я начинаю с простого, просто делая сферный префаб, движущийся в одном направлении, но мне кажется, что никаких префабов не создается.
Iу меня есть пустой префаб игрового объекта с RenderMesh, который имеет меш Sphere и простой материал, и у меня также есть скрипт, прикрепленный к префабу:
using System;
using Unity.Entities;
using UnityEngine;
[Serializable]
public struct Position : IComponentData
{
public Vector3 Value;
}
public class BoidPositionComponent : ComponentDataProxy<Position> { }
Затем у меня есть SteeringSystem:
using System.Collections;
using System.Collections.Generic;
using Unity.Entities;
using Unity.Jobs;
using Unity.Burst;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
public class SteeringSystem : JobComponentSystem
{
[BurstCompile]
struct SteeringJob : IJobProcessComponentData<Position>
{
public float deltaTime;
public void Execute(ref Position position)
{
Vector3 value = position.Value;
value = new Vector3(value.x + deltaTime + 1.0f, value.y, value.z);
position.Value = value;
}
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
SteeringJob steeringJob = new SteeringJob
{
deltaTime = Time.deltaTime
};
JobHandle jobHandle = steeringJob.Schedule(this, inputDeps);
return jobHandle;
}
}
И, наконец, у меня на сцене есть пустой игровой объект со следующим сценарием:
using Unity.Entities;
using Unity.Rendering;
using Unity.Collections;
using UnityEngine;
public class ECSWorld : MonoBehaviour
{
public GameObject boidPrefab;
private static EntityManager entityManager;
private static RenderMesh renderMesh;
private static EntityArchetype entityArchetype;
// Start is called before the first frame update
void Start()
{
entityManager = World.Active.GetOrCreateManager<EntityManager>();
entityArchetype = entityManager.CreateArchetype(typeof(Position));
AddBoids();
}
void AddBoids()
{
int amount = 200;
NativeArray<Entity> entities = new NativeArray<Entity>(amount, Allocator.Temp);
entityManager.Instantiate(boidPrefab, entities);
for (int i = 0; i < amount; i++)
{
// Do stuff, like setting data...
entityManager.SetComponentData(entities[i], new Position { Value = Vector3.zero });
}
entities.Dispose();
}
}
Но я ничего не вижу, когда запускаю игру.Разве он не должен создавать 200 og моего префаба и заставлять их двигаться на экране?Что мне здесь не хватает?
Спасибо
Сёрен