Skip to content

Instantly share code, notes, and snippets.

View ByronMayne's full-sized avatar

Byron Mayne ByronMayne

View GitHub Profile
@ByronMayne
ByronMayne / AssemblyUtility.cs
Created January 20, 2018 18:33
A simple method to force Unity Editor to recompile all scripts.
public class AssemblyUtility
{
/// <summary>
/// Forces Unity to recompile all scripts and then refresh.
/// </summary>
public static void DirtyAllScripts()
{
// Grab the UnityEditor assembly
Assembly editorAssembly = typeof(UnityEditor.Editor).Assembly;
// Find the type that contains the method we want
@ByronMayne
ByronMayne / CollapsableEventDrawer.cs
Last active September 27, 2022 19:04
Override the default UnityEventDrawer to draw a very small version when there are no callbacks.
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Events;
[CustomPropertyDrawer(typeof(UnityEvent))]
public class CollapsableEventDrawer : UnityEventDrawer
{
@ByronMayne
ByronMayne / ExampleWeaverComponent.cs
Created November 28, 2017 17:23
This is an example weaver componet
using System;
using Mono.Cecil;
using UnityEngine;
using Mono.Cecil.Cil;
namespace Weaver
{
// Inherit WeaverComponent to get callbacks and to show up as a componet in our ScriptableObject settings.
public class ServerCommandComponent : WeaverComponent
{
@ByronMayne
ByronMayne / AssetIterator.cs
Created November 1, 2017 12:54
A simple to use script for Unity that lets you loop over all scenes and/or prefabs and get a callback for each Behaviour, Property, and/or GameObject.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;
public delegate void VistedDelegate<T>(T instance);
@ByronMayne
ByronMayne / DelayCall.cs
Created November 1, 2017 12:47
Delay Call, A simple to use script used to replace using coroutines to delay functions in Unity.
using System;
using System.Reflection;
using UnityEngine;
public static class DelayCall
{
public delegate void DelayedDelegate();
public delegate void DelayedDelegate<T>(T parameter);
private static int DEFAULT_POOL_SIZE = 5;
@ByronMayne
ByronMayne / TheSolution.cs
Created October 6, 2017 17:30
You don't have to use reflection if everything is public
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mono.Cecil;
using UnityEditor;
using UnityEditorInternal;
public class TheSolution
{
[MenuItem("The Solution/Do It...")]
@ByronMayne
ByronMayne / FolderInspector
Created June 13, 2017 03:41
The code from your Unity tip from 6/13/2017
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(DefaultAsset), editorForChildClasses: true, isFallback = false)]
public class FolderInspector : Editor
{
private int m_ContentCount;
private GUIStyle m_TitleStyle;
private GUIStyle m_ListStyle;
@ByronMayne
ByronMayne / AnimatedComponent.cs
Created May 29, 2017 11:17
The source code behind my Unity tip.
using UnityEngine;
using System.Collections;
// This is not need but I just wanted to make the point clear.
public class AnimatedComponent : MonoBehaviour
{
}
@ByronMayne
ByronMayne / GUICarousel
Created February 11, 2017 21:56
A simple to use IMGUI Carousel
using UnityEngine;
using UnityEditor;
using UnityEditor.AnimatedValues;
using UnityEngine.Events;
public class GUICarousel
{
// Delegates
public delegate void OnDrawElementCallbackDelegate(Rect rect, SerializedProperty element, bool isSelected);
public delegate void OnDrawToolbarCallbackDelegate(Rect rect);
@ByronMayne
ByronMayne / Point
Last active May 5, 2018 16:01
A int version of a Vector2 in Unity. Supports explicit conversion between the two types as well as a few helpful helper functions. The second script is a property drawer that supports panning of values and right clicking to reset the value to zero (taking from 3Ds Max).
using UnityEngine;
using System;
[Serializable]
public struct Point
{
[SerializeField]
public int x;
[SerializeField]
public int y;