Skip to content

Instantly share code, notes, and snippets.

View karljj1's full-sized avatar

Karl Jones karljj1

View GitHub Profile
@karljj1
karljj1 / Unity Assembly Definition Debugger.cs
Last active March 27, 2024 17:18
Find out what assemblies are being built and how long each takes.
using System;
using System.Collections.Generic;
using System.Text;
using UnityEditor;
using UnityEditor.Compilation;
using UnityEngine;
[InitializeOnLoad]
public class AsmdefDebug
{
/*
* Legacy Particle System Updater
* A tool that can be used to convert Legacy Particle Systems into new Particle System Components.
* https://forum.unity.com/threads/release-legacy-particle-system-updater.510879/
*
* v1.0
* Initial release
*
* v1.1
* Fixed incorrect billboard mode
@karljj1
karljj1 / SerializedDictionaryExample.cs
Last active February 13, 2024 14:04
Serializing a Dictionary in a VisualElement (Unity 2023.2.0a9)
using System;
using System.Collections.Generic;
using UnityEngine.UIElements;
[Serializable]
class DictItem
{
public int key;
public string value;
}
@karljj1
karljj1 / ObjectChangeEventsExample.cs
Last active February 13, 2024 14:01
Example of how to use ObjectChangeEvents in Unity
using System.Text;
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public class ObjectChangeEventsExample
{
static ObjectChangeEventsExample()
{
ObjectChangeEvents.changesPublished += ChangesPublished;
@karljj1
karljj1 / RemoveLocale.cs
Created February 5, 2024 10:54
Example of removing a locale and its assets
public static void RemoveLocale(LocaleIdentifier localeIdentifier)
{
foreach (var collectionStrings in LocalizationEditorSettings.GetStringTableCollections())
{
var table = collectionStrings.GetTable(localeIdentifier);
if (table != null)
{
collectionStrings.RemoveTable(table);
AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(table));
}
@karljj1
karljj1 / DropDownButton.cs
Created February 1, 2024 15:50
UI Toolkit version of the IMGUI DropDownButton
abstract class DropDownButton : BaseField<string>
{
TextElement m_TextElement;
VisualElement m_ArrowElement;
public DropDownButton(string label)
: base(label, null)
{
AddToClassList(EnumField.ussClassName);
labelElement.AddToClassList(EnumField.labelUssClassName);
@karljj1
karljj1 / WordCount.cs
Last active January 15, 2024 17:54
Generate String Table Word Count Report
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEditor.Localization;
using UnityEngine.Localization.Settings;
using UnityEngine.Localization.SmartFormat;
using UnityEngine.Localization.SmartFormat.Core.Extensions;
@karljj1
karljj1 / DefaultTmpFont.cs
Last active December 31, 2023 17:48
Localize the default TextMeshPro font.
using System.Reflection;
using TMPro;
using UnityEngine;
using UnityEngine.Localization;
/// <summary>
/// Sets the default TextMeshPro font to be used.
/// </summary>
[ExecuteInEditMode]
public class DefaultTmpFont : MonoBehaviour
@karljj1
karljj1 / AddressablesBinding.cs
Last active November 23, 2023 14:42
Example of a UI Toolkit custom binding for Addressables (2023.3)
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.UIElements;
#if UNITY_EDITOR
public class AssetReferenceConverter<T> : UnityEditor.UIElements.UxmlAttributeConverter<AssetReferenceT<T>> where T : Object
{
public override AssetReferenceT<T> FromString(string value)
{
@karljj1
karljj1 / FindUsedKeys.cs
Created May 20, 2022 15:59
Find localization entries that are not used
using System;
using System.Collections.Generic;
using System.Text;
using UnityEditor;
using UnityEditor.Localization;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.Localization.Tables;
using Object = UnityEngine.Object;