Skip to content

Instantly share code, notes, and snippets.

@Kroporo
Kroporo / OpenXRRestarterKiller.cs
Created November 15, 2022 15:10
Workaround to console spam caused by `OpenXRRestarter` introduced in `com.unity.xr.openxr@1.5.1` -> "Failure to restart OpenXRLoader after shutdown"
using UnityEngine;
using UnityEditor;
using System.Reflection;
using System;
// This class finds and kills a coroutine that throws errors inside the editor every 5 seconds if no headset is connected
// The coroutine was introduced in the OpenXR Plugin [1.5.1] - 2022-08-11
// There absolutely has to be a better way, and this code should NOT be maintained incase the issue is resolved
public class OpenXRRestarterKiller : MonoBehaviour {
private static bool isHookedIntoUpdate = false;
@jeffvella
jeffvella / NativeDebugger.cs
Last active September 28, 2023 13:17
Debug Logger that works in burst and any thread.
using System;
using System.Diagnostics;
using Unity.Burst;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Jobs.LowLevel.Unsafe;
using Unity.Mathematics;
using UnityEditor;
using Debug = UnityEngine.Debug;
using System.Runtime.CompilerServices;
@phi-lira
phi-lira / UnlitTexture.shader
Last active March 23, 2024 18:12
URP Unlit Texture example
Shader "Custom/UnlitTexture"
{
Properties
{
[MainColor] _BaseColor("BaseColor", Color) = (1,1,1,1)
[MainTexture] _BaseMap("BaseMap", 2D) = "white" {}
}
// Universal Render Pipeline subshader. If URP is installed this will be used.
SubShader
@asus4
asus4 / NativeArrayExtension.cs
Last active February 2, 2023 16:12
NativeArray -> byte[] , byte[] -> NativeArray
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
namespace ARKitStream.Internal
{
public static class NativeArrayExtension
{
public static byte[] ToRawBytes<T>(this NativeArray<T> arr) where T : struct
{
var slice = new NativeSlice<T>(arr).SliceConvert<byte>();
@MephestoKhaan
MephestoKhaan / TextureArrayCreator.cs
Created October 3, 2018 16:52
A quick wizard to create Texture Array assets from normal textures in unity
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
namespace MK.Utilities
{
public class TextureArrayCreator : ScriptableWizard
{
[MenuItem("Window/Texture Array Creator")]
@bugshake
bugshake / SortedGizmos.cs
Created September 28, 2018 12:27
Depth sorted Gizmos in the Unity Editor
using System;
using System.Collections.Generic;
using UnityEngine;
public static class SortedGizmos
{
static List<ICommand> commands = new List<ICommand>(1000);
public static Color color { get; set; }
@belzecue
belzecue / CameraTrackingRefraction.cs
Created May 21, 2018 19:15 — forked from runevision/CameraTrackingRefraction.cs
Unity CommandBuffer replacement for GrabPass - works with multiple separate cameras.
using UnityEngine;
using UnityEngine.Rendering;
// This script is added to cameras automatically at runtime by the ObjectNeedingRefraction scripts.
public class CameraTrackingRefraction : MonoBehaviour {
[System.NonSerialized]
public int lastRenderedFrame = -1;
Camera cam;
@Borod4r
Borod4r / FBSucks.cs
Last active March 11, 2022 02:53
Share image with text on android (works with FB)
private static void ShareImageWithTextOnAndroid(string message, string imageFilePath)
{
AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");
intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));
AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", "file://" + imageFilePath);
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject);
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), message);
@tgjones
tgjones / HlslAntlrLexer.g4
Created May 25, 2015 10:17
ANTLR4 grammar for HLSL
lexer grammar HlslAntlrLexer;
@lexer::header {#pragma warning disable 3021}
AppendStructuredBuffer : 'AppendStructuredBuffer';
Bool : 'bool';
Bool1 : 'bool1';
Bool2 : 'bool2';
Bool3 : 'bool3';
Bool4 : 'bool4';