Skip to content

Instantly share code, notes, and snippets.

@DomDomHaas
DomDomHaas / ScenePaletteSwitcherInspector.cs
Created February 16, 2017 09:19
The Editor script for the ScenePaletteSwitcher.cs (https://gist.github.com/DomDomHaas/518d60d388bc593b2ffa5975abb9172b Is only working with the ColorPalettes u3d.as/bFr extension)
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
#pragma warning disable 3009
namespace MrWhaleGames.ColorPalette
{
@DomDomHaas
DomDomHaas / SaveHook
Created December 7, 2014 17:43
Unity SaveHook to save all persistencyIds
using UnityEngine;
using UnityEditor;
using JSONPersistency;
using UnityEditor.Callbacks;
public class SaveSceneHook : AssetModificationProcessor
{
static string[] OnWillSaveAssets (string[] paths)
{
@DomDomHaas
DomDomHaas / Arduino Tinylab Debounce Buttons
Created November 1, 2016 23:02
arduino Tinylab buttons handling in a debounce style
// This example code is based on http://www.arduino.cc/en/Tutorial/Debounce
boolean debug = true;
long debounceDelay = 50;
class LEDButton{
public:
int buttonPin = 0;
int buttonState = 0;
int lastButtonState = LOW;
@DomDomHaas
DomDomHaas / ScreenshotSequencer
Last active February 25, 2016 08:12
ScreenshotSequencer for Unity. Choose a Key to hit while taking a Sequence of Screenshots.
#if UNITY_EDITOR
// only got it to work in the Editor
using UnityEngine;
using System;
using System.Collections;
using System.IO;
public class ScreenshotSequencer : MonoBehaviour
@DomDomHaas
DomDomHaas / PostBuildHook
Last active August 29, 2015 14:11
PostBuildHook for Unity
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor.Callbacks;
using UnityEditor;
using System.IO;
public static class PostBuildHook
{
private static int filecount;
@DomDomHaas
DomDomHaas / DragNDropInspector
Created November 14, 2014 09:02
Unity Editor Drag'n'Drop
using UnityEngine;
using UnityEditor;
using System.Collections;
using JSONPersistency;
[CustomEditor(typeof(DragNDrop))]
public class DragNDropInspector : Editor
{
Color picked = Color.green;
@DomDomHaas
DomDomHaas / DrawCircle_Unity
Created November 11, 2014 11:29
Unity Inspector script to draw a circle in the SceneView
using UnityEngine;
using UnityEditor;
// replace "SpawnZone" with the class of your Script on a GameObject
[CustomEditor(typeof(SpawnZone))]
public class SpawnZoneInspector : Editor
{
// replace "SpawnZone" with the class of your Script on a GameObject
private SpawnZone myZone;
@DomDomHaas
DomDomHaas / reorderableList
Created October 8, 2014 22:04
ReorderableList for Unity
private ReorderableList list;
list = new ReorderableList(property.serializedObject, property.FindPropertyRelative("tagList"), true, true, true, true);
list.drawHeaderCallback += rect => GUI.Label(rect, label);
list.drawElementCallback += (rect, index, active, focused) =>
{
rect.height = 16;
rect.y += 2;
EditorGUI.PropertyField(rect,
list.serializedProperty.GetArrayElementAtIndex(index),
@DomDomHaas
DomDomHaas / stick-deadzone
Last active August 29, 2015 14:07
Use a deadzone for very used, old controllers which aren't percise anymore
// http://www.third-helix.com/2013/04/12/doing-thumbstick-dead-zones-right.html
float deadzone = 0.25f;
Vector2 stickInput = new Vector2(Input.GetAxis(“Horizontal”), Input.GetAxis(“Vertical”));
if(stickInput.magnitude < deadzone)
stickInput = Vector2.zero;
else
stickInput = stickInput.normalized * ((stickInput.magnitude - deadzone) / (1 - deadzone));
@DomDomHaas
DomDomHaas / gist:e31156e8c67dbcad8637
Last active August 29, 2015 14:07
Unity RayCast from clicking
Vector3 clickPos = new Vector3 (Input.mousePosition.x, Input.mousePosition.y, 0);
Ray camRay = Camera.main.ScreenPointToRay (clickPos);
RaycastHit hit;
if (Physics.Raycast (camRay.origin, camRay.direction,
out hit, rayLength, fieldMask)) {
// do awesome stuff here
}