Skip to content

Instantly share code, notes, and snippets.

View andrew-raphael-lukasik's full-sized avatar
🏴‍☠️

Andrew Raphael Lukasik andrew-raphael-lukasik

🏴‍☠️
View GitHub Profile
@andrew-raphael-lukasik
andrew-raphael-lukasik / ConvertGameObjectHierarchyExample.cs
Last active April 19, 2022 16:41
GameObject-Entity conversion examples
using UnityEngine;
using Unity.Entities;
public class ConvertGameObjectHierarchyExample : MonoBehaviour
{
[SerializeField] GameObject _prefab = null;
BlobAssetStore _blobAssetStore;
void Awake ()
{
var world = World.DefaultGameObjectInjectionWorld;
@andrew-raphael-lukasik
andrew-raphael-lukasik / Worlds.cs
Last active November 12, 2022 20:53
(dots) code for world serialization and deserialization
// src: https://gist.github.com/andrew-raphael-lukasik/66d898be737734f26e607e6526d22901
using IO = System.IO;
using UnityEngine;
using Unity.Entities;
using Unity.Scenes;
using Unity.Entities.Serialization;
public static class Worlds
{
@andrew-raphael-lukasik
andrew-raphael-lukasik / Mem.cs
Last active November 29, 2022 23:24
MemCpy between unmanaged and managed arrays
// src* https://gist.github.com/andrew-raphael-lukasik/b5cd9eb0c6f36388069d3211554409de
using UnityEngine;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
// Project Settings/Player/Other Settings/Script Compilation/Allow `Unsafe` Code = ☑
public static class Mem
{
public static unsafe bool Cpy<SRC, DST>(NativeArray<SRC> src, DST[] dst)
@andrew-raphael-lukasik
andrew-raphael-lukasik / simd.cs
Last active December 13, 2022 11:10
my thoughts on simd and Burst
using Unity.Collections;
using Unity.Jobs;
using Unity.Mathematics;
using BurstCompile = Unity.Burst.BurstCompileAttribute;
[BurstCompile] public unsafe struct NoSimd : IJob
{
public float a, b;
public float* c;
void IJob.Execute () { *c = a * b; }
@andrew-raphael-lukasik
andrew-raphael-lukasik / Binary Reader & Writer.cs
Last active December 27, 2022 03:51
Unity.Entities.Serialization.BinaryReader basic implementation
// src: https://gist.github.com/andrew-raphael-lukasik/6813fe2b8688eb3ea4e333f21d3cc02a
namespace Unity.Entities.Serialization
{
public unsafe struct Reader : BinaryReader
{
System.IO.BinaryReader _reader;
System.IO.FileStream _stream;
public Reader ( string filePath )
{
@andrew-raphael-lukasik
andrew-raphael-lukasik / Fix Terrain Seams.md
Last active December 28, 2022 23:30
UnityEngine, Fix Terrain Seams
// src*: https://gist.github.com/andrew-raphael-lukasik/d2903247b3f9c94e6faa9c042d9f0460/

#if UNITY_EDITOR
[UnityEditor.MenuItem( "Tools/Fix All Terrain Seams" )]
static void FixAllSeams () { FixTerrains( Object.FindObjectsOfType<Terrain>() ); }
#endif

static void FixTerrains ( Terrain[] terrains )
@andrew-raphael-lukasik
andrew-raphael-lukasik / Wait.cs
Last active December 28, 2022 23:32
WaitForSeconds cached means less memory allocations because of coroutines
//Usage example:
//yield return Wait.t2s5;//waits 2.5 seconds
using UnityEngine;
public class Wait
{
public readonly static object frame = null;
public readonly static WaitForEndOfFrame endOfFrame = new WaitForEndOfFrame();
public readonly static WaitForFixedUpdate fixedUpdate = new WaitForFixedUpdate();
@andrew-raphael-lukasik
andrew-raphael-lukasik / MirrorThisTransformInEcsWorld.cs
Last active May 31, 2023 16:34
Mirror hundreds of `Transform`s in an ECS `World` easily. Uses `IJobParallelForTransform`/`TransformAccessArray`
// src* https://gist.github.com/andrew-raphael-lukasik/530e90ee27cd7a9be47351e03b2634d1
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Jobs;
using Unity.Entities;
using Unity.Transforms;
using Unity.Rendering;
using Unity.Collections;
using Unity.Mathematics;
// src: https://gist.github.com/andrew-raphael-lukasik/bc05310efcb1bcb2875a376494414f36
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
public interface INativeMinHeapComparer<I,V>
where I : unmanaged
where V : unmanaged
{
int Compare ( I lhs , I rhs , NativeSlice<V> comparables );
}
@andrew-raphael-lukasik
andrew-raphael-lukasik / Persistence.cs
Last active July 10, 2023 08:38
Skeleton structure for a save system.
// src: https://gist.github.com/andrew-raphael-lukasik/e02f21cc507da9e5eb7569b8793e70f4
using System.Collections.Generic;
using System.Linq;
using IO = System.IO;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.UIElements;
#if UNITY_EDITOR
using UnityEditor.UIElements;
#endif