Skip to content

Instantly share code, notes, and snippets.

@TrinketBen
TrinketBen / SizeToFitContents.cs
Created December 5, 2024 22:42
Tries to calculate a size for a parent RectTransform (e.g. a window) based on the child RectTransforms relative to a target Transform, Content.
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using Sirenix.OdinInspector;
namespace Trinket.UtilityComponents {
[ExecuteAlways]
public class SizeToFitContents : MonoBehaviour {
public RectTransform Content;
@TrinketBen
TrinketBen / ComponentContextMenu.cs
Created January 10, 2024 15:44
Adds a right-click context menu item to all components that sets the Hierarchy search filter to find all components of the selected type in the scene.
using System.Reflection;
using UnityEditor;
using UnityEngine;
#if UNITY_EDITOR
namespace Trinket.StaticUtilities {
public static class ComponentContextMenu {
public enum FilterMode : int {
All,
@TrinketBen
TrinketBen / UtilitiesComponentContextMenu.cs
Created January 14, 2016 15:11
Adds options to the Component context menu (the gear) to move a component all the way to the top or bottom of the inspector.
using System;
using UnityEditor;
using UnityEngine;
public static class UtilitiesComponentContextMenu
{
[MenuItem("CONTEXT/Component/Move To Top")]
static void MoveComponentToTop(MenuCommand menuCommand)
{
var component = menuCommand.context as Component;