Skip to content

Instantly share code, notes, and snippets.

View thebeardphantom's full-sized avatar

Mika Notarnicola thebeardphantom

View GitHub Profile
@thebeardphantom
thebeardphantom / AssemblyDefinitionCleanupPostProcessor.cs
Last active March 31, 2024 23:19
Sorts imports of an AssemblyDefinition asset in Unity.
#define POSTPROCESSOR_ENABLED
using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEditorInternal;
using Debug = UnityEngine.Debug;
@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 / PoissonJob.cs
Created January 29, 2024 09:03
A port of Fast Poisson Disk Sampling for Unity to the Jobs System (https://gist.github.com/a3geek/8532817159b77c727040cf67c92af322)
using System;
using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
using Unity.Mathematics;
using UnityEngine;
using Random = Unity.Mathematics.Random;
/*
* A port of Fast Poisson Disk Sampling for Unity to the Jobs System.
@thebeardphantom
thebeardphantom / CsvDataGenerator.CsvFile.cs
Last active January 27, 2024 11:06
An example of generating ScriptableObjects and populating their serialized properties via CSV files.
using System;
using System.Linq;
using UnityEngine;
public static partial class CsvDataGenerator
{
#region Types
public class CsvFile
{
@thebeardphantom
thebeardphantom / ZeroAll.cs
Last active December 4, 2023 07:51
A quick way to reset transforms in Unity3D!
using UnityEngine;
using System.Collections;
using UnityEditor;
namespace BSGTools {
namespace EditorUtilities {
public class ZeroAll : Editor {
[MenuItem("GameObject/Reset/Zero All %&a")]
static void ResetAll() {
GameObject[] selection = Selection.gameObjects;
@thebeardphantom
thebeardphantom / GSheetImporter.cs
Last active October 29, 2023 10:35
Simple .gsheet to TextAsset ScriptedImporter for Unity, with code from https://gist.github.com/jasonleehodges/359eb2af0d1caec0153bb7450c165ffd
[ScriptedImporter(1, "gsheet")]
public class GSheetImporter : ScriptedImporter
{
#region Types
private class WebClientEx : WebClient
{
#region Fields
private readonly CookieContainer _container;
@thebeardphantom
thebeardphantom / BlenderSupportFunctions.cs
Last active September 4, 2023 16:49
Improvements to Unity <-> Blender <-> FBX <-> Blendfile workflows. See readme.txt.
using System;
using System.Diagnostics;
using System.IO;
using Unity.Logging;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
using Debug = UnityEngine.Debug;
public class BlenderSupportFunctions : AssetPostprocessor
@thebeardphantom
thebeardphantom / SerializedPropertyUtility.cs
Created March 4, 2021 23:34
Find FieldInfo for a given SerializedProperty.
public static class SerializedPropertyUtility
{
private static readonly MethodInfo getFieldInfoFromProperty;
static SerializedPropertyUtility()
{
var scriptAttributeUtility = typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.ScriptAttributeUtility");
Assert.IsNotNull(scriptAttributeUtility, "ScriptAttributeUtility != null");
getFieldInfoFromProperty = scriptAttributeUtility.GetMethod(nameof(GetFieldInfoFromProperty), BindingFlags.NonPublic | BindingFlags.Static);
@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 / AttenuationCurve.cs
Last active June 17, 2022 23:42
AttenuationCurve
using System;
using Unity.Mathematics;
using UnityEngine;
[Serializable]
public struct AttenuationCurve
{
#region Properties
[field: SerializeField]