Esempio n. 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;
        }
Esempio n. 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
        }
Esempio n. 3
0
        public void OnUpdate(float deltaTime)
        {
            // If Queue Empty, EXIT
            if (AssetReferencesQueue.Capacity == EMPTY)
            {
                return;
            }

            List <string> assetReferences = AssetReferencesQueue[FIRST];

            if (AsyncOrders[FIRST] == ECgLoadAsyncOrder.Bulk)
            {
                OnLoadProgressUpdated_Event.Broadcast((float)AssetReferencesLoadedCount / (float)assetReferences.Capacity);
            }

            // If Still Loading, EXIT
            if (AssetReferencesLoadedCount < assetReferences.Capacity)
            {
                return;
            }

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

            // All AssetReferences are LOADED
            if (LogLoading.Log())
            {
                // FirstToLast
                if (AsyncOrders[FIRST] == ECgLoadAsyncOrder.FirstToLast)
                {
                    FCgDebug.Log("FCsManager_Loading.OnUpdate: Finished Loading " + AssetReferencesLoadedCount + " Assets. " + ResourceSizeLoaded.ToString_Megabytes() + " in " + loadingTime + " seconds");
                }
                // None | Bulk
                else
                {
                    FCgDebug.Log("FCsManager_Loading.OnUpdate: Finished Loading " + AssetReferencesLoadedCount + " Assets in " + loadingTime + " seconds");
                }
            }

            AsyncOrders.RemoveAt(FIRST);
            AssetReferencesQueue.RemoveAt(FIRST);

            OnFinishedLoadingAssetReferences_Events[FIRST].Broadcast(LoadedAssets, loadingTime);
            OnFinishedLoadingAssetReferences_Events.RemoveAt(FIRST);

            OnFinishedLoadingAssetReferences_Event.Broadcast(LoadedAssets, loadingTime);

            // Assume the Callback holds onto the references for LoadedAssets
            LoadedAssets.Clear();

            // If Queue is NOT Empty, Load the next batch of AssetReferences
            if (AssetReferencesQueue.Capacity != EMPTY)
            {
                LoadAssetReferences_Internal(AssetReferencesQueue[FIRST], AsyncOrders[FIRST]);
            }
        }
Esempio n. 4
0
        public void LoadAssetReferences_Internal(List <string> assetReferences, ECgLoadAsyncOrder asyncOrder)
        {
            AssetReferencesLoadedCount = 0;

            ResourceSizeLoaded.Reset();

            // Start Loading - Load All References

            int size = assetReferences.Capacity;

            OnStartLoadingAssetReferences_Event.Broadcast(size);
            OnStartLoadProgress_Event.Broadcast(size);

            if (LogLoading.Log())
            {
                FCgDebug.Log("FCgManager_Loading.LoadAssetReferences_Internal: Requesting Load of " + size + " Assets");
                // None | Bulk
                if (asyncOrder == ECgLoadAsyncOrder.None ||
                    asyncOrder == ECgLoadAsyncOrder.Bulk)
                {
                    for (int i = 0; i < size; ++i)
                    {
                        FCgDebug.Log("FCsManager_Loading.LoadAssetReferences_Internal: Requesting Load of " + assetReferences[i]);
                    }
                }
            }
            // Start the Async Load

            // FirstToLast
            if (asyncOrder == ECgLoadAsyncOrder.FirstToLast)
            {
                if (LogLoading.Log())
                {
                    FCgDebug.Log("FCsManager_Loading.LoadAssetReferences_Internal: Requesting Load of " + assetReferences[FIRST]);
                }
                OnStartLoadingAssetReference_Event.Broadcast(assetReferences[FIRST]);

                ResourceRequest r = Resources.LoadAsync(assetReferences[FIRST]);
                r.completed += OnFinishedLoadingAssetReference;
            }
            // Bulk
            else
            {
                for (int i = 0; i < size; ++i)
                {
                    ResourceRequest r = Resources.LoadAsync(assetReferences[i]);
                    r.completed += OnFinishedLoadingAssetReference_Bulk;
                }
            }

            LoadingStartTime      = Time.realtimeSinceStartup;
            LoadingTotalStartTime = LoadingStartTime;
        }
Esempio n. 5
0
        public static void Init(Type type)
        {
            if (_Instance != null)
            {
                return;
            }

            if (!type.IsSubclassOf(typeof(FCgBlockchain)))
            {
                FCgDebug.Log("FCgBlockchain.Init: Passed in Type of " + type.GetType().Name + " is NOT a SubclassOf FCgBlockchain");
                return;
            }
            ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);

            _Instance = (ICgBlockchain)constructor.Invoke(Type.EmptyTypes);
        }
Esempio n. 6
0
        public static void Init(Type type)
        {
            if (_Instance != null)
            {
                return;
            }

            if (!type.IsSubclassOf(typeof(TCgManager_PooledObjects_Map <FECgProcess, FCgProcess, FCgProcessPayload>)))
            {
                FCgDebug.Log("ICgManager_Process.Init: Passed in Type of " + type.GetType().Name + " is NOT a SubclassOf TCgManager_PooledObjects_Map<ECgProcess, FCgProcess, FCgProcessPayload>");
                return;
            }

            GameObject go = new GameObject("Manager_Process");

            _Instance = go.AddComponent <ICgManager_Process>();

            _Instance.Internal = (FCgManager_Process)type.GetConstructor(Type.EmptyTypes).Invoke(Type.EmptyTypes);
            _Instance.Internal.OnAddToPool_Event.Add(_Instance.OnAddToPool);
        }
Esempio n. 7
0
        public static void Init(Type type)
        {
            if (_Instance != null)
            {
                return;
            }

            if (!type.IsSubclassOf(typeof(TCgManager_PooledMonoObjects_Map <FECgProjectileType, MCgProjectile, FCgProjectilePayload, FCgProjectileCache>)))
            {
                FCgDebug.Log("ICgManager_Projectile.Init: Passed in Type of " + type.GetType().Name + " is NOT a SubclassOf TCgManager_PooledMonoObjects_Map<FECgProjectileType, MCgProjectile, FCgProjectilePayload, FCgProjectileCache>");
                return;
            }

            GameObject go = MonoBehaviour.Instantiate(FCgManager_Prefab.Get().EmptyGameObject);

            _Instance = go.AddComponent <ICgManager_Projectile>();
            go.name   = "ICgManager_Projectile";

            _Instance.Internal = (FCgManager_Projectile)type.GetConstructor(Type.EmptyTypes).Invoke(Type.EmptyTypes);
            _Instance.Internal.OnAddToPool_Event.Add(_Instance.OnAddToPool);
            _Instance.Internal.ConstructObject.Unbind();
            _Instance.Internal.ConstructObject.Bind(_Instance.ConstructObject);
        }