Skip to content

Instantly share code, notes, and snippets.

@Refsa
Refsa / SerializedPropertyExtensions.cs
Last active September 16, 2019 06:54
Getting the SerializedProperty of the actual object of a CustomPropertyDrawer, when the object is stored in a List
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEditor;
public static class SerializedPropertyExtensions
{
// Takes the property path and does a regex to find all the sub paths to reach the actual object,
// then follows the path to find the actual SerializedProperty
//
// Example of how a property path string looks like in an extreme use case:
@Refsa
Refsa / DebugExtensions.cs
Created October 11, 2019 02:19
Clear the content of the debug console window
using UnityEngine;
public static class DebugExtensions
{
public static void ClearConsole ()
{
var logentries = System.Type.GetType ("UnityEditor.LogEntries, UnityEditor.dll");
var clearmethod = logentries.GetMethod ("Clear", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
clearmethod.Invoke (null, null);
}
@Refsa
Refsa / BetterBounds.cs
Last active October 22, 2019 09:30
Seperate Axis Theorem on two box bounds
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BetterBounds
{
public Vector3 center;
public Vector3 size;
public Quaternion rotation;
@Refsa
Refsa / DeferredArrayExample.cs
Created April 22, 2020 20:55
Unity DOTS: How to use Deferred Array function on NativeList to consume the lists content before it's job has completed
protected override void OnUpdate()
NativeList<int> testList = new NativeList<int>(10, Allocator.TempJob);
Job.
WithCode(
() => {
for (int i = 0; i < 10; i++)
testList.Add(i);
}
)
@Refsa
Refsa / ExamplePreferenceProvider.cs
Created April 23, 2020 16:00
Open Unity Preferences window to specific preference provider
// As an example it will look for the name specified in the SettingsProvider
using UnityEditor;
public static class PreferenceProviderExample
{
[SettingsProvider]
public static SettingsProvider CreateSettingsProvider()
{
var provider = new SettingsProvider("YourPreference", SettingsScope.User)
@Refsa
Refsa / GitHubTagsResponse.cs
Last active April 24, 2020 06:19
Unity Package Manager updater for Unity UPM packages on GitHub using Git Tags for versions
// Object representation of the json result from the GitHub tags API
[System.Serializable]
class GitHubTagsResponseCommit
{
public string sha;
public string url;
}
[System.Serializable]
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class FPSCounterIMGUI : MonoBehaviour
{
[SerializeField] int maxFrames = 100;
Queue<float> avgFPS = new Queue<float>();
@Refsa
Refsa / ProceduralQuads.compute
Last active August 27, 2020 05:44
Lockless drawing of procedural quads on the GPU in Unity - 16 million quads on a 2070 @ 60FPS
#pragma kernel Setup
#pragma kernel Runtime
struct RenderData
{
float3 Position;
float4 Color;
};
// From: https://thebookofshaders.com/11/
@Refsa
Refsa / GrabScreenFeature.cs
Last active April 9, 2024 13:04
Unity URP custom grab pass
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class GrabScreenFeature : ScriptableRendererFeature
{
[System.Serializable]
public class Settings