Skip to content

Instantly share code, notes, and snippets.

View ByronMayne's full-sized avatar

Byron Mayne ByronMayne

View GitHub Profile
@ByronMayne
ByronMayne / Injector.cs
Last active April 30, 2020 13:35
This code is used to inject a callback into Unity's internal build system. They should have this but if you really want to you can just make your own. This only needs Mono.Cecil #Magic
public class Injector
{
[MenuItem("Hacks/Inject Build Callback")]
public static void BuildCallback()
{
Assembly.BeginEditingAssembly(AssemblyTypes.UnityEditor, editAlreadyModifed:true);
{
TypeDefinition buildPiplelineType = Assembly.GetType<BuildPipeline>();
MethodDefinition buildInternalMethod = buildPiplelineType.GetMethod("BuildPlayerInternal");
@ByronMayne
ByronMayne / VersionUpdater.cs
Created September 14, 2016 01:43
This script will bump your build version number every time you make a build.
using UnityEditor;
using UnityEngine;
using UnityEditorInternal;
using System.Linq;
using Version = System.Version;
using UnityEditor.Callbacks;
public class VersionUpdate
{
private const string PLAYER_SETTINGS_ASSEMBLY_NAME = "UnityEditor.PlayerSettings";
@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;
@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 / 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 / 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 / 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 / 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 / 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 / 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
{