Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ MonoBehaviour:
m_ReadOnly: 0
m_SerializedLabels: []
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: 0bbeb665cb8b4bb4cbea314581e50bab
m_Address: Assets/DCL/InWorldCamera/InWorldCamera/UI/Textures/RuleOf3rd.png
m_ReadOnly: 0
m_SerializedLabels: []
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: 0eecf14978c1aa74381023946dde5c78
m_Address: Character Object
m_ReadOnly: 0
Expand All @@ -65,6 +70,11 @@ MonoBehaviour:
m_ReadOnly: 0
m_SerializedLabels: []
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: 1979326266a1bec44bc70519850f7a5a
m_Address: Assets/DCL/AuthenticationScreenFlow/Assets/Textures/PadlockImg.png
m_ReadOnly: 0
m_SerializedLabels: []
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: 1b149c5240fcd49309285605ce2e8067
m_Address: CategoryMarkerObject
m_ReadOnly: 0
Expand Down Expand Up @@ -165,6 +175,11 @@ MonoBehaviour:
m_ReadOnly: 0
m_SerializedLabels: []
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: 4974685691c134a35bcea75af1936381
m_Address: Assets/DCL/UI/Controls/Textures/Controls.png
m_ReadOnly: 0
m_SerializedLabels: []
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: 4a2a7b610414b45c1b576946ce094877
m_Address: NftCategoryIcons
m_ReadOnly: 0
Expand Down
43 changes: 23 additions & 20 deletions Explorer/Assets/DCL/AssetsProvision/AssetsProvision.asmdef
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
{
"name": "AssetsProvision",
"rootNamespace": "",
"references": [
"GUID:9e24947de15b9834991c9d8411ea37cf",
"GUID:84651a3751eca9349aac36a66bba901b",
"GUID:593a5b492d29ac6448b1ebf7f035ef33",
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:3640f3c0b42946b0b8794a1ed8e06ca5",
"GUID:4a12c0b1b77ec6b418a8d7bd5c925be3",
"GUID:8322ea9340a544c59ddc56d4793eac74"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
"name": "AssetsProvision",
"rootNamespace": "",
"references": [
"GUID:9e24947de15b9834991c9d8411ea37cf",
"GUID:84651a3751eca9349aac36a66bba901b",
"GUID:593a5b492d29ac6448b1ebf7f035ef33",
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:3640f3c0b42946b0b8794a1ed8e06ca5",
"GUID:4a12c0b1b77ec6b418a8d7bd5c925be3",
"GUID:8322ea9340a544c59ddc56d4793eac74",
"GUID:fa7b3fdbb04d67549916da7bd2af58ab",
"GUID:eec0964c48f6f4e40bc3ec2257ccf8c5",
"GUID:166b65e6dfc848bb9fb075f53c293a38"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
3 changes: 3 additions & 0 deletions Explorer/Assets/DCL/AssetsProvision/Contextual.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using Cysharp.Threading.Tasks;
using System;
using System.Threading;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using Utility.Ownership;
using Object = UnityEngine.Object;

namespace DCL.AssetsProvision
{
public class ContextualAsset<T> : IDisposable where T: Object
{
private readonly AssetReferenceT<T> reference;
private Owned<T>? asset;

public enum State
{
UNLOADED,
LOADING,
LOADED,
}

public State CurrentState { get; private set; }

public ContextualAsset(AssetReferenceT<T> reference)
{
this.reference = reference;
asset = null;
CurrentState = State.UNLOADED;
}

public async UniTask<Weak<T>> AssetAsync(CancellationToken token)
{
try
{
if (asset == null)
{
CurrentState = State.LOADING;
var handle = reference.LoadAssetAsync();
await handle.Task!.AsUniTask().AttachExternalCancellation(token);
if (handle.Status != AsyncOperationStatus.Succeeded) throw new Exception($"Load failed: {reference.RuntimeKey}");
T value = handle.Result!;
asset = new Owned<T>(value);
CurrentState = State.LOADED;
}

return asset!.Downgrade();
}
catch (Exception)
{
CurrentState = State.UNLOADED;
throw;
}
}

public void Release()
{
if (asset == null) return;
reference.ReleaseAsset();
asset.Dispose(out _);
asset = null;
CurrentState = State.UNLOADED;
}

public void Dispose()
{
Release();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using Cysharp.Threading.Tasks;
using DCL.Diagnostics;
using DCL.Utilities.Extensions;
using System;
using System.Threading;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.UI;
using Utility.Ownership;
using Utility.Types;

namespace DCL.AssetsProvision
{
// Can be improved further with prewarming by asset groups
[RequireComponent(typeof(Image))]
public class ContextualImage : MonoBehaviour
{
[SerializeField] private Image image = null!;
[SerializeField] private AssetReferenceT<Sprite> spriteAsset = null!;

private ContextualAsset<Sprite> asset = null!;

private void Awake()
{
if (image.sprite != null)
ReportHub.LogError(ReportCategory.UI, "Image must not have a sprite to avoid hard linking the sprite into memory, when sprite is linked directly the contextual load won't apply optimization effect");

asset = new ContextualAsset<Sprite>(spriteAsset.EnsureNotNull("reference != null"));
}

private void OnEnable()
{
if (asset.CurrentState is ContextualAsset<Sprite>.State.UNLOADED)
LoadAsync().Forget();
}

private async UniTask LoadAsync()
{
Weak<Sprite> sprite = await asset.AssetAsync(destroyCancellationToken);
Option<Sprite> resource = sprite.Resource;

if (resource.Has) image.sprite = resource.Value;
else ReportHub.LogError(ReportCategory.UI, "Cannot load grid asset");
}

private void OnDisable()
{
image.sprite = null!;
asset.Release();
}

private void OnDestroy()
{
image.sprite = null!;
asset.Dispose();
}

public UniTask TriggerOrWaitReadyAsync(CancellationToken token) =>
asset.CurrentState switch
{
ContextualAsset<Sprite>.State.UNLOADED => LoadAsync(),
ContextualAsset<Sprite>.State.LOADING => UniTask.WaitWhile(() => asset.CurrentState is ContextualAsset<Sprite>.State.LOADING, cancellationToken: token),
ContextualAsset<Sprite>.State.LOADED => UniTask.CompletedTask,
_ => throw new ArgumentOutOfRangeException()
};
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Cysharp.Threading.Tasks;
using System;
using System.Threading;
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Localization.Tables;
using Utility.Ownership;
using Object = UnityEngine.Object;

namespace DCL.AssetsProvision
{
public sealed class ContextualLocalizedAsset<T> : IDisposable where T: Object
{
private readonly LocalizedAsset<T> localizedAsset;
private readonly AssetTable assetTable;
private readonly CancellationTokenSource cancellationTokenSource;

private Owned<T>? asset;

public ContextualLocalizedAsset(LocalizedAsset<T> localizedAsset, AssetTable assetTable)
{
this.localizedAsset = localizedAsset;
this.assetTable = assetTable;
this.cancellationTokenSource = new CancellationTokenSource();
}

public async UniTask<Weak<T>> AssetAsync()
{
if (asset == null)
{
T value = await localizedAsset.LoadAssetAsync().ToUniTask();
asset = new Owned<T>(value);
}

return asset!.Downgrade();
}

public void Release()
{
if (asset == null) return;
asset!.Dispose(out T? _); // T : UnityEngine.Object doesn't require additional release logic
assetTable.ReleaseAsset(localizedAsset.TableEntryReference);
asset = null;
}

public void Dispose()
{
Release();
cancellationTokenSource.Cancel();
cancellationTokenSource.Dispose();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1074,8 +1074,9 @@ GameObject:
- component: {fileID: 8128219955958824478}
- component: {fileID: 7128006657025016999}
- component: {fileID: 8478992858286646769}
- component: {fileID: 4407985999973896273}
m_Layer: 0
m_Name: Image
m_Name: PadLock
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
Expand Down Expand Up @@ -1128,7 +1129,7 @@ MonoBehaviour:
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: 1979326266a1bec44bc70519850f7a5a, type: 3}
m_Sprite: {fileID: 0}
m_Type: 0
m_PreserveAspect: 1
m_FillCenter: 1
Expand All @@ -1138,6 +1139,26 @@ MonoBehaviour:
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!114 &4407985999973896273
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4861453223584964866}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9688e6de611b437aaa1cbd8dd2bcd932, type: 3}
m_Name:
m_EditorClassIdentifier:
image: {fileID: 8478992858286646769}
spriteAsset:
m_AssetGUID: 1979326266a1bec44bc70519850f7a5a
m_SubObjectName: PadlockImg
m_SubObjectType: UnityEngine.Sprite, UnityEngine.CoreModule, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
m_SubObjectGUID:
m_EditorAssetChanged: 0
--- !u!1 &5312144585228980273
GameObject:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ MonoBehaviour:
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Texture: {fileID: 2800000, guid: feb17d16b84e84e55a6dc530923024ef, type: 3}
m_Texture: {fileID: 0}
m_UVRect:
serializedVersion: 2
x: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public void Initialize(RenderTexture targetTexture, Vector3 position)
cameraData.renderPostProcessing = false;
}

public void DeInitialize()
{
camera.targetTexture = null!;
}

public void SetCameraPosition(CharacterPreviewCameraPreset preset)
{
if (cameraTarget != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public void Dispose()
if (globalWorld.TryGet(characterPreviewEntity, out AvatarBase avatarBase) && avatarBase != null)
avatarBase.HeadIKRig.weight = 0;

characterPreviewAvatarContainer.DeInitialize();
characterPreviewContainerPool.Release(characterPreviewAvatarContainer);
cameraController.Dispose();
}
Expand Down
Loading
Loading