Second commit

This commit is contained in:
ThomasCharester committed 2026-09-20 15:26:03 +03:00
commit 36840f3ad4
999 files changed
+61364

No files matched your search

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8b895dc7f3a74ac1a27fec3a77248e5d
timeCreated: 1716201044
@@ -0,0 +1,159 @@
//
// This file is part of the Tremble package by Tiny Goose.
// Copyright (c) 2024-2026 TinyGoose Ltd., All Rights Reserved.
//
#if ADDRESSABLES_INSTALLED
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.ResourceManagement.ResourceLocations;
using Debug = UnityEngine.Debug;
using Object = UnityEngine.Object;
namespace TinyGoose.Tremble
{
public class AddressablesLoaderAdaptor : IAssetLoaderAdaptor
{
public bool SupportsPreloading => true;
private readonly List<AsyncOperationHandle> m_OwnedHandles = new(1024);
private readonly Dictionary<string, object> m_LoadedAssets = new(1024);
public string[] FindAssetPaths(Type type, string name = "")
{
return TrembleAssetLoader.FindAssetDataMany(a => a.Path.ContainsInvariant(name))
.Where(a => a.FullTypeName.EqualsInvariant(type.FullName))
.Select(a => a.Path)
.ToArray();
}
public TAsset LoadAssetByPath<TAsset>(string path) where TAsset : Object
{
if (path.IsNullOrEmpty())
return null;
if (!TrembleAssetLoader.TryGetAssetDataFromPath(path, out AssetMetadata assetData))
{
Debug.LogError($"Not loading invalid addressable: {path}");
return null;
}
if (m_LoadedAssets.TryGetValue(assetData.AddressableName, out object existingAsset) &&
existingAsset is TAsset tAsset)
{
return tAsset;
}
AsyncOperationHandle<TAsset> handle = Addressables.LoadAssetAsync<TAsset>(assetData.AddressableName);
TAsset asset = handle.WaitForCompletion();
if (!asset)
{
Addressables.Release(handle);
return null;
}
m_OwnedHandles.Add(handle);
m_LoadedAssets[path] = handle;
return asset;
}
public async Task PreloadAssetsByPaths(IList<string> paths)
{
if (paths.Count == 0)
return;
List<string> addresses = new(paths.Count);
// First, remove dupes, invalid and ones we already loaded
for (int i = 0; i < paths.Count; i++)
{
string path = paths[i];
if (path.IsNullOrEmpty() || !TrembleAssetLoader.TryGetAssetDataFromPath(path, out AssetMetadata assetData))
{
Debug.LogError($"Not loading invalid addressable: {path}");
paths.RemoveAt(i--);
continue;
}
if (m_LoadedAssets.ContainsKey(assetData.AddressableName))
{
paths.RemoveAt(i--);
continue;
}
if (paths.IndexOf(path) != i)
{
paths.RemoveAt(i--);
continue;
}
// This is valid - add to list of addresses
addresses.Add(assetData.AddressableName);
}
if (addresses.Count == 0)
return;
AsyncOperationHandle<IList<Object>> resultsHandle = Addressables.LoadAssetsAsync<Object>(addresses, null, Addressables.MergeMode.Union);
await resultsHandle.Task;
for (int i = 0; i < paths.Count; i++)
{
string path = paths[i];
if (TrembleAssetLoader.TryGetAssetDataFromPath(path, out AssetMetadata assetData))
{
m_LoadedAssets[assetData.AddressableName] = resultsHandle.Result[i];
}
}
m_OwnedHandles.Add(resultsHandle);
}
public string GetPath(Object obj)
{
Debug.LogError("GetPath is not implemented in Addressables (yet!)");
return null;
}
public TrembleSyncSettings LoadSyncSettings()
{
return Addressables
.LoadAssetAsync<TrembleSyncSettings>(TrembleSyncSettings.ADDRESSABLE_KEY)
.WaitForCompletion();
}
public Material LoadClipMaterial()
{
return Addressables.LoadAssetAsync<Material>("M_NullRender").WaitForCompletion();
}
public void ReleaseAll()
{
foreach (AsyncOperationHandle handle in m_OwnedHandles)
{
Addressables.Release(handle);
}
m_OwnedHandles.Clear();
}
private static bool IsAddressablePathValid(string path)
{
if (path == null)
return false;
AsyncOperationHandle<IList<IResourceLocation>> locationLoadOperation = Addressables.LoadResourceLocationsAsync(path);
IList<IResourceLocation> results = locationLoadOperation.WaitForCompletion();
bool isValidPath = results is { Count: > 0 };
Addressables.Release(locationLoadOperation);
return isValidPath;
}
}
}
#endif
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: f4959867e61442c2aa78844ff6cd8e06
timeCreated: 1716201342
AssetOrigin:
serializedVersion: 1
productId: 277805
packageName: Tremble - Map Importer
packageVersion: 1.11.1
assetPath: Assets/Tremble/AssetLoading/Adaptors/AddressablesLoaderAdaptor.cs
uploadId: 939664
@@ -0,0 +1,105 @@
//
// This file is part of the Tremble package by Tiny Goose.
// Copyright (c) 2024-2026 TinyGoose Ltd., All Rights Reserved.
//
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
#if UNITY_EDITOR
namespace TinyGoose.Tremble
{
public class EditorLoaderAdaptor : IAssetLoaderAdaptor
{
public bool SupportsPreloading => false;
private static readonly Dictionary<string, string[]> s_CachedQueryResults = new(1024);
public string[] FindAssetPaths(Type type, string name = "")
{
string typeString = type == typeof(GameObject) ? "prefab" : type.Name;
string fullQuery = $"t:{typeString} {name}";
if (!s_CachedQueryResults.TryGetValue(fullQuery, out string[] results))
{
results = AssetDatabase
.FindAssets(fullQuery, new[] { "Assets" })
.Select(AssetDatabase.GUIDToAssetPath)
.ToArray();
if (results.Length > 0)
{
s_CachedQueryResults[fullQuery] = results;
}
}
return results;
}
public TAsset LoadAssetByPath<TAsset>(string path) where TAsset : Object
=> AssetDatabase.LoadAssetAtPath<TAsset>(path);
public Task PreloadAssetsByPaths(IList<string> paths)
{
// We don't need to preload in Editor ;)
return Task.CompletedTask;
}
public async Task PreloadAssetsByPathsAsync(IList<string> paths)
{
// We don't need to preload in Editor ;)
await Task.CompletedTask;
}
public string GetPath(Object obj) => AssetDatabase.GetAssetPath(obj);
public TrembleSyncSettings GetSyncSettings() => TrembleSyncSettings.Get();
public Material LoadClipMaterial()
{
string clipPath = Path.Combine(TrembleConsts.EDITOR_GetTrembleInstallFolder(), "Materials", "M_NullRender.mat");
return LoadAssetByPath<Material>(clipPath);
}
public TrembleSyncSettings LoadSyncSettings()
{
string[] paths = FindAssetPaths(typeof(TrembleSyncSettings));
switch (paths.Length)
{
case 0:
return null;
case >1:
Debug.LogError("More than one Tremble Sync Settings file found!");
foreach (string path in paths)
{
Debug.LogWarning($"Found at: {path}", AssetDatabase.LoadAssetAtPath<TrembleSyncSettings>(path));
}
Debug.LogError("There should be only one! Picking one arbitrarily for now.");
goto default;
default:
return AssetDatabase.LoadAssetAtPath<TrembleSyncSettings>(paths[0]);
}
}
public void ReleaseAll() { }
public static void DropCachedAssetPaths()
{
s_CachedQueryResults.Clear();
}
}
}
#endif
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: a410384015ae43959c21d5c273d941a0
timeCreated: 1716201389
AssetOrigin:
serializedVersion: 1
productId: 277805
packageName: Tremble - Map Importer
packageVersion: 1.11.1
assetPath: Assets/Tremble/AssetLoading/Adaptors/EditorLoaderAdaptor.cs
uploadId: 939664
@@ -0,0 +1,36 @@
//
// This file is part of the Tremble package by Tiny Goose.
// Copyright (c) 2024-2026 TinyGoose Ltd., All Rights Reserved.
//
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using Object = UnityEngine.Object;
namespace TinyGoose.Tremble
{
public interface IAssetLoaderAdaptor
{
// -----------------------------------------------------------------------------------------------------------------------------
// Finding & loading assets
// -----------------------------------------------------------------------------------------------------------------------------
string[] FindAssetPaths(Type type, string name = "");
TAsset LoadAssetByPath<TAsset>(string path) where TAsset : Object;
Task PreloadAssetsByPaths(IList<string> paths);
bool SupportsPreloading { get; }
// -----------------------------------------------------------------------------------------------------------------------------
// Getting path for a loaded asset
// -----------------------------------------------------------------------------------------------------------------------------
string GetPath(Object obj);
// -----------------------------------------------------------------------------------------------------------------------------
// Misc
// -----------------------------------------------------------------------------------------------------------------------------
TrembleSyncSettings LoadSyncSettings();
Material LoadClipMaterial();
void ReleaseAll();
}
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 7271c3afa0854533a18a87ea7a9690c8
timeCreated: 1716201055
AssetOrigin:
serializedVersion: 1
productId: 277805
packageName: Tremble - Map Importer
packageVersion: 1.11.1
assetPath: Assets/Tremble/AssetLoading/Adaptors/IAssetLoaderAdaptor.cs
uploadId: 939664
@@ -0,0 +1,61 @@
//
// This file is part of the Tremble package by Tiny Goose.
// Copyright (c) 2024-2026 TinyGoose Ltd., All Rights Reserved.
//
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using Object = UnityEngine.Object;
namespace TinyGoose.Tremble
{
public class NullLoaderAdaptor : IAssetLoaderAdaptor
{
public bool SupportsPreloading => false;
public string[] FindAssetPaths(Type type, string name = "")
{
Debug.LogError("No valid loader adaptor - ensure you have Addressables installed or are in editor!");
return Array.Empty<string>();
}
public TAsset LoadAssetByPath<TAsset>(string path) where TAsset : Object
{
Debug.LogError("No valid loader adaptor - ensure you have Addressables installed or are in editor!");
return null;
}
public Task PreloadAssetsByPaths(IList<string> paths)
{
Debug.LogError("No valid loader adaptor - ensure you have Addressables installed or are in editor!");
return Task.CompletedTask;
}
public string GetPath(Object obj)
{
Debug.LogError("No valid loader adaptor - ensure you have Addressables installed or are in editor!");
return null;
}
public TrembleSyncSettings GetSyncSettings()
{
Debug.LogError("No valid loader adaptor - ensure you have Addressables installed or are in editor!");
return null;
}
public TrembleSyncSettings LoadSyncSettings()
{
Debug.LogError("No valid loader adaptor - ensure you have Addressables installed or are in editor!");
return null;
}
public Material LoadClipMaterial()
{
Debug.LogError("No valid loader adaptor - ensure you have Addressables installed or are in editor!");
return null;
}
public void ReleaseAll() { }
}
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: a3c2e961a9234fcb94549e1f5bb3e8f2
timeCreated: 1716201662
AssetOrigin:
serializedVersion: 1
productId: 277805
packageName: Tremble - Map Importer
packageVersion: 1.11.1
assetPath: Assets/Tremble/AssetLoading/Adaptors/NullLoaderAdaptor.cs
uploadId: 939664
@@ -0,0 +1,170 @@
//
// This file is part of the Tremble package by Tiny Goose.
// Copyright (c) 2024-2026 TinyGoose Ltd., All Rights Reserved.
//
//#define USE_ADDRESSABLES_IN_EDITOR
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using UnityEngine;
using Object = UnityEngine.Object;
namespace TinyGoose.Tremble
{
public static class TrembleAssetLoader
{
// -----------------------------------------------------------------------------------------------------------------------------
// Adaptor
// -----------------------------------------------------------------------------------------------------------------------------
private static IAssetLoaderAdaptor s_LoaderAdaptor;
private static IAssetLoaderAdaptor LoaderAdaptor
{
get
{
if (s_LoaderAdaptor == null)
{
#if UNITY_EDITOR && !USE_ADDRESSABLES_IN_EDITOR
s_LoaderAdaptor = new EditorLoaderAdaptor();
#elif UNITY_SERVER
s_LoaderAdaptor = new NullLoaderAdaptor();
#elif ADDRESSABLES_INSTALLED
s_LoaderAdaptor = new AddressablesLoaderAdaptor();
#else
s_LoaderAdaptor = new NullLoaderAdaptor();
#endif
}
return s_LoaderAdaptor;
}
}
// -----------------------------------------------------------------------------------------------------------------------------
// Generic
// -----------------------------------------------------------------------------------------------------------------------------
public static string FindAssetPath<TAsset>(string name = "") where TAsset : Object
{
string[] paths = FindAssetPaths<TAsset>(name);
switch (paths.Length)
{
// Nothing matched - return null :(
case 0:
return null;
// Multiple matches - check if we have an EXACT match
case > 1:
{
foreach (string path in paths)
{
string filename = Path.GetFileNameWithoutExtension(path);
if (!filename.EqualsInvariant(name))
continue;
return path;
}
break;
}
}
// Only a single match, or couldn't disambiguate - return first
return paths[0];
}
public static string[] FindAssetPaths<TAsset>(string name = "") where TAsset : Object => FindAssetPaths(typeof(TAsset), name);
public static string[] FindAssetPaths(Type type, string name = "") => LoaderAdaptor.FindAssetPaths(type, name);
public static string GetPath(Object obj) => LoaderAdaptor.GetPath(obj);
public static GameObject LoadPrefabByName(string name) => LoadAssetByName<GameObject>(name);
public static GameObject LoadPrefabByPath(string path) => LoadAssetByPath<GameObject>(path);
public static TAsset LoadAssetByName<TAsset>(string name) where TAsset : Object
{
string path = FindAssetPath<TAsset>(name);
return LoadAssetByPath<TAsset>(path);
}
public static TAsset LoadAssetByPath<TAsset>(string path) where TAsset : Object
=> LoaderAdaptor.LoadAssetByPath<TAsset>(path);
public static async Task PreloadAssetsByPaths(IList<string> paths)
=> await LoaderAdaptor.PreloadAssetsByPaths(paths);
public static bool SupportsPreloading => LoaderAdaptor.SupportsPreloading;
public static void ReleaseAll() => LoaderAdaptor.ReleaseAll();
// -----------------------------------------------------------------------------------------------------------------------------
// Queries
// -----------------------------------------------------------------------------------------------------------------------------
private static int s_NumAssetMetadatas;
private static readonly Dictionary<string, int> s_MapNameToMetadataIndex = new();
private static readonly Dictionary<string, int> s_PathToMetadataIndex = new();
public static bool TryGetAssetDataFromMapName(string mapName, out AssetMetadata foundMetadata)
{
TrembleSyncSettings syncSettings = TrembleSyncSettings.Get();
CreateLookups(syncSettings);
bool found = s_MapNameToMetadataIndex.TryGetValue(mapName, out int index);
foundMetadata = found ? syncSettings.AssetMetadatas[index] : default;
return found;
}
public static bool TryGetAssetDataFromPath(string path, out AssetMetadata foundMetadata)
{
TrembleSyncSettings syncSettings = TrembleSyncSettings.Get();
CreateLookups(syncSettings);
bool found = s_PathToMetadataIndex.TryGetValue(path, out int index);
foundMetadata = found ? syncSettings.AssetMetadatas[index] : default;
return found;
}
private static void CreateLookups(TrembleSyncSettings syncSettings)
{
if (syncSettings.AssetMetadatas == null)
return;
if (s_NumAssetMetadatas == syncSettings.AssetMetadatas.Length)
return;
s_NumAssetMetadatas = syncSettings.AssetMetadatas.Length;
s_MapNameToMetadataIndex.Clear();
s_PathToMetadataIndex.Clear();
for (int i = 0; i < syncSettings.AssetMetadatas.Length; i++)
{
s_MapNameToMetadataIndex[syncSettings.AssetMetadatas[i].MapName] = i;
s_PathToMetadataIndex[syncSettings.AssetMetadatas[i].Path] = i;
}
}
public static AssetMetadata[] FindAssetDataMany(Func<AssetMetadata, bool> filter)
{
TrembleSyncSettings syncSettings = TrembleSyncSettings.Get();
return syncSettings.AssetMetadatas != null
? syncSettings.AssetMetadatas.Where(filter).ToArray()
: Array.Empty<AssetMetadata>();
}
public static bool TryFindAssetData(Func<AssetMetadata, bool> filter, out AssetMetadata found)
{
AssetMetadata[] results = FindAssetDataMany(filter);
found = results.Length > 0 ? results[0] : default;
return results.Length > 0;
}
// -----------------------------------------------------------------------------------------------------------------------------
// Specifics
// -----------------------------------------------------------------------------------------------------------------------------
public static Material LoadClipMaterial() => LoaderAdaptor.LoadClipMaterial();
public static TrembleSyncSettings LoadSyncSettings() => LoaderAdaptor.LoadSyncSettings();
}
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: fe12c1abce564e1d8163e2f1197f500b
timeCreated: 1715666874
AssetOrigin:
serializedVersion: 1
productId: 277805
packageName: Tremble - Map Importer
packageVersion: 1.11.1
assetPath: Assets/Tremble/AssetLoading/TrembleAssetLoader.cs
uploadId: 939664