Skip to content

Instantly share code, notes, and snippets.

@OscarAbraham
OscarAbraham / ControlUtility.cs
Last active June 1, 2023 20:47
Utility to create custom VisualElements that correspond to specific types in Unity
using UnityEngine;
using UnityEditor;
using UnityEngine.UIElements;
using System;
using System.Collections.Generic;
public static class ControlUtility
{
private static class ControlCache<TBaseControl, TBaseObject> where TBaseControl : VisualElement where TBaseObject : class
{
@OscarAbraham
OscarAbraham / PlainDataInstancer.cs
Last active March 18, 2024 15:58
PlainDataInstancer ScriptableObject for Unity, so you can create deep clones of data stored in SO assets at runtime without the overhead of ScriptableObject copies.
using System.Collections.Generic;
using UnityEngine;
// TData should be a plain class or struct with the [System.Serializable] attribute.
// TData can implement ISerializationCallbackReceiver if needed for more advanced uses.
public class PlainDataInstancer<TData> : ScriptableObject
{
private static bool s_DataTypeValidated;
[SerializeField] private TData m_PrototypeData;