public bool Load(long localBandwidth, long remoteBandwidth) { if (Time.unscaledTime > m_LastUpdateTime) { m_BytesLoaded += (long)Math.Ceiling((Time.unscaledTime - m_LastUpdateTime) * localBandwidth); m_LastUpdateTime = Time.unscaledDeltaTime; } if (m_BytesLoaded < m_AssetInfo.Size) { return(true); } if (!(Context is IResourceLocation)) { return(false); } var assetPath = (Context as IResourceLocation).InternalId; var t = typeof(TObject); if (t.IsArray) { SetResult(ResourceManagerConfig.CreateArrayResult <TObject>(AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath))); } else if (t.IsGenericType && typeof(IList <>) == t.GetGenericTypeDefinition()) { SetResult(ResourceManagerConfig.CreateListResult <TObject>(AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath))); } else { SetResult(AssetDatabase.LoadAssetAtPath(assetPath, typeof(TObject)) as TObject); } InvokeCompletionEvent(); return(false); }
internal override TObject ConvertResult(AsyncOperation op) { var t = typeof(TObject); try { var req = op as AssetBundleRequest; if (req == null) { return(null); } if (t.IsArray) { return(ResourceManagerConfig.CreateArrayResult <TObject>(req.allAssets)); } if (t.IsGenericType && typeof(IList <>) == t.GetGenericTypeDefinition()) { return(ResourceManagerConfig.CreateListResult <TObject>(req.allAssets)); } return(req.asset as TObject); } catch (Exception e) { OperationException = e; return(null); } }
void CompleteLoad() { var location = Context as IResourceLocation; var assetPath = location == null ? string.Empty : location.InternalId; var t = typeof(TObject); if (t.IsArray) { SetResult(ResourceManagerConfig.CreateArrayResult <TObject>(AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath))); } else if (t.IsGenericType && typeof(IList <>) == t.GetGenericTypeDefinition()) { SetResult(ResourceManagerConfig.CreateListResult <TObject>(AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath))); } else { SetResult(AssetDatabase.LoadAssetAtPath(assetPath, typeof(TObject)) as TObject); } OnComplete(); }
/// <inheritdoc/> public override IAsyncOperation <TObject> Provide <TObject>(IResourceLocation location, IAsyncOperation <IList <object> > loadDependencyOperation) { if (location == null) { throw new ArgumentNullException("location"); } var t = typeof(TObject); if (t.IsArray) { return(new CompletedOperation <TObject>().Start(location, location.InternalId, ResourceManagerConfig.CreateArrayResult <TObject>(Resources.LoadAll(location.InternalId, t.GetElementType())))); } if (t.IsGenericType && typeof(IList <>) == t.GetGenericTypeDefinition()) { return(new CompletedOperation <TObject>().Start(location, location.InternalId, ResourceManagerConfig.CreateListResult <TObject>(Resources.LoadAll(location.InternalId, t.GetGenericArguments()[0])))); } return(AsyncOperationCache.Instance.Acquire <InternalOp <TObject> >().StartOp(location)); }