Exemple #1
0
        protected void OnFinishedLoadingAssetReference(AsyncOperation operation)
        {
            ResourceRequest request = (ResourceRequest)operation;

            List <string> assetReferences = AssetReferencesQueue[FIRST];
            string        assetReference  = assetReferences[AssetReferencesLoadedCount];

            if (request.asset == null)
            {
                FCgDebug.LogError("FCgManager_Loading.OnFinishedLoadingAssetReference: Failed to load asset at: " + assetReference);
                return;
            }

            LoadedAssets.Add(request.asset);

            int lastCount = AssetReferencesLoadedCount;

            ++AssetReferencesLoadedCount;

            // Get Memory loaded and the time it took
            int   bytes     = (int)Profiler.GetRuntimeMemorySizeLong(request.asset);
            float kilobytes = FCgCommon.BytesToKilobytes(bytes);
            float megabytes = FCgCommon.BytesToMegabytes(bytes);

            ResourceSizeLoaded.Bytes     += bytes;
            ResourceSizeLoaded.Kilobytes += kilobytes;
            ResourceSizeLoaded.Megabytes += megabytes;

            float currentTime = Time.realtimeSinceStartup;
            float loadingTime = currentTime - LoadingStartTime;

            if (LogLoading.Log())
            {
                FCgDebug.Log("FCsManager_Loading.OnFinishedLoadingAssetReference: Finished Loading " + assetReference + ". " + megabytes + " mb (" + kilobytes + " kb, " + bytes + " bytes) in " + loadingTime + " seconds.");
            }

            // Broadcast the event to anyone listening
            AssetReferenceLoadedCache.Reference      = assetReference;
            AssetReferenceLoadedCache.Count          = lastCount;
            AssetReferenceLoadedCache.Size.Bytes     = bytes;
            AssetReferenceLoadedCache.Size.Kilobytes = kilobytes;
            AssetReferenceLoadedCache.Size.Megabytes = megabytes;
            AssetReferenceLoadedCache.Time           = loadingTime;

            OnFinishedLoadingAssetReference_Event.Broadcast(AssetReferenceLoadedCache);
            // FirstToLast, Queue the NEXT Asset for Async Load
            if (AssetReferencesLoadedCount < assetReferences.Capacity)
            {
                if (LogLoading.Log())
                {
                    FCgDebug.Log("FCsManager_Loading.OnFinishedLoadingAssetReference: Requesting Load of " + assetReferences[AssetReferencesLoadedCount]);
                }
                OnStartLoadingAssetReference_Event.Broadcast(assetReferences[AssetReferencesLoadedCount]);

                ResourceRequest r = Resources.LoadAsync(assetReferences[AssetReferencesLoadedCount]);
                r.completed += OnFinishedLoadingAssetReference;
            }
            LoadingStartTime = currentTime;
        }
Exemple #2
0
        protected void OnFinishedLoadingAssetReference_Bulk(AsyncOperation operation)
        {
            ResourceRequest request = (ResourceRequest)operation;

#if UNITY_EDITOR
            string assetReference = AssetDatabase.GetAssetPath(request.asset);
#endif // #if UNITY_EDITOR

            if (request.asset == null)
            {
#if UNITY_EDITOR
                FCgDebug.LogError("FCgManager_Loading.OnFinishedLoadingAssetReference_Bulk: Failed to load asset at: " + assetReference);
#else
                FCgDebug.LogError("FCgManager_Loading.OnFinishedLoadingAssetReference_Bulk: Failed to load asset");
#endif // #if UNITY_EDITOR
                return;
            }

            LoadedAssets.Add(request.asset);

            int lastCount = AssetReferencesLoadedCount;

            ++AssetReferencesLoadedCount;

            // Get Memory loaded and the time it took
            int   bytes     = (int)Profiler.GetRuntimeMemorySizeLong(request.asset);
            float kilobytes = FCgCommon.BytesToKilobytes(bytes);
            float megabytes = FCgCommon.BytesToMegabytes(bytes);

            ResourceSizeLoaded.Bytes     += bytes;
            ResourceSizeLoaded.Kilobytes += kilobytes;
            ResourceSizeLoaded.Megabytes += megabytes;

            float currentTime = Time.realtimeSinceStartup;
            float loadingTime = currentTime - LoadingStartTime;

            if (LogLoading.Log())
            {
#if UNITY_EDITOR
                FCgDebug.Log("FCsManager_Loading.OnFinishedLoadingAssetReference_Bulk: Finished Loading " + assetReference + ". " + megabytes + " mb (" + kilobytes + " kb, " + bytes + " bytes).");
#else
                FCgDebug.Log("FCsManager_Loading.OnFinishedLoadingAssetReference_Bulk: Finished Loading an asset. " + megabytes + " mb (" + kilobytes + " kb, " + bytes + " bytes).");
#endif // #if UNITY_EDITOR
            }

#if UNITY_EDITOR
            // Broadcast the event to anyone listening
            AssetReferenceLoadedCache.Reference      = assetReference;
            AssetReferenceLoadedCache.Count          = lastCount;
            AssetReferenceLoadedCache.Size.Bytes     = bytes;
            AssetReferenceLoadedCache.Size.Kilobytes = kilobytes;
            AssetReferenceLoadedCache.Size.Megabytes = megabytes;
            AssetReferenceLoadedCache.Time           = loadingTime;

            OnFinishedLoadingAssetReference_Event.Broadcast(AssetReferenceLoadedCache);
#endif // #if UNITY_EDITOR
        }