Skip to content

Instantly share code, notes, and snippets.

@SolarianZ
SolarianZ / SearchablePopupField.cs
Created May 1, 2025 07:54
{"category": "Unity Engine/Editor/Extensions", "keywords": "Unity, Editor, Searchable, PopupField"} Display a searchable PopupField in the Unity Editor.
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.UIElements;
using PopupWindow = UnityEditor.PopupWindow;
@SolarianZ
SolarianZ / ModalDialog.cs
Last active December 1, 2024 05:31
{"category": "Unity Engine/Editor/Extensions", "keywords": "Unity, Editor, DisplayDialog, Modal, Checkbox, Button"} Display a modal dialog window with multiple checkboxes and buttons in the Unity Editor.
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
/// <summary>
/// Display a modal dialog window with multiple checkboxes and buttons in the Unity Editor.
/// </summary>
public static class ModalDialog
@SolarianZ
SolarianZ / PickableHandleSample.cs
Created August 12, 2024 14:17
{"category": "Unity Engine/Editor/Sample/Handles", "keywords": "Unity, Editor, Handles, Scene, Pickable, Clickable"} An example of drawing clickable lines (Handles) in the SceneView.
using UnityEditor;
using UnityEngine;
public class PickableHandleSample : MonoBehaviour
{
public Vector3 startPoint = Vector3.zero;
public Vector3 endPoint = Vector3.up * 3;
}
[CustomEditor(typeof(PickableHandleSample))]
@SolarianZ
SolarianZ / OdinPrimaryKeyAttribute.cs
Last active July 24, 2024 10:03
{"category": "Unity Engine/Editor/Extensions", "keywords": "Unity, Editor, UI, Odin, Primary, Key, List, Element"} Odin extension to verify the primary key of the list element.
using System;
using System.Collections;
using System.Diagnostics;
using Sirenix.OdinInspector.Editor;
using Sirenix.Utilities.Editor;
using UnityEngine;
// Put the following class to the Runtime folder
// Used on primary key field
[Conditional("UNITY_EDITOR")]
@SolarianZ
SolarianZ / PointerDragAndDropManipulator.cs
Created July 22, 2024 04:02
{"category": "Unity Engine/Editor/Extensions", "keywords": "Unity, Editor, UIToolkit, UIEElement, DragAndDrop, Manipulator"} Manipulator to simplify the implementation of VisualElement drag-and-drop functionality.
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
public interface IDragAndDropDataProvider
{
/// <summary>
/// Get data associated with current drag and drop operation.
/// </summary>
@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