Skip to content

Instantly share code, notes, and snippets.

View thebeardphantom's full-sized avatar

Mika Notarnicola thebeardphantom

View GitHub Profile
@thebeardphantom
thebeardphantom / EditorHelper.cs
Created July 29, 2019 03:13
Show confirmation dialog before actually quitting the Unity Editor.
using UnityEditor;
[InitializeOnLoad]
public static class EditorHelper
{
#region Constructors
static EditorHelper()
{
EditorApplication.wantsToQuit += OnEditorWantsToQuit;
@thebeardphantom
thebeardphantom / ExecuteEditorTests.cs
Last active November 11, 2018 08:01
How to execute edit mode tests from script. Only subscribes to finished events. Requires that you can reference test assemblies.
private static void ExecuteTests()
{
// Select all types in appdomain
var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()).ToArray();
// Need to create an empty runner filter
var filterType = types.First(t => t.Name == "TestRunnerFilter");
var filter = Activator.CreateInstance(filterType);
// Create a test launcher
@thebeardphantom
thebeardphantom / GameApp.cs
Created November 30, 2017 08:28
Dead simple dependency injection micro-framework, minus C# object ctor calling support
using UnityCommonLibrary;
using UnityEngine;
/// <summary>
/// Application lifecycle management class
/// </summary>
public static class GameApp
{
/// <summary>
/// Active service container
@thebeardphantom
thebeardphantom / SceneListExporter.cs
Last active September 11, 2022 23:21
Unity doesn't provide an API to get all of the scenes in your build. This script will automatically (at script reload), or manually through the Assets menu, generate a text file that contains all of your enabled scenes in your build settings in a Resources folder. This can then be read at runtime and stored in an array.
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
public static class SceneListExporter
{
[DidReloadScripts]
[MenuItem("Assets/Generate Scene List")]
@thebeardphantom
thebeardphantom / NavMeshAgentVisualizer.cs
Last active April 24, 2017 17:48
NavMeshAgent's shape visualization is broken! Here's a temporary fix. Attach this to a NavMeshAgent's GameObject to get an accurate visualization.
using UnityEngine;
using UnityEngine.AI;
[RequireComponent(typeof(NavMeshAgent))]
[ExecuteInEditMode]
public class NavMeshAgentVisualizer : MonoBehaviour
{
#if UNITY_EDITOR
private NavMeshAgent agent;
private Mesh cylinderMesh;
@thebeardphantom
thebeardphantom / Services.cs
Last active March 8, 2017 07:44
An example of how to register services immediately at runtime in Unity.
using UnityEngine;
using UnityCommonLibrary;
using UnityCommonLibrary.Messaging;
using System;
public static class Services
{
public class DebugServiceLocator : ServiceLocator
{
protected override void RegisterServices()
@thebeardphantom
thebeardphantom / AssetManager.cs
Last active January 25, 2017 07:12
A simple endpoint for replacing Unity's Resources folder.
#if UNITY_EDITOR
using UnityEditor;
#endif
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public static class AssetManager
{
private const string ASSET_PATH = "Assets/_core/bundled_assets";
@thebeardphantom
thebeardphantom / AssetLookup.cs
Created November 18, 2016 06:33
AssetLookup
[CreateAssetMenu]
public class AssetLookup : ScriptableObject
{
private static AssetLookup _get;
public static AssetLookup get
{
get
{
if(_get)
@thebeardphantom
thebeardphantom / ColorPalette.cs
Created October 8, 2016 18:37
Dead simple single class for globalizing colors across your Unity game.
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(menuName = "KingMe/ColorPalette")]
public class ColorPalette : ScriptableObject
{
[SerializeField]
private List<NamedColor> list = new List<NamedColor>();
public static Color GetColor(string palette, string key)
[MenuItem("Game Tools/CompoundColliderBuilder")]
private static void DoCompoundCollider()
{
var obj = Selection.activeGameObject;
var meshCollider = obj.GetComponent<MeshCollider>();
if (!meshCollider)
{
return;
}
var meshBounds = meshCollider.bounds;