Skip to content

Instantly share code, notes, and snippets.

View andydbc's full-sized avatar

andy andydbc

View GitHub Profile
rm -Force ./.git/index.lock
taskkill /F /IM git.exe
@andydbc
andydbc / EditorUtils.cs
Created November 5, 2024 23:19
Helper tool to identify missing component scripts on Prefabs in the project.
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEditor;
public static class EditorUtils
{
static void FindMissingScriptsInGO(GameObject go)
{
@andydbc
andydbc / LightFlicker.cs
Created November 5, 2024 23:21
Randomly flicker a light intensity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Light))]
public class Flicker : MonoBehaviour
{
Light _light;
private float _intensity;
@andydbc
andydbc / MonoBehaviourExtensions.cs
Created November 5, 2024 23:29
Extension methods to execute an action after a specified delay.
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using System;
using System.Collections;
using System.Collections.Generic;
public static class MonoBehaviourExtensions
{
public static Coroutine DelayedAction(this MonoBehaviour m, float delay, System.Action action)
@andydbc
andydbc / UIExtensions.cs
Created November 5, 2024 23:32
Disable a UI element when a mouse click occurs outside its bounding rectangle.
public static class UIExtensions
{
public static bool HideIfClickedOutside(this GameObject panel) {
if (Input.GetMouseButton(0) && panel.activeSelf &&
!RectTransformUtility.RectangleContainsScreenPoint(
panel.GetComponent<RectTransform>(),
Input.mousePosition,
null)) {
panel.SetActive(false);
return false;
@andydbc
andydbc / TriggerEventDispatcher.cs
Created November 5, 2024 23:37
A lightweight helper to forward trigger events from a GameObject to listeners.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class TriggerEventDispatcher : MonoBehaviour
{
public delegate void OnTriggerEnterEvent(Collider other);
public event OnTriggerEnterEvent TriggerEnter;
@andydbc
andydbc / SetTextFromFile.cs
Created November 5, 2024 23:40
Retrieve content from a text file and assign it to a TextMesh component.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
[RequireComponent(typeof(TextMesh))]
[ExecuteInEditMode]
public class SetTextFromFile : MonoBehaviour
{
public TextAsset textFile;
@andydbc
andydbc / DrawLabel.cs
Created November 6, 2024 22:56
A simple utility for displaying object names in the Editor View. It can be used to draw custom labels, object names, or names of referenced objects.
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
public enum LabelMode
{
GameObjectName = 0,
ReferenceName = 1,
Custom = 2
@andydbc
andydbc / TransformExtensions.cs
Created November 8, 2024 15:37
Helper extensions for Transform: delete all child objects of a Transform
using UnityEngine;
public static class TransformExtensions
{
public static void DestroyChildren(this Transform t)
{
foreach (Transform child in t)
{
GameObject.Destroy(child.gameObject);
}