Skip to content

Instantly share code, notes, and snippets.

Avatar
🏴‍☠️

Andrew Raphael Lukasik andrew-raphael-lukasik

🏴‍☠️
View GitHub Profile
@andrew-raphael-lukasik
andrew-raphael-lukasik / .Unity.Jobs Utilities
Last active Sep 14, 2022
Write to managed arrays from an `IJob` ! A collections of useful utilities when working with `Unity.Jobs`.
View .Unity.Jobs Utilities
### Highlights
- cast T[] to NativeArray<T>
- schedule jobs that read/write to managed arrays
- pointer safety assertion that prevent crashes and data corruption
- ...
@andrew-raphael-lukasik
andrew-raphael-lukasik / SunController.cs
Last active Aug 23, 2022
basic sun controller script
View SunController.cs
// src* https://gist.github.com/andrew-raphael-lukasik/2f337c0e6c467f084cded9bf63dd8556
using UnityEngine;
public class SunController : MonoBehaviour
{
[SerializeField][Range(0,1)] float _dayTime = 0.5f;// 0.5 means noon
[SerializeField] float _timeScale = 1;
[SerializeField] Light _sun = null;// make sure it is directional
[SerializeField] Vector2 _sunAtMidnight = new Vector2(45,0);// degrees
[SerializeField] Vector2 _earthRotationAxis = new Vector2(-45,0);// degrees, axis relative to your location (so pointing straight up if you are on a N or S pole)
@andrew-raphael-lukasik
andrew-raphael-lukasik / DrawDebugShapesFromAnEditorWindow.cs
Last active Sep 27, 2022
How to draw debug shapes from an EditorWindow ? (URP edition)
View DrawDebugShapesFromAnEditorWindow.cs
// src* https://gist.github.com/andrew-raphael-lukasik/999d776b052fb5f8f1784bd754106559
using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.Rendering;
using UnityEditor;
using UnityEditor.UIElements;
public class DrawDebugShapesFromAnEditorWindow : EditorWindow
{
Vector3Field A, B;
@andrew-raphael-lukasik
andrew-raphael-lukasik / RandomnessAndIJobParallelFor.cs
Last active Aug 18, 2022
lets run some test and figure out how to generate useful random numbers in a `Unity.Collections.IJobParallelFor` run
View RandomnessAndIJobParallelFor.cs
// src* https://gist.github.com/andrew-raphael-lukasik/b767c82969eb67ae76b6351bd31bb558
using UnityEngine;
using Unity.Jobs;
using Unity.Collections;
using Random = Unity.Mathematics.Random;
public class RandomnessAndIJobParallelFor : MonoBehaviour
{
[SerializeField][Min(1)] uint _seed = 1234;
@andrew-raphael-lukasik
andrew-raphael-lukasik / MyTurretComponent.cs
Last active Jul 14, 2022
basic turret with limited gimbal range
View MyTurretComponent.cs
// src* https://gist.github.com/andrew-raphael-lukasik/39977c56509eb60a8d44bd94e77cce7a
using UnityEngine;
public class MyTurretComponent : MonoBehaviour
{
public Transform target;
[SerializeField] float
_reloadtime = 1f ,
_launchForce = 10f;
[SerializeField] Vector2
@andrew-raphael-lukasik
andrew-raphael-lukasik / Planted.cs
Last active May 28, 2022
Example of a grid system built with with ISystemStateComponentData
View Planted.cs
// src: https://gist.github.com/andrew-raphael-lukasik/19170443b976582f97404f6da9875b4c
using UnityEngine;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Collections;
using Unity.Jobs;
namespace Sandbox
{
public class Planted : MonoBehaviour
@andrew-raphael-lukasik
andrew-raphael-lukasik / Binary Reader & Writer.cs
Last active May 26, 2022
Unity.Entities.Serialization.BinaryReader basic implementation
View Binary Reader & Writer.cs
// 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 / CapsuleCapsuleIntersection.cs
Last active Sep 15, 2022
capsule-capsule intersection test (also segment-segment)
View CapsuleCapsuleIntersection.cs
// web* src: https://gist.github.com/andrew-raphael-lukasik/dcf4d308f96852b790f49efb87e462dd
using UnityEngine;
using Unity.Mathematics;
public class CapsuleCapsuleIntersection : MonoBehaviour
{
[SerializeField] CapsuleCollider _capsuleA, _capsuleB;
void OnDrawGizmos ()
{
@andrew-raphael-lukasik
andrew-raphael-lukasik / ButtonThatCanBeDisabled.cs
Created May 14, 2022
UI Toolkit Button class that can be disabled via style sheet or uxml inline property
View ButtonThatCanBeDisabled.cs
// web* src: https://gist.github.com/andrew-raphael-lukasik/69c7858e39e22f197ca51b318b218cc7
using UnityEngine.UIElements;
[UnityEngine.Scripting.Preserve]
public class ButtonThatCanBeDisabled : Button
{
public bool enabled {
get => enabledSelf;
set => SetEnabled(value);
}
View GpuInstancingForGameObjects.cs
// scr* https://gist.github.com/andrew-raphael-lukasik/df4a36ff2ad89078258fd653c422a021
using System.Collections.Generic;
using UnityEngine;
public class GpuInstancingForGameObjects : MonoBehaviour
{
[SerializeField] Camera _camera = null;
[SerializeField] MeshRenderer[] _meshRenderers = new MeshRenderer[0];
/// <summary>