Skip to content

Instantly share code, notes, and snippets.

@SolarianZ
SolarianZ / DontCallBaseImplementationAnalyzer.cs
Created June 25, 2024 11:53
{"category": "C#/Analyzer", "keywords": "C#, Roslyn, Analyzer, override, call, base"} A Roslyn analyzer used to prevent calling the base class method implementation when overriding a method.
// < !--Add to YOUR_PROJECT.csproj-- >
// < Project Sdk = "Microsoft.NET.Sdk" >
//
// < !--... -->
//
// < ItemGroup >
// < Analyzer Include = "ABSOLUTE_OR_RELATIVE_FOLDER\DontCallBaseImplementation.dll" />
// </ ItemGroup >
//
// < !--... -->
@SolarianZ
SolarianZ / GraphicInput.cs
Created June 11, 2024 04:32
{"category": "Unity Engine/Runtime/Input", "keywords": "Unity, Runtime, Input, UI, Touch, Mouse, Drag, Zoom"} Detects touch screen or mouse input in the specified UI area.
using System;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using UInput = UnityEngine.Input;
public interface IGraphicInputProvider
{
public Vector2 Drag { get; }
@SolarianZ
SolarianZ / AlertOnRemoveComponentEditor.cs
Created June 7, 2024 05:29
{"category": "Unity Engine/Editor/Extensions", "keywords": "Unity, Editor, Alert, Message, Remove, Component"} Custom editor to show alert message on remove component.
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
// [CustomEditor(typeof(YOUR_COMPONENT))]
public class AlertOnRemoveComponentEditor :
#if ODIN_INSPECTOR
Sirenix.OdinInspector.Editor.OdinEditor
#else
@SolarianZ
SolarianZ / FindPanelRootVisualElementByPanelName.cs
Created May 31, 2024 13:54
{"category": "Unity Engine/Editor/Extensions", "keywords": "Unity, Editor, Find, Panel, rootVisualElement, Name"} Find panel's rootVisualElement by panel name.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine.UIElements;
public static VisualElement FindPanelRootVisualElementByPanelName(string panelName)
{
// UnityEngine.UIElements.UIElementsUtility.GetAllPanels
// UnityEngine.UIElements.UIElementsUtility.GetPanelsIterator
@SolarianZ
SolarianZ / DynamicMenuItem.cs
Last active May 14, 2024 05:18
{"category": "Unity Engine/Editor/Extensions", "keywords": "Unity, Editor, Dynamic, Modify, Menu Item, MenuItemAttribute"} Modify menu items dynamically, no need for MenuItemAttribute.
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
/// <summary>
/// Modify menu items dynamically, no need for MenuItemAttribute.
/// Some methods are not available in earlier versions of Unity.
/// </summary>
public static class DynamicMenuItem
@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 April 26, 2024 11:33
{"category": "Unity Engine/Editor/Extensions", "keywords": "Unity, Editor, UI, Odin, Foldout, Collapse, List, Element"} Odin extenssion 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 November 20, 2023 13:39
{"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]