Exemplo n.º 1
0
        /// <summary>
        /// Returns the loading operation for the asset.
        /// Check isDone to see if the asset is available for immediate use, if not you can yield on the operation or add a callback subscriber.
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public AsyncOperationHandle <TObject> GetAssetAsync <TObject>(long keyId) where TObject : Object
        {
            var entry = GetEntry(keyId);

            if (entry == null)
            {
                var keyName = SharedData.GetKey(keyId);

                return(ResourceManager.CreateCompletedOperation <TObject>(null, $"Could not find asset with key \"{keyName}({keyId})\""));
            }
            return(GetAssetAsync <TObject>(entry));
        }
 internal AsyncOperationHandle <TObject> GetAssetAsync <TObject>(AssetTableEntry entry) where TObject : Object
 {
     if (!entry.AsyncOperation.HasValue)
     {
         if (string.IsNullOrEmpty(entry.Guid))
         {
             var keyName = SharedData.GetKey(entry.Data.Id);
             return(ResourceManager.CreateCompletedOperation <TObject>(null, $"The asset table entry \"{keyName}({entry.Data.Id})\" is empty, no asset can be loaded from the table \"{ToString()}\""));
         }
         entry.AsyncOperation = Addressables.LoadAssetAsync <TObject>(entry.Guid);
     }
     return(entry.AsyncOperation.Value.Convert <TObject>());
 }