Skip to content

Instantly share code, notes, and snippets.

View LotteMakesStuff's full-sized avatar
💤
sleepy

LotteMakesStuff LotteMakesStuff

💤
sleepy
View GitHub Profile
@LotteMakesStuff
LotteMakesStuff / HighlightAttribute.cs
Last active April 10, 2024 11:52
Having trouble finding the right property on a component cos theres just so many identical looking fields? Add some color to you inspectors! mark important property with a bright color so it always stands out, or supply a validation function so highlights show on values that would effect the current ingame logic!
// NOTE DONT put in an editor folder
using UnityEngine;
public class HighlightAttribute : PropertyAttribute
{
public HighlightColor Color;
public string ValidateMethod;
public object Value;
@LotteMakesStuff
LotteMakesStuff / PlayerLoop.cs
Last active March 25, 2024 02:38
Player Loop Visualizer: Built to explore the new PlayerLoopSystem api in Unity 2018.1b2. This tool shows you all the PlayerLoop systems that unity uses to update a frame, and demos how to add your own and even remove systems from the player loop. For more info see the patreon post https://www.patreon.com/posts/unity-2018-1-16336053
// Put this in an editor folder
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.Experimental.LowLevel;
using UnityEngine.Profiling;
@LotteMakesStuff
LotteMakesStuff / Flicker.cs
Created June 16, 2021 04:49
Quake/Halflife style light flicker
using UnityEngine;
public class Flicker : MonoBehaviour
{
public string LightStyle = "mmamammmmammamamaaamammma";
private Light light;
public float loopTime = 2f;
[SerializeField]
private int currentIndex = 0;
@LotteMakesStuff
LotteMakesStuff / NativeMeshTest.cs
Created August 8, 2018 00:30
[NativeCollections] How to copy a regular .C# array into a NativeArray suuuuuper quick using memcpy. its about as fast as its ever gunna get!
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Mathematics;
using UnityEngine;
public class NativeMeshTest : MonoBehaviour
{
private NativeArray<float3> vertexBuffer;
private Vector3[] vertexArray;
@LotteMakesStuff
LotteMakesStuff / EditorDispatcher.cs
Last active February 13, 2024 13:22
Allows threaded Unity Editor code to dispatch an action or coroutine to the main thread.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEditor;
using UnityEngine;
public static class EditorDispatcher
{
private static readonly Queue<Action> dispatchQueue = new Queue<Action>();
@LotteMakesStuff
LotteMakesStuff / Colors.cs
Created April 6, 2017 23:45
Trying to set Colours from code but need something better than the few that unity provide and dont wanna mess around with colour values for ages? Colors is your friend!!!
using UnityEngine;
public class Colors
{
// NOTE: The follwing color names come from the CSS3 specification, Section 4.3 Extended Color Keywords
// http://www.w3.org/TR/css3-color/#svg-color
public static readonly Color AliceBlue = new Color32(240,248,255,255);
public static readonly Color AntiqueWhite = new Color32(250,235,215,255);
public static readonly Color Aqua= new Color32(0,255,255,255);
@LotteMakesStuff
LotteMakesStuff / TrafficLightAttribute.cs
Last active February 2, 2024 15:58
TrafficLight control/layout/property drawer: Adds a new editor control that draws lil Traffic Lights in the inspector. its really useful for visualizing state. For example, checkboxes can be hard to read at a glace, but a Red or Green status light is easy! Recommend you use the attached package, as it has all the icon image files.
// Non Editor code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class TrafficLightAttribute : PropertyAttribute
{
public bool DrawLabel = true;
public string CustomLabel;
public bool AlsoDrawDefault;
@LotteMakesStuff
LotteMakesStuff / AutohookAttribute.cs
Last active January 2, 2024 13:54
[Autohook] property drawer for unity - Add this [Autohook] attribute to a property to and the inspector will automagically hook up a valid reference for you if it can find a component attached to the same game object that matches the field you put it on. You can watch a demo of this in action here https://youtu.be/faVt09NGzws <3
// NOTE DONT put in an editor folder!
using UnityEngine;
public class AutohookAttribute : PropertyAttribute
{
}
@LotteMakesStuff
LotteMakesStuff / LayoutUtils.cs
Last active November 2, 2023 21:04
Simple tool for importing editor layout files (.wlt files) from the asset folder. this is cool cos you can then share layouts with your team via source control
// put me in an Editor folder
using System.IO;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
public static class LayoutUtils
{
// unity stores layouts in a path referenced in WindowLayout.LayoutsPreferencesPath.
// Unfortunately, thats internal - well just creat the path in the same way they do!
@LotteMakesStuff
LotteMakesStuff / LookatTool.cs
Last active November 2, 2023 21:04
In Unity 2019.1 Unity added a new custom EditorTool API, heres some example code showing some tools we could make with it!
using UnityEditor;
using UnityEditor.EditorTools;
using UnityEngine;
[EditorTool("LookAt Tool")]
public class LookatTool : EditorTool
{
GUIContent cachedIcon;
// NOTE: as were caching this, unity will serialize it between compiles! so if we want to test out new looks,