Skip to content

Instantly share code, notes, and snippets.

View LotteMakesStuff's full-sized avatar
💤
sleepy

LotteMakesStuff LotteMakesStuff

💤
sleepy
View GitHub Profile
@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,
@LotteMakesStuff
LotteMakesStuff / InspectorButtonsTest.cs
Last active November 2, 2023 21:03
Code running pack! two property drawing scripts that make it super easy to trigger code via buttons in the inspector, and get feedback! [TestButton] draws you little buttons that call a method on your MonoBehaviour, and [ProgressBar] give you a great way to show feedback from long running methods. These are *super* helpful for things like proced…
using UnityEngine;
using System.Collections;
public class InspectorButtonsTest : MonoBehaviour
{
[TestButton("Generate world", "DoProcGen", isActiveInEditor = false)]
[TestButton("Clear world", "ClearWorld", 2, isActiveInEditor = false)]
[ProgressBar(hideWhenZero = true, label = "procGenFeedback")]
public float procgenProgress = -1;
@LotteMakesStuff
LotteMakesStuff / PackageManagerExtentionExample.cs
Last active September 4, 2023 02:25
As of v1.9.3, Unity has added a simple extention API to the PackageManager UI. This small example shows you how to implment it and add a new window to the package manager. Note: you will need to change to the Staging package repository as time of writing. This code needs to go in an Editor folder
using System.Linq;
using UnityEditor;
using UnityEditor.PackageManager.UI;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEngine.Experimental.UIElements.StyleEnums;
using PackageInfo = UnityEditor.PackageManager.PackageInfo;
[InitializeOnLoad]
public class PackageManagerExtentionExample : IPackageManagerExtension
@LotteMakesStuff
LotteMakesStuff / DashButton.cs
Created October 31, 2017 22:50
Simple proof of concept editor extention for using amazon dash buttons with Unity
using DashSharp;
using DashSharp.Exceptions;
using DashSharp.Models;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class DashButton : EditorWindow
@LotteMakesStuff
LotteMakesStuff / EditorExtensionMethods.cs
Last active April 28, 2023 09:50
A reimplementation of the logic in the Unity Editor that draws an inspector for a component. We can use this to learn how unity actually draws the inspector. for more info see https://www.patreon.com/posts/16724128
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Reflection;
public static class EditorExtensionMethods
{
// Public reimplmentation of extention methods and helpers that are marked internal in UnityEditor.dll
@LotteMakesStuff
LotteMakesStuff / NetworkingTools.cs
Last active April 28, 2023 09:49
Since Unity 2018.3 we've had this cool new tool called [SettingsProvider] that we can use to add custom settings menu into Unitys settings screens. This short example shows how i use [SettingsProvider] and some [MenuItems] to help build and run test clients when im developing a multiplayer game. My usecase is that i want a quick way to build and…
using System.Collections.Generic;
using System.Diagnostics;
using UnityEditor;
using UnityEditor.Build.Reporting;
using UnityEngine;
using Debug = UnityEngine.Debug;
public static class NetworkingTools
{
@LotteMakesStuff
LotteMakesStuff / StatsBarAttribute.cs
Last active March 24, 2023 16:37
StatsBar property drawer for Unity~ Add a [StatsBar] attribute to a property to make it draw a lil bar, really useful for visualizing character stats like Health or Mana.
// NOTE DONT put in an editor folder
using UnityEngine;
public class StatsBarAttribute : PropertyAttribute
{
public string valueMax;
public StatsBarColor color;
public StatsBarAttribute(string valueMax = null, StatsBarColor color = StatsBarColor.Red)
@LotteMakesStuff
LotteMakesStuff / MinMaxAttribute.cs
Last active March 16, 2023 16:47
MinMax property drawer for Unity - Add a [MinMax] attribute to a property to draw a useful min/max setting slider.
// NOTE DONT put in an editor folder
using UnityEngine;
public class MinMaxAttribute : PropertyAttribute
{
public float MinLimit = 0;
public float MaxLimit = 1;
public bool ShowEditRange;
public bool ShowDebugValues;
@LotteMakesStuff
LotteMakesStuff / 1.md
Last active January 5, 2023 20:54
UPM: How to make a custom package

UPM: How to make a custom package So, Unity has this shiny new package manager, and you have code you want to share between projects - wouldn't it be great if we could bundle up our shared code and plug it into all the projects that need it? Let's figure out how to make our own Package!


Todo

  • Modify the project manifest
  • Make a package manifest
  • Package the manifest up with some test code
  • Try it out in Unity!

@LotteMakesStuff
LotteMakesStuff / ReadOnlyAttribute.cs
Created January 17, 2017 00:17
ReadOnly property drawer for Unity~ Add a [ReadOnly] attribute to a property to make it show up as read only in the inspector
// NOTE DONT put in an editor folder
using UnityEngine;
public class ReadOnlyAttribute : PropertyAttribute { }