Skip to content

Instantly share code, notes, and snippets.

@SolarianZ
SolarianZ / AssetTool.cs
Last active May 22, 2024 02:43
{"category": "Unity Engine/Editor/Extensions", "keywords": "Unity, Editor, Asset, Move"} Add 'Move to' menu item to move selected assets to a folder.
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
public static class AssetTool
{
// Add 'Move to' menu item to move selected assets to a folder
[MenuItem("Tools/Bamboo/Asset/Move Selected Assets to Folder")]
[MenuItem("Assets/Move to", priority = 20)]
@SolarianZ
SolarianZ / OdinFoldoutableListElement.cs
Last active July 24, 2024 10:03
{"category": "Unity Engine/Editor/Extensions", "keywords": "Unity, Editor, UI, Odin, Foldout, Collapse, List, Element"} Odin extension for foldout elements in list.
// Odin extension for foldout elements in list.
// Example:
// [Serializable]
// public class MyData1 : IFoldoutableInList
// {
// // members...
// }
// [Serializable]
// public class MyData2 : IForceFoldoutableInList
// {
@SolarianZ
SolarianZ / GetStyleByName
Created March 29, 2024 03:12
{"category": "Unity Engine/Editor/Extensions", "keywords": "Unity, Editor, UI, Skin, Style"} Get gui style by name in the Unity Editor.
/// <summary>
/// Get gui style by name.
/// </summary>
/// <param name="styleName"></param>
/// <returns></returns>
public static GUIStyle GetStyleByName(string styleName)
{
GUIStyle style = GUI.skin.FindStyle(styleName);
if (style == null)
{
@SolarianZ
SolarianZ / BoneVibrator.cs
Last active December 6, 2025 19:11
{"category": "Unity/Runtime/Utility/Animation", "keywords": "Animation, Hit feedback, Bone Vibrate, Simple Harmonic Motion, SHM, Second Order System"} A simple single-skeleton vibrator for simple hit feedback.
// NOTE: The 'SimpleHarmonicMotion.cs' is here: https://gist.github.com/SolarianZ/78f9b22d9663d77b6e6c1b0c60cc6322
// You need to change `System.Numerics.Vector3` to `UnityEngine.Vector3` in SimpleHarmonicMotion.cs
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
[DisallowMultipleComponent]
public class BoneVibrator : MonoBehaviour
@SolarianZ
SolarianZ / SimpleHarmonicMotionTest.cs
Last active August 24, 2023 13:52
{"category": "Unity/Runtime/Utility/Math", "keywords": "Math, Physics, Simple Harmonic Motion, SHM, Second Order System"} Simple Harmonic Motion Visualizer.
// NOTE: The 'SimpleHarmonicMotion.cs' is here: https://gist.github.com/SolarianZ/78f9b22d9663d77b6e6c1b0c60cc6322
using UnityEngine;
using SVector3 = System.Numerics.Vector3;
using UVector3 = UnityEngine.Vector3;
#if UNITY_EDITOR
using UnityEditor;
#endif
[DisallowMultipleComponent]
@SolarianZ
SolarianZ / SimpleHarmonicMotion.cs
Last active July 12, 2023 15:19
{"category": "C#/Runtime/Utility/Math", "keywords": "Math, Physics, Simple Harmonic Motion, SHM, Second Order System"} An approximate simulator for Simple Harmonic Motion. Note: This is not a precise simulator.
// Visualizer(In Unity Engine): https://gist.github.com/SolarianZ/a53363f0994aa7858d9e0a08ecf3f014
using System;
using System.Numerics;
// Note: This is not a precise simulator.
public class SimpleHarmonicMotion
{
/// <summary>
/// The natural frequency of the system measured in Hz.
@SolarianZ
SolarianZ / DebugDrawer.cs
Last active January 23, 2024 11:58
{"category": "Unity Engine/Runtime/Utility", "keywords": "Unity, Runtime, Debug, DrawWireShape"} Drawing shapes with Debug.DrawLine method in the Unity Editor.
using System.Diagnostics;
using UnityEngine;
using UDebug = UnityEngine.Debug;
public static class DebugDrawer
{
public static byte CircleResolution
{
get => _circleResolution;
set
@SolarianZ
SolarianZ / AnimationClipEventTool.cs
Last active May 7, 2024 04:58
{"category": "Unity Engine/Editor/Extensions", "keywords": "Unity, Editor, AnimationClip, AnimationEvent, Rename"} Log/Rename AnimationEvents of selected AnimationClip/FBXs in Unity Editor.
using System;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
public static class AnimationClipEventTool
{
#region Log Animation Events
@SolarianZ
SolarianZ / MissingScriptTool.cs
Last active July 6, 2023 15:03
{"category": "Unity Engine/Editor/Extensions", "keywords": "Unity, Editor, GameObject, Missing, Script"} Log GameObjects with missing scripts in loaded scenes, remove missing scripts from selected GameObjects recursively in the Unity Editor.
public static class MissingScriptTool
{
[MenuItem("Tools/Bamboo/GameObject/Log GameObjects with Missing Script in Loaded Scenes")]
public static void LogGameObjectsWithMissingScriptInLoadedScenes()
{
var missingScriptCount = 0;
var sceneCount = SceneManager.loadedSceneCount;
for (var i = 0; i < sceneCount; i++)
{
var scene = SceneManager.GetSceneAt(i);
@SolarianZ
SolarianZ / CustomEditorToolbar.cs
Last active October 27, 2025 20:39
{"category": "Unity Engine/Editor/Extensions", "keywords": "Unity, Editor, Toolbar, Custom, UI"} Add custom UI to the Unity Editor's main toolbar. This example adds a FloatField to the main toolbar to control the `Time.timeScale` . You can refer to this example to add other UI elements. It has been tested in Unity 2021.3.
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
[InitializeOnLoad]
public static class CustomEditorToolbar
{
#region TimeScale Slider