Skip to content

Instantly share code, notes, and snippets.

View mkoutroumpas's full-sized avatar

Marios Koutroumpas mkoutroumpas

View GitHub Profile
public class RotatorScalerSystem : SystemBase
{
private EntityQuery entityQuery;
// ...
[BurstCompile]
struct ScalerAndRotatorJob : IJobChunk
{
//...
public class RotatorScalerSystem : SystemBase
{
private EntityQuery entityQuery;
// ...
protected override void OnCreate()
{
base.OnCreate();
using Unity.Entities;
[GenerateAuthoringComponent]
public struct Rotator : IComponentData
{
public float Speed;
public float Angle;
public bool Enabled;
}
@mkoutroumpas
mkoutroumpas / ZTranslationSystem.cs
Last active April 18, 2020 11:05
ZTranslationSystem class
public class ZTranslationSystem : JobComponentSystem
{
[BurstCompile]
[RequireComponentTag(typeof(CubeComponent))]
struct TranslateJob : IJobForEach<Translation, MoveSpeedComponentData>
{
[ReadOnly]
public float DeltaTime;
[ReadOnly]
@mkoutroumpas
mkoutroumpas / Cube.cs
Created April 5, 2020 20:17
Cube class
using Unity.Entities;
using UnityEngine;
public class Cube : MonoBehaviour, IConvertGameObjectToEntity
{
public void Convert(Entity entity, EntityManager entityManager, GameObjectConversionSystem conversionSystem)
{
entityManager.AddComponent(entity, typeof(CubeComponent));
entityManager.AddComponentData(entity, new MoveSpeedComponentData { Value = Random.Range(0.1f, 1.0f) });
}
@mkoutroumpas
mkoutroumpas / ExampleOfTwoComponents.cs
Created March 31, 2020 09:15
Example of two ECS Components.
using System;
using Unity.Entities;
[Serializable]
public struct CubeComponent : IComponentData { }
[Serializable]
public struct MoveSpeedComponentData : IComponentData
{
public float Value;
@mkoutroumpas
mkoutroumpas / InstantiateEntities.cs
Created March 31, 2020 09:10
Entity instantiation on ECS.
public class URPTestTwo : MonoBehaviour
{
private EntityManager _entityManager;
[SerializeField]
public GameObject Prefab;
[SerializeField]
public int NumberOfObjects = 1000;
[SerializeField]
public int XSpread = 10;
@mkoutroumpas
mkoutroumpas / ZTranslationJob.cs
Created January 28, 2020 12:16
ZTranslationJob.cs
using Assets.Scripts.Classes;
using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
using Unity.Mathematics;
[BurstCompile]
public struct ZTranslationJob : IJobParallelFor
{
public NativeArray<float> MoveSpeeds;
// Use Entity instantiation.
private void Start()
{
// ...
var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, null);
_entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
var entity = GameObjectConversionUtility.ConvertGameObjectHierarchy(ObjectToMove, settings);
for (var i = 0; i < NumberOfObjects; i++)
@mkoutroumpas
mkoutroumpas / ECS_Testbed_PlainGameObjects.cs
Last active January 28, 2020 11:24
ECS_Testbed_PlainGameObjects
// Use plain GameObject instantiation.
private void Start()
{
// ...
Transform instance = Instantiate(
ObjectToMove,
new Vector3(UnityEngine.Random.Range(-XSpread, XSpread),
UnityEngine.Random.Range(-YSpread, YSpread),
UnityEngine.Random.Range(-ZSpread, ZSpread)), Quaternion.identity);
// ...