Skip to content

Instantly share code, notes, and snippets.

View sarkahn's full-sized avatar

sark sarkahn

  • Alberta, Canada
View GitHub Profile
@sarkahn
sarkahn / ECSandUGUI.cs
Created January 3, 2021 09:16
ECS with UGUI Example
using Unity.Entities;
using UnityEngine;
using UnityEngine.UI;
public class PlayerHealthUIAuthoring : MonoBehaviour, IConvertGameObjectToEntity
{
[SerializeField]
TMPro.TMP_Text _uiText;
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
@sarkahn
sarkahn / ECSInput.cs
Last active December 5, 2020 15:43
ECS Input
public class PlayerInputSystem : SystemBase
{
Controls _controls;
InputAction _moveAction;
protected override void OnCreate()
{
_controls = new Controls();
_controls.Enable();
_moveAction = _controls.Default.Move;
using NUnit.Framework;
using System.Runtime.InteropServices;
using Unity.Entities;
using UnityEngine;
// Credit to https://github.com/5argon/EcsTesting\
public class ECSTestBase
{
protected World World { get; private set; }
protected EntityManager EntityManager => World.EntityManager;
@sarkahn
sarkahn / EntityTransactionTest
Created October 6, 2020 07:35
Simple test showing how to use ExclusiveEntityTransaction in Unity ECS
using NUnit.Framework;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
[TestFixture]
public class EntityTransactionTests
{
struct SomeComponent : IComponentData
{ }
using System.Collections;
using System.Collections.Generic;
using Unity.Entities;
using UnityEngine;
struct FixedRateTestUtilsTest : IComponentData
{ }
class FixedRateSystemGroup : ComponentSystemGroup
{
using NUnit.Framework;
using System.Collections;
using System.Collections.Generic;
using Unity.Entities;
using UnityEngine;
namespace ECBEntityRefTests
{
struct CompA : IComponentData
{
using System.Collections;
using System.Collections.Generic;
using Unity.Collections;
using Unity.Entities;
using UnityEngine;
public class GlobalArray
{
public static NativeArray<int> Array;
}
using System.Collections;
using System.Collections.Generic;
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using UnityEngine;
public class FunctionPointerOnComponents : SystemBase
{
[BurstCompile]
// Sort so that players are first, and everything else is sorted by speed
struct PlayerSpeedSort : IComparer<Entity>
{
ComponentDataFromEntity<Speed> speedFromEntity;
ComponentDataFromEntity<Player> playerFromEntity;
public PlayerSpeedSort(ComponentDataFromEntity<Speed> speedFromEntity, ComponentDataFromEntity<Player> playerFromEntity)
{
this.speedFromEntity = speedFromEntity;
this.playerFromEntity = playerFromEntity;
@sarkahn
sarkahn / gist:13a283a190bffaa390e93fe2ff4c407d
Created February 15, 2020 04:06
AsDeferredJobArray example
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
var ints = new NativeList<int>(Allocator.TempJob);
inputDeps = new IntJob
{
ints = ints
}.Schedule(inputDeps);
inputDeps = new Reader