Skip to content

Instantly share code, notes, and snippets.

View sabresaurus's full-sized avatar

Sabresaurus sabresaurus

View GitHub Profile
@sabresaurus
sabresaurus / WindowKiller.cs
Created January 29, 2019 23:06
If an editor window breaks (due to an issue with serialized internal state for example) it can be a pain to close and reopen it as the context menu for closing it no longer works. This utility allows you to close any editor window.
// MIT License
//
// Copyright (c) 2019 Sabresaurus
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// Example of how to use AutoComponent ( https://gist.github.com/sabresaurus/339fcaab18ea7c6a2c53 )
[AutoComponent(RecursiveDirection.Up)]
Agent parentAgent;
[AutoComponent(RecursiveDirection.Down)]
MuzzleFlash muzzleFlash;
[AutoComponent(RecursiveDirection.Down)]
GunAnimator gunAnimator;
@sabresaurus
sabresaurus / SharedPaletteData.cs
Created November 10, 2019 17:00
Part of SharedPaletteWindow, must be its own file so that Unity can serialize the scriptable object correctly.
// MIT License
//
// Copyright (c) 2019 Sabresaurus
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@sabresaurus
sabresaurus / ConditionalVisibilityAttribute.cs
Created October 16, 2019 19:17
Allows you to restrict visibility of serialised fields based on an attribute, e.g. [ConditionalVisibility("siblingBool","True"),SerializeField] float foo = 0;
// MIT License
//
// Copyright (c) 2019 Sabresaurus
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@sabresaurus
sabresaurus / RagdollTest.cs
Created September 15, 2019 12:28
Toggle between animations and ragdoll
// MIT License
//
// Copyright (c) 2019 Sabresaurus
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
using UnityEngine;
using System.Collections.Generic;
using Sabresaurus.SabreCSG;
public class RuntimeCSGExample1 : MonoBehaviour
{
[SerializeField]
int count = 30; // Number of brushes to create
[SerializeField]
@sabresaurus
sabresaurus / BSPTreePostProcess.cs
Last active September 19, 2016 19:04
Makes generated mesh colliders compatible with SuperCharacterController (https://github.com/IronWarrior/SuperCharacterController)
#if UNITY_EDITOR
using UnityEngine;
using Sabresaurus.SabreCSG;
public static class BSPTreePostProcess
{
[PostProcessCSGBuild]
public static void OnPostProcessCSGBuild(Transform meshGroup)
{
if(meshGroup != null)
using UnityEngine;
using System.Collections.Generic;
using Sabresaurus.SabreCSG;
public class RuntimeCSGExample2 : MonoBehaviour
{
// Number of cells to create in the X and Z axis
[SerializeField]
int cellXCount = 10;
[SerializeField]
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using Type = System.Type;
public static class DuplicationUtility
{
public static GameObject DuplicateGameObject(GameObject source)