Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add AssetDatabaseAssetResolver
- Loading branch information
Showing
13 changed files
with
134 additions
and
4 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
Assets/UIComponents.Benchmarks/AssetLoading/AssetDatabaseAssetLoadBenchmarks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using NUnit.Framework; | ||
using UIComponents.Editor; | ||
using Unity.PerformanceTesting; | ||
|
||
namespace UIComponents.Benchmarks.AssetLoading | ||
{ | ||
[TestFixture] | ||
public partial class AssetDatabaseAssetLoadBenchmarks | ||
{ | ||
[AssetPrefix("Assets/Samples/Addressables/Data/")] | ||
[Layout("AddressablesExampleComponent.uxml")] | ||
[Stylesheet("AddressablesExampleComponent.uss")] | ||
[Stylesheet("Box.uss")] | ||
[Dependency(typeof(IAssetResolver), provide: typeof(AssetDatabaseAssetResolver), Scope.Transient)] | ||
private partial class ComponentWithAssets : UIComponent {} | ||
|
||
[Test, Performance, Version(BenchmarkUtils.Version)] | ||
public void InitializeComponentWithWarmCache() | ||
{ | ||
BenchmarkUtils.MeasureComponentInitWithWarmCache<ComponentWithAssets>(); | ||
} | ||
|
||
[Test, Performance, Version(BenchmarkUtils.Version)] | ||
public void InitializeComponentWithColdCache() | ||
{ | ||
BenchmarkUtils.MeasureComponentInitWithColdCache<ComponentWithAssets>(); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/UIComponents.Benchmarks/AssetLoading/AssetDatabaseAssetLoadBenchmarks.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
Assets/UIComponents.Tests/Editor/AssetDatabaseAssetResolverTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Collections; | ||
using NUnit.Framework; | ||
using UIComponents.Editor; | ||
using UnityEngine.TestTools; | ||
using UnityEngine.UIElements; | ||
|
||
namespace UIComponents.Tests.Editor | ||
{ | ||
[TestFixture] | ||
public class AssetDatabaseAssetResolverTests : AssetResolverTestSuite<AssetDatabaseAssetResolver> | ||
{ | ||
[UnityTest] | ||
public IEnumerator Should_Be_Able_To_Load_Existing_Asset() | ||
{ | ||
yield return Assert_Loads_Existing_Asset<StyleSheet>( | ||
"Assets/UIComponents.Tests/Addressables/Assets/Component.uss" | ||
); | ||
yield return Assert_Loads_Existing_Asset<VisualTreeAsset>( | ||
"Assets/UIComponents.Tests/Addressables/Assets/Component.uxml" | ||
); | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator Should_Be_Able_To_Tell_If_Asset_Exists() | ||
{ | ||
yield return Assert_Tells_If_Asset_Exists( | ||
"Assets/UIComponents.Tests/Addressables/Assets/Component.uss" | ||
); | ||
yield return Assert_Tells_If_Asset_Exists( | ||
"Assets/UIComponents.Tests/Addressables/Assets/Component.uxml" | ||
); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/UIComponents.Tests/Editor/AssetDatabaseAssetResolverTests.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Threading.Tasks; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace UIComponents.Editor | ||
{ | ||
/// <summary> | ||
/// An IAssetResolver which loads assets with AssetDatabase. | ||
/// </summary> | ||
/// <seealso cref="DependencyAttribute"/> | ||
/// <seealso cref="UIComponent"/> | ||
public class AssetDatabaseAssetResolver : IAssetResolver | ||
{ | ||
public Task<T> LoadAsset<T>(string assetPath) where T : Object | ||
{ | ||
var asset = AssetDatabase.LoadAssetAtPath<T>(assetPath); | ||
|
||
return Task.FromResult(asset); | ||
} | ||
|
||
public Task<bool> AssetExists(string assetPath) | ||
{ | ||
var asset = AssetDatabase.LoadAssetAtPath<Object>(assetPath); | ||
|
||
return Task.FromResult(asset != null); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/UIComponents/Editor/AssetDatabaseAssetResolver.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "UIComponents.Editor", | ||
"rootNamespace": "UIComponents", | ||
"references": [ | ||
"GUID:d593635333b4cae48bac5b5f0b596e90" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters