Skip to content

Instantly share code, notes, and snippets.

@sttz
sttz / SceneLabelsPreserver.cs
Created January 8, 2023 13:18
Workaround for Unity 2022.2 bug where scene asset labels are removed on save
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;
using System.IO;
/// <summary>
/// Workaround for bug: https://issuetracker.unity3d.com/issues/scene-asset-label-disappears-when-the-scene-is-saved
/// Saves the scene's label before and re-applies them after saving.
/// Will log if the labels are preserved and this workaround is no longer necessary.
@iwill
iwill / get-opts.sh
Last active December 28, 2022 10:57
A Bash Script - Get Options without `getopt`, `getopts` or `gnu-getopt`.
#!/bin/bash
## basic
set -e -o pipefail
cmd="get-opts.sh"
RED='01;38;5;196'
@SolidAlloy
SolidAlloy / PrefabPropertyReverter.cs
Last active May 20, 2025 09:48
Unity utility class for reverting overrides of a field or component in all prefab instances.
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;
using vietlabs.fr2;
// I was frustrated with the fact that RectTransform fields are often marked as overriden when prefab instances
@popcron
popcron / PlayerLoopExtensions.cs
Last active August 5, 2025 20:57
Unity player loop extensions for injecting your own update loops
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine.LowLevel;
using static UnityEngine.LowLevel.PlayerLoopSystem;
public static class PlayerLoopExtensions
{
public static Type GetParentSystemType<T>(this PlayerLoopSystem playerLoop)
{
@starikcetin
starikcetin / EditorUtils.cs
Last active May 9, 2025 07:03
Unity get Attributes of a specific type on a SerializedProperty
using System;
using System.Reflection;
using UnityEditor;
public static class EditorUtils
{
private const BindingFlags AllBindingFlags = (BindingFlags)(-1);
/// <summary>
/// Returns attributes of type <typeparamref name="TAttribute"/> on <paramref name="serializedProperty"/>.
@Okay-Roman
Okay-Roman / RadialFillElement.cs
Last active October 16, 2025 14:42
A radial fill element that can be used in Unity UI Toolkit, makes use of MeshWriteData to create a mesh which will only be visible within the confines of its parent due to the overflow attribute.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UIElements;
namespace NS.RomanLib
{
public class RadialFillElement: VisualElement, INotifyValueChanged<float>
{
protected float m_value = float.NaN;
using System;
using UnityEngine;
#if UNITY_2020_1_OR_NEWER
// good to go
#else
#error "Optional<T> plugin requires Unity 2020.1 or above for it to work. On below versions serializing fields of generic types was not possible."
#endif
[Serializable]
@LuviKunG
LuviKunG / UnityEditorMenuExtension.cs
Last active August 7, 2025 09:36
Unity Editor Menu Tweaks for easy access to persistent folder and project assets folder.
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace LuviKunG
{
/// <summary>
/// Unity Editor Menu Extension.
/// </summary>
public static class UnityEditorMenuExtension
@SolidAlloy
SolidAlloy / CutComponentMenuItem.cs
Created April 28, 2022 12:47
"Cut Component" context menu that copies the component data and removes the component from the source object in one click.
namespace CutComponent.Editor
{
using UnityEditor;
using UnityEngine;
public static class CutComponentMenuItem
{
private const string CutComponentPath = "CONTEXT/Component/Cut Component";
[MenuItem(CutComponentPath, priority = 500)]
@gtoto007
gtoto007 / AddLanguagesPostBuildIOS.cs
Last active December 19, 2023 06:48
Defining localization/language for an ios unity app
using UnityEditor;
using UnityEditor.Callbacks;
#if UNITY_IOS
using UnityEditor.iOS.Xcode;
#endif
using UnityEngine;
public static class AddLanguagesPostBuildIOS {
[PostProcessBuild(int.MaxValue)]