public static AsyncOperationHandle <T> LoadAssetAsync <T>(AssetReferenceT <T> pAsset, Action <float> pProgress = null, Action <T> pOnCompleted = null) where T : Object { var operation = pAsset.LoadAssetAsync(); WaitLoadTask(operation, pProgress, pOnCompleted); return(operation); }
public void AssetReference_SetEditorAsset_ReturnsNullIfObjectTypeIsIncorrect() { AssetReferenceT <Sprite> incorrectlyTypedAssetReference = new AssetReferenceT <Sprite>("badguid"); incorrectlyTypedAssetReference.SetEditorAsset(subSO); Assert.IsNull(incorrectlyTypedAssetReference.editorAsset, "Attempting to set an editor asset of an incorrect type should return null."); }
internal AssetReferenceTracker(AssetReferenceT <TObject> _reference, AssetReferenceTrackerCallbackDelegate <TObject> _callback) { handle = _reference.LoadAssetAsync(); loadingTrackers.Add(handle, new Pair(this, _callback)); handle.Completed += OnCompleted; }
private IEnumerator ValidateTestDependency() { AsyncOperationHandle <IList <IResourceLocation> > locationsHandle = default(AsyncOperationHandle <IList <IResourceLocation> >); try { locationsHandle = Addressables.LoadResourceLocationsAsync("TestAddressablePrefab"); } catch (Exception e) { Assert.Inconclusive("You need to set TestAddressablePrefab key to run this test"); yield break; } while (!locationsHandle.IsDone) { yield return(null); } var locations = locationsHandle.Result; if (locations == null || locations.Count == 0) { Assert.Inconclusive("You need to set TestAddressablePrefab key to run this test"); } var resourceLocation = locations[0]; if (resourceLocation.ResourceType != typeof(GameObject)) { Assert.Inconclusive("TestAddressablePrefab should be a GameObject"); } addressablePrefabReference = new AssetReferenceT <GameObject>(resourceLocation.PrimaryKey); }
public void AssetReference_SetEditorAsset_SucceedsOnMatchedTypeAssetReference() { AssetReference typeCorrectReference = new AssetReferenceT <TestSubObject>("badguid"); typeCorrectReference.SetEditorAsset(subSO); Assert.NotNull(typeCorrectReference.editorAsset, "Attempting to set editor asset on an AssetReferenceT should return the first matching object at the guid"); Assert.AreEqual(subSO, typeCorrectReference.editorAsset, "Attempting to set editor asset on an AssetReferenceT should return the first matching object at the guid"); }
public void AssetReference_SetEditorAsset_ReturnsCorrectObjectIfMultipleOfSameTypeExist() { AssetReferenceT <TestSubObject> typedAssetReference = new AssetReferenceT <TestSubObject>("badguid"); typedAssetReference.SetEditorAsset(subSO2); Assert.AreEqual(subSO2, typedAssetReference.editorAsset, "When using a typed asset reference, the editor asset should be set to the requested object even if its a subobject."); Assert.AreNotEqual(subSO, typedAssetReference.editorAsset, "When using a typed asset reference, the editor asset should be set to specifically the requested object, not just an object with the same type and guid."); }
public void AssetReference_SetEditorAsset_NullsOnAttemptWithWrongTypeFromDerivedType() { var guid = AssetDatabase.AssetPathToGUID(m_ScriptableObjectPath); AssetReference typeConflictReference = new AssetReferenceT <Animation>("badguid"); typeConflictReference.SetEditorAsset(mainSO); Assert.IsNull(typeConflictReference.editorAsset, "Attempting to set editor asset on an AssetReferenceT should return null if the types do not match."); }
public static IAddressableObservable <TData> ToObservable <TData>(this AssetReferenceT <TData> reference) where TData : Object { var observable = ClassPool.Spawn <AddressableObservable <AssetReferenceT <TData>, TData, TData> >(); observable.Initialize(reference); return(observable); }
protected void LoadAsset() { var assetRef = new AssetReferenceT <UnityEngine.Object>(path); assetReference = assetRef; assetAsyncHandle = assetRef.LoadAssetAsync(); assetAsyncHandle.Completed += AddressableLoadCompleted; status = ContentAsyncStatus.Loading; }
public bool TryGetAsset(AssetReferenceT <TAsset> assetReference, out TAsset asset) { if (_preloadedAssets.TryGetValue(assetReference.RuntimeKey, out var handle)) { asset = handle.Result; return(true); } asset = default; return(false); }
public void AssetReference_SetEditorAsset_CorrectlySetsSubAssetWhenUsingTypedReference() { AssetReferenceT <TestSubObject> typedAssetReference = new AssetReferenceT <TestSubObject>("badguid"); typedAssetReference.SetEditorAsset(subSO); Assert.AreEqual(subSO, typedAssetReference.editorAsset, "When using a typed asset reference, the editor asset should be set to the requested object even if its a subobject."); AssetReference typedAssetReference2 = new AssetReferenceT <TestSubObject>("badguid"); typedAssetReference2.SetEditorAsset(subSO); Assert.AreEqual(subSO, typedAssetReference2.editorAsset, "When using a typed asset reference, the editor asset should be set to the requested object even if its a subobject."); }
public void SetObject_WhenTargetIsSubAsset_IsSetAsSubObject() { // Prepare test fbx m_fbxAssetPath = GetAssetPath("testFBX.fbx"); if (!File.Exists(m_fbxAssetPath)) { string fbxResourcePath = null; var repoRoot = Directory.GetParent(Application.dataPath).Parent?.FullName; if (!string.IsNullOrEmpty(repoRoot)) { fbxResourcePath = Path.Combine(repoRoot, "Projects", "TestsResources", "testFBX.fbx"); } if (string.IsNullOrEmpty(fbxResourcePath) || !File.Exists(fbxResourcePath)) { Assert.Ignore($"Unable to find required FBX file to run this test. Ignoring."); } File.Copy(fbxResourcePath, m_fbxAssetPath, true); AssetDatabase.Refresh(); } Assert.IsTrue(File.Exists(m_fbxAssetPath)); var fbxAsset = AssetDatabase.LoadAssetAtPath <Object>(m_fbxAssetPath); var meshSubAsset = AssetDatabase.LoadAllAssetRepresentationsAtPath(m_fbxAssetPath).First(o => o is Mesh); AssetDatabase.TryGetGUIDAndLocalFileIdentifier(fbxAsset, out string fbxAssetGuid, out long _); Assert.IsFalse(string.IsNullOrEmpty(fbxAssetGuid)); // Setup property var ar = new AssetReferenceT <Mesh>(""); var obj = ScriptableObject.CreateInstance <TestObjectWithRef>(); obj.Reference = ar; var so = new SerializedObject(obj); var property = so.FindProperty("Reference"); // Test string guid; m_AssetReferenceDrawer = new AssetReferenceDrawer(); m_AssetReferenceDrawer.GatherFilters(property); m_AssetReferenceDrawer.m_AssetRefObject = ar; var success = m_AssetReferenceDrawer.SetObject(property, meshSubAsset, out guid); // Assert Assert.IsTrue(success); Assert.AreEqual(fbxAssetGuid, guid); Assert.AreEqual(fbxAsset.name, m_AssetReferenceDrawer.m_AssetRefObject.editorAsset.name); Assert.AreEqual(meshSubAsset.name, m_AssetReferenceDrawer.m_AssetRefObject.SubObjectName); Assert.AreEqual(meshSubAsset.GetType(), m_AssetReferenceDrawer.m_AssetRefObject.SubOjbectType); }
public void UnloadAsset(AssetReferenceT <TAsset> assetReference) { var key = assetReference.RuntimeKey; if (_preloadedAssets.TryGetValue(key, out var handle)) { Addressables.Release(handle); _preloadedAssets.Remove(key); } else { Debug.LogWarning($"{Constants.LogsTag} Trying to unload not loaded asset: {assetReference.RuntimeKey}"); } }
public void AssetReferenceEditorAssetForSubObject_DifferentType() { var guid = AssetDatabase.AssetPathToGUID(m_ScriptableObjectPath); AssetReferenceT <TestSubObject> typeReference = new AssetReferenceT <TestSubObject>(guid); typeReference.SubObjectName = "sub"; //Test Assert.IsNull(typeReference.editorAsset); AssetReference asBase = typeReference; Assert.IsNotNull(asBase.editorAsset); Assert.AreEqual(asBase.editorAsset, AssetDatabase.LoadAssetAtPath <TestObject>(m_ScriptableObjectPath)); }
public static async UniTask <TAsset> LoadAssetAsync <TAsset>( this IAddressablesLoader <TAsset> addressablesLoader, AssetReferenceT <TAsset> assetReference) where TAsset : Object { if (addressablesLoader.IsAssetPreloaded(assetReference)) { return(addressablesLoader.GetAsset(assetReference)); } await addressablesLoader.PreloadAssetAsync(assetReference); return(addressablesLoader.GetAsset(assetReference)); }
public void AssetReferenceEditorAssetForSubObject_NullIfIncorrectType() { var guid = AssetDatabase.AssetPathToGUID(m_ScriptableObjectPath); AssetReferenceT <Animation> typeReference = new AssetReferenceT <Animation>(guid); typeReference.SubObjectName = "sub"; //Test Assert.IsNull(typeReference.editorAsset, "Attempting to get an object of a type not located at a guid should return a null value."); AssetReference asBase = typeReference; Assert.IsNull(asBase.editorAsset, "Attempting to get an object type not located at a guid should return a null value even if the method of the generic AssetReference class is being called."); AssetReference baseReference = new AssetReference(guid); Assert.AreEqual(baseReference.editorAsset, AssetDatabase.LoadAssetAtPath <TestObject>(m_ScriptableObjectPath), "Generic AssetReference should get the asset of the main type at the guid."); }
public void AssetReferenceEditorAssetForSubObject_DifferentType() { var guid = AssetDatabase.AssetPathToGUID(m_ScriptableObjectPath); AssetReferenceT <TestSubObject> typeReference = new AssetReferenceT <TestSubObject>(guid); typeReference.SubObjectName = "sub"; //Test Assert.AreEqual(typeReference.editorAsset, AssetDatabase.LoadAssetAtPath <TestSubObject>(m_ScriptableObjectPath), "AssetReference with explicit type should get first instance of that type at that guid."); AssetReference asBase = typeReference; Assert.IsNotNull(asBase.editorAsset); Assert.AreEqual(asBase.editorAsset, AssetDatabase.LoadAssetAtPath <TestSubObject>(m_ScriptableObjectPath), "AssetReference with explicit type declared under generic AssetReference should still get the first instance of the specific type at the guid."); AssetReference baseReference = new AssetReference(guid); Assert.AreEqual(baseReference.editorAsset, AssetDatabase.LoadAssetAtPath <TestObject>(m_ScriptableObjectPath), "Generic AssetReference should get the asset of the main type at the guid."); }
public async UniTask PreloadAssetAsync(AssetReferenceT <TAsset> assetReference) { if (_preloadedAssets.ContainsKey(assetReference.RuntimeKey)) { Debug.LogWarning($"{Constants.LogsTag} Trying to load already loaded asset: {assetReference.RuntimeKey}"); return; } var handle = Addressables.LoadAssetAsync <TAsset>(assetReference); await handle; lock (_preloadedAssets) { _preloadedAssets.Add(assetReference.RuntimeKey, handle); } }
public AsyncFromBinderBase FromAssetReferenceT <TConcreteObj>(AssetReferenceT <TConcreteObj> reference) where TConcreteObj : UnityEngine.Object, TConcrete { BindInfo.RequireExplicitScope = false; var contractType = typeof(TContract); if (typeof(UnityEngine.Object).IsAssignableFrom(contractType)) { var addressableInjectType = typeof(AddressableInject <>).MakeGenericType(typeof(TContract)); BindInfo.ContractTypes.Add(addressableInjectType); } // Don't know how it's created so can't assume here that it violates AsSingle BindInfo.MarkAsCreationBinding = false; SubFinalizer = new ScopableBindingFinalizer( BindInfo, (container, originalType) => new AddressableProviderSimple <TContract, TConcreteObj>(reference)); return(this); }
public static bool TryInstantiateMultiOrLoadAsync <TComponentType>(AssetReferenceT <TComponentType> aRef, int count, Vector3 position, Quaternion rotation, Transform parent, out AsyncOperationHandle <List <TComponentType> > handle) where TComponentType : Component { return(TryInstantiateMultiOrLoadAsync(aRef as AssetReference, count, position, rotation, parent, out handle)); }
public static bool TryGetComponentSync <TComponentType>(AssetReferenceT <TComponentType> aRef, out TComponentType result) where TComponentType : Component { return(TryGetComponentSync(aRef as AssetReference, out result)); }
public static AssetReferenceTracker <TObject> LoadAssetAsyncAndTrack <TObject>(this AssetReferenceT <TObject> _reference, AssetReferenceTrackerCallbackDelegate <TObject> _callback = null) where TObject : UnityEngine.Object { return(new AssetReferenceTracker <TObject>(_reference, _callback)); }
public AnimationGameObjectAssetLoader(AssetReferenceT <GameObject> assetReference) : base(assetReference) { }
protected override AsyncOperationHandle <GameObject> LoadAsync(AssetReferenceT <GameObject> assetReference) { return(Addressables.InstantiateAsync(assetReference.RuntimeKey, this.root.transform, false, false)); }
public void Teardown() { addressablePrefabReference = null; Resources.UnloadUnusedAssets(); }
public static bool TryInstantiateMultiSync <TComponentType>(AssetReferenceT <TComponentType> aRef, int count, Vector3 position, Quaternion rotation, Transform parent, out List <TComponentType> result) where TComponentType : Component { return(TryInstantiateMultiSync(aRef as AssetReference, count, position, rotation, parent, out result)); }
public static bool TryGetObjectSync <TObjectType>(AssetReferenceT <TObjectType> aRef, out TObjectType result) where TObjectType : Object { return(TryGetObjectSync(aRef as AssetReference, out result)); }
public AddressableProviderSimple(AssetReferenceT <TConcrete> assetReference) { this.assetReference = assetReference; }
public static UniTask <T> LoadAssetAsync <T>(this AssetReferenceT <T> assetReference, IProgress <float> progress = null, PlayerLoopTiming playerLoopTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default) where T : UnityEngine.Object { return(assetReference.LoadAssetAsync <T>().ConfigureAwait(progress, playerLoopTiming, cancellationToken)); }
/// <summary> /// Load the object using an asset reference. /// </summary> /// <param name="reference">The asset reference.</param> public AssetLoadingHandle(AssetReferenceT <T> reference) : base(reference.LoadAssetAsync()) { base.onCompleted += OnCompleted; }