Skip to content

Instantly share code, notes, and snippets.

View bkevelham's full-sized avatar

Bart Kevelham bkevelham

View GitHub Profile
@bkevelham
bkevelham / DropdownFixer.cs
Created November 24, 2023 13:52
A small component which ensures that a Unity Dropdown, after having a value selected, will show that value at the top when reopening the dropdown.
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class DropdownFixer : MonoBehaviour, IPointerClickHandler
{
public Dropdown Dropdown;
public int ElementHeight = 50; //The height of the elements in your Dropdown
public void OnPointerClick(PointerEventData eventData)
@bkevelham
bkevelham / CustomScriptableObjectAssetEditor.cs
Created December 2, 2021 12:17
A minimal sample of how to handle ScriptableObject drag and drops into a scene view and onto a given GameObject.
//Minimal sample of how to drag a ScriptableObject into a scene
//onto a GameObject in that scene, and have something happen as a result
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(CustomScriptableObjectAsset))]
public class CustomScriptableObjectAssetEditor : Editor
{
@bkevelham
bkevelham / MeshUtil.cs
Created November 20, 2021 23:46
Deep copy a Mesh in Unity 2020+
using UnityEngine;
public class MeshUtil
{
public static Mesh DeepCopy(Mesh sourceMesh)
{
//Instead of getting all a mesh's properties by hand, and re-creating a mesh,
//use the API used for the job system and Burst compiler.
//This seems to work fine when not using either of those.
Mesh meshCopy = new Mesh();