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 / RequireReference.cs
Last active Jul 9, 2018
Mark your fields with [RequireReference] attribute to make them glow red if null
View RequireReference.cs
//SOURCE: https://gist.github.com/andrew-raphael-lukasik/60e6dc072dc170ab535a7aff961c3ba9
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
//TODO: Add build-time warnings
@andrew-raphael-lukasik
andrew-raphael-lukasik / Wait.cs
Last active Oct 3, 2018
WaitForSeconds cached means no more memory leaks in coroutines
View Wait.cs
//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();
View SevenZipHelper.cs
using System;
using System.IO;
namespace SevenZip.Compression.LZMA
{
public static class SevenZipHelper
{
static int dictionary = 1 << 23;
View DynamicMeshData.cs
using UnityEngine;
using Unity.Collections;
using Unity.Mathematics;
public class DynamicMeshData : System.IDisposable
{
#region FIELDS & PROPERTIES
View CoroutineController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CoroutineController : MonoBehaviour
{
static CoroutineController _singleton;
static Dictionary<string,IEnumerator> _routines = new Dictionary<string,IEnumerator>(100);
[RuntimeInitializeOnLoadMethod( RuntimeInitializeLoadType.BeforeSceneLoad )]
@andrew-raphael-lukasik
andrew-raphael-lukasik / raycast_tester.cs
Created Aug 17, 2020
raycast hit normal to useful quaternion
View raycast_tester.cs
void OnDrawGizmos ()
{
Vector3 origin = transform.position, dir = transform.forward;
float maxDist = 100f;
if( Physics.Raycast( origin:origin , direction:dir , hitInfo:out var hit , maxDistance:maxDist ) )
{
// normal vector:
Gizmos.color = Color.magenta;
Gizmos.DrawLine( hit.point , hit.point+hit.normal );
@andrew-raphael-lukasik
andrew-raphael-lukasik / MeshTrianglesToEdges.cs
Created Sep 19, 2020
creates array of edges from array of mesh triangles
View MeshTrianglesToEdges.cs
int2[] ToEdges ( int[] triangles )
{
var edges = new Dictionary<ulong,int2>();
for( int i=0 ; i<triangles.Length ; i+=3 )
{
int a = triangles[i];
int b = triangles[i+1];
int c = triangles[i+2];
ulong hash;
@andrew-raphael-lukasik
andrew-raphael-lukasik / SelectionSystem.cs
Last active Dec 7, 2020
Simple entity selection system
View SelectionSystem.cs
// src: https://gist.github.com/andrew-raphael-lukasik/917046557baed6646c9fdc3b40671307
using UnityEngine;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Collections;
using Unity.Rendering;
[UpdateInGroup( typeof(PresentationSystemGroup) )]
public class SelectionSystem : SystemBase
{
@andrew-raphael-lukasik
andrew-raphael-lukasik / NoiseFieldMesh.cs
Last active Jan 4, 2021
MonoBehaviour * Unity.Jobs = simple and fast dynamic mesh generation method.
View NoiseFieldMesh.cs
// src: https://gist.github.com/andrew-raphael-lukasik/c83f1d9b3a356f36e0c66ddffbae3271
using System.Runtime.CompilerServices;
using UnityEngine;
using Unity.Mathematics;
using Unity.Collections;
using Unity.Jobs;
[RequireComponent( typeof(MeshFilter) , typeof(MeshRenderer) )]
public class NoiseFieldMesh : MonoBehaviour
{
@andrew-raphael-lukasik
andrew-raphael-lukasik / NoiseFieldAuthoring.cs
Last active Jan 4, 2021
Generates noise field meshes with no seems between them (useful for generating terrain meshes).
View NoiseFieldAuthoring.cs
// src: https://gist.github.com/andrew-raphael-lukasik/104e5826015c2f4d47021ba564e9bfe8
// REQUIRES: com.unity.rendering.hybrid package
using System.Runtime.CompilerServices;
using System.Collections.Generic;
using UnityEngine;
using Unity.Mathematics;
using Unity.Entities;
using Unity.Rendering;
using Unity.Collections;
using Unity.Transforms;