Skip to content

Instantly share code, notes, and snippets.

View karljj1's full-sized avatar

Karl Jones karljj1

View GitHub Profile
@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;
using TMPro;
using UnityEditor;
using UnityEngine.Localization.PropertyVariants;
using UnityEngine.Localization.PropertyVariants.TrackedObjects;
using UnityEngine.Localization.PropertyVariants.TrackedProperties;
public class AutoLinkTMP
{
[MenuItem("CONTEXT/TextMeshProUGUI/Localize (With Localized Properties)")]
static void LocalizeTMProText(MenuCommand command)
@karljj1
karljj1 / LocalizedTextureBinder.cs
Created March 22, 2022 15:37
Localization support for VFX Graph
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.VFX;
using UnityEngine.VFX.Utility;
[VFXBinder("Localization/Texture Binder")]
public class LocalizedTextureBinder : VFXBinderBase
{
[SerializeField]
LocalizedTexture m_Texture;
@karljj1
karljj1 / GetSizeOfObject.cs
Last active March 4, 2022 14:39
sizeof - Estimate the size of a managed instance
public static int GetSizeOfObject(object obj, StringBuilder sb = null, int indent = 0, bool details = true)
{
if (sb == null)
{
sb = new StringBuilder();
sb.AppendLine("|Name |Type |Size(b)|");
sb.AppendLine("|--- |--- |--- |");
}
if (indent == 0)
using System;
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Localization.PropertyVariants;
using UnityEngine.Localization.PropertyVariants.TrackedObjects;
using UnityEngine.Localization.PropertyVariants.TrackedProperties;
using UnityEngine.ResourceManagement.AsyncOperations;
using Object = UnityEngine.Object;
[Serializable]
using System;
using UnityEngine;
public class SerializeType : ScriptableObject, ISerializationCallbackReceiver
{
[SerializeField] string m_TypeString;
public Type MyType { get; set; }
public void OnBeforeSerialize()
@karljj1
karljj1 / ClearTable.cs
Created October 8, 2021 11:28
Clear all entries in an Asset Table collection
public static void ClearAll()
{
var collection = LocalizationEditorSettings.GetAssetTableCollection("My Assets");
foreach(var table in collection.AssetTables)
{
foreach(var tableEntry in table.Values)
{
// Remove the asset from Addressables
if (!string.IsNullOrEmpty(tableEntry.Guid))
{
public class PatchTableContents : MonoBehaviour
{
public IEnumerator Start()
{
// Load the table.
var table = LocalizationSettings.StringDatabase.GetTableAsync("My Table");
yield return table;
// Prevent the table from being unloaded and the changes lost.
Addressables.ResourceManager.Acquire(table);
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Localization;
using UnityEngine.ResourceManagement.AsyncOperations;
public class PreloadSelectedTables : MonoBehaviour
{
public List<LocalizedStringTable> tablesToPreload = new List<LocalizedStringTable>();
@karljj1
karljj1 / EditorBootScene.cs
Created February 11, 2021 14:17
Initializes the localization settings before entering into a scene in play mode
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine.Localization.Settings;
using UnityEngine.SceneManagement;
[InitializeOnLoad]
public static class EditorBootScene
{
static EditorBootScene()
{