Entity: the entities, or things, that populate your game or program
Component: the data associated with your entities, but organized by the data itself rather than by entity. (This difference in organization is one of the key differences between an object-oriented and a data-oriented design.)
System: the logic that transforms the component data from its current state to its next state— for example, a system might update the positions of all moving entities by their velocity times the time interval since the previous frame.
using Unity.Burst; using Unity.Collections; using Unity.Entities; using Unity.Jobs; using Unity.Mathematics; using Unity.Transforms; using UnityEngine;
[BurstCompile] privatestruct RotationSpeedJob : IJobChunk { publicfloat DeltaTime; public ArchetypeChunkComponentType<Rotation> RotationType; [ReadOnly] public ArchetypeChunkComponentType<RotationSpeed> RotationSpeedType; publicvoidExecute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var chunkRotations = chunk.GetNativeArray(RotationType); var chunkRotationSpeeds = chunk.GetNativeArray(RotationSpeedType); for (var i = 0; i < chunk.Count; i++) { var rotation = chunkRotations[i]; var rotationSpeed = chunkRotationSpeeds[i];
chunkRotations[i] = new Rotation { Value = math.mul(math.normalize(rotation.Value), quaternion.AxisAngle(math.up(), rotationSpeed.RadiansPerSecond * DeltaTime)) }; } } }
protectedoverride JobHandle OnUpdate(JobHandle inputDeps) { var rotationType = GetArchetypeChunkComponentType<Rotation>(); var rotationSpeedType = GetArchetypeChunkComponentType<RotationSpeed>();
var job = new RotationSpeedJob { DeltaTime = Time.deltaTime, RotationType = rotationType, RotationSpeedType = rotationSpeedType };