Skip to content

Instantly share code, notes, and snippets.

View beardordie's full-sized avatar

Beard or Die beardordie

View GitHub Profile
@beardordie
beardordie / GrabbablePointerEvents.cs
Last active April 27, 2024 22:05
Meta Interaction SDK: Hide the Controller visuals when a Grabbable is grabbed. How? Get access to the (manually) assigned Data of an Interactor. This version Uses Odin Inspector and UltEvents,. For this to work, you must manually assign the Optionals -> Data object of each Interactor to its sibling ControllerRef component.
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* Licensed under the Oculus SDK License Agreement (the "License");
* you may not use the Oculus SDK except in compliance with the License,
* which is provided at the time of installation or download, or which
* otherwise accompanies this software in either electronic or hard copy form.
*
* You may obtain a copy of the License at
@beardordie
beardordie / gist:043b1d62e1746c36b17b2ccd8f16b7fd
Created December 6, 2023 07:22
How To Force Exit Play mode in Unity when stuck inside an infinite loop - Unity Freeze - Visual Studio - Immediate Window trick fix
// If you're in an infinite loop in Unity, it will hang, and you won't be able to hit the Play button to exit Play mode.
// If you happen to be attached to the Visual Studio debugger, and if you can hit a breakpoint somewhere in the executing infinite loop,
// You have hope!
// You can use Immediate Window to issue a command that will break you out of the infinite loop
// After the breakpoint is hit in Visual Studio, open up the Immediate Window (Debug->Windows->Immediate Window)
// Type this command and hit enter:
// DestroyImmediate(this);
// It will give an error in Unity, and it will destroy the offending GameObject with all its scripts including the infinite loop script
// But now you can hit the Play button to exit Play Mode.
// Now fix that dang script before running it again!
@beardordie
beardordie / JawAnimator.cs
Created December 6, 2023 06:23
Using audiosamples/volume of AudioSource to simply animate a Jaw Transform. As seen here: https://youtu.be/5P_mWSFA4ow
[SerializeField] private AudioSource _linkedAudioSource = null;
[SerializeField] private float _minRmsValue = 0.0001f; // minimum to consider "talking"
[SerializeField] private Renderer _rendererToCheckVisibility = null;
[SerializeField] private float _jawTalkSpeed = 0.12f;
private JawStates _jawState = JawStates.Default;
private float[] _samples = new float[512]; // For spectrum data
private float _rmsValue; // Root mean square, representing audio level
public enum JawStates
@beardordie
beardordie / CustomGameObjectInspector.cs
Last active December 6, 2023 08:05
Custom Game Object Inspector - filter the Inspector to find a property or component, made by Mattimus in the More Mountains Community Discord (updated to work with Unity 2022.3)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
using System.Reflection;
[CustomEditor(typeof(GameObject), true)]
[CanEditMultipleObjects]
public class CustomGameObjectInspector : Editor
@beardordie
beardordie / F10ApplicationQuit.cs
Created March 24, 2020 03:44
Unity - Press F10 to Quit, or stop playing in the Editor.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class F10ApplicationQuit : MonoBehaviour {
public KeyCode keyCode = KeyCode.F10;
// Update is called once per frame
void Update () {
@beardordie
beardordie / F5ReloadScene.cs
Created March 24, 2020 03:43
Unity - Press F5 to reload the current Scene. Used a lot in development. Probably remove before making a public build.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class F5ReloadScene : MonoBehaviour {
public KeyCode keyCode = KeyCode.F5;
// Update is called once per frame
void Update () {
@beardordie
beardordie / CheatCodeDetector.cs
Created March 24, 2020 03:27
A simple Unity Cheat Code system, optionally play a sound when a cheat code is used. Add cheats in the Inspector with UnityEvent, or through code using RegisterCheat method
using UnityEngine;
using System.Collections.Generic;
using System;
using UnityEngine.Events;
[RequireComponent(typeof(AudioSource))]
public class CheatCodeDetector : MonoBehaviour
{
[SerializeField] private List<Cheat> cheats = new List<Cheat>();
@beardordie
beardordie / ScreenFader.cs
Created March 24, 2020 01:50
Example from Unity's Gamekit2D to do fade to Black, Loading, and GameOver screens using multiple CanvasGroups, appearing on top and blocking raycasts beneath
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
namespace Gamekit2D
{
public class ScreenFader : MonoBehaviour
{
public enum FadeType
{
@beardordie
beardordie / SelectionBase.cs
Created March 24, 2020 01:43
Unity - If you want a root GameObject to be selected when you click on a child object such as a mesh, put this MonoBehaviour on the root
using UnityEngine;
[SelectionBase]
public class SelectionBase : MonoBehaviour {
}
@beardordie
beardordie / CustomSettingsMenu.cs
Created March 15, 2020 19:31
Add your own submenu in Unity's Preferences window with various boolean settings that other Editor scripts can make use of
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
namespace CustomSettingsMenuNamespace
{
[InitializeOnLoad]
public class NewCustomSettingsHandler