Example #1
0
        private void Update()
        {
            if (m_operation == null || !m_operation.isDone)
            {
                return;
            }

            m_loadedObject = m_operation.GetAsset <GameObject>();
            m_operation    = null;

            if (!m_loadedObject)
            {
                Logger.LogWarning("AssetManager: [{1}] Failed to load {0}.", m_assetName, name);
                m_loadedObject = new GameObject(m_assetName);
            }
            else
            {
                m_loadedObject      = GameObject.Instantiate(m_loadedObject);
                m_loadedObject.name = m_assetName;
            }

            Util.AddChild(transform, m_loadedObject.transform);

            if (m_onLoad != null)
            {
                m_onLoad(this);
            }
            m_onLoad = null;

            AssetManager.UnloadAssetBundle(m_assetName);
        }
Example #2
0
        // Sets up download operation for the given asset bundle if it's not downloaded already.
        protected static bool LoadAssetBundleInternal(string name)
        {
            // Already loaded.
            var bundle = m_assets.Get(name);

            if (bundle != null)
            {
                bundle.refCount++;
                return(true);
            }

            // Already in loading queue
            var operation = m_operations.Find(o => o.name == name);

            if (operation != null)
            {
                operation.refCount++;
                return(true);
            }

            // Add new load operation
            operation = new AssetLoadOperation(name, m_serverUrl, LoadType.Load);

            m_operations.Add(operation);

            return(false);
        }
Example #3
0
        void ProcessSimulateOperation(AssetLoadOperation operation)
        {
            var asset = Asset.Create(operation.name, operation.GetAssets());

            asset.refCount = operation.refCount;
            m_assets.Set(operation.name, asset);
        }
Example #4
0
 private void ProcessFinishedOperation(AssetLoadOperation operation)
 {
     if (!operation.fromCache && operation.asset)
     {
         var asset = Asset.Create(operation.asset);
         asset.refCount = operation.refCount;
         m_assets.Set(operation.name, asset);
     }
 }
Example #5
0
        public void Load(string assetName, System.Action <AssetLoader> onLoad = null)
        {
            StopAllCoroutines();

            m_onLoad = onLoad;

            m_assetName = assetName;
            m_operation = AssetManager.LoadAssetAsync(m_assetName, m_assetName, typeof(GameObject));

            Update();
        }
Example #6
0
        // Load level from the given assetBundle.
        static public AssetLoadOperation LoadLevelAsync(string assetBundleName, string levelName, bool isAdditive)
        {
            Log(LogType.Info, "Loading " + levelName + " from " + assetBundleName + " bundle");

            AssetLoadOperation operation = null;

            assetBundleName = RemapVariantName(assetBundleName);
            LoadAssetBundle(assetBundleName);
            operation = new AssetBundleLoadLevelOperation(assetBundleName, levelName, isAdditive);

            m_InProgressOperations.Add(operation);


            return(operation);
        }
Example #7
0
        /// <summary>
        /// Starts a load operation for an asset from the given asset bundle.
        /// </summary>
        public static AssetLoadOperation LoadAssetAsync(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }

            if (enableLog && (!Level.loading || enableLoadingLog))
            {
                Logger.LogDetail("AssetManager: Loading asset bundle {0}", name);
            }

            AssetLoadOperation operation = null;

#if UNITY_EDITOR
            if (simulateMode)
            {
                var assetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(name);
                if (assetPaths.Length == 0)
                {
                    Logger.LogError("There is no asset bundle with name \"{0}\".", name);
                    return(null);
                }

                var target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]);
                operation = new AssetLoadOperation(name, target);
                operation.Complete();
                instance.ProcessSimulateOperation(operation);
            }
            else
#endif
            {
                operation = m_operations.Find(op => op.name == name);

                if (operation != null)
                {
                    operation.refCount++;
                }
                else
                {
                    operation = new AssetLoadOperation(name, m_serverUrl, LoadType.Load);

                    _AddOperation(operation);
                }
            }

            return(operation);
        }
Example #8
0
        public static AssetLoadOperation LoadManifest()
        {
#if UNITY_EDITOR
            Logger.LogDetail("AssetManager: Simulation Mode is [{0}]", simulateMode ? "Enabled" : "Disabled");

            if (simulateMode)
            {
                return(null);
            }
#endif

            Logger.LogDetail("AssetManager: Loading manifest file...");

            var operation = new AssetLoadOperation(platform, serverURL, "AssetBundleManifest", typeof(AssetBundleManifest));
            m_operations.Add(operation);
            return(operation);
        }
Example #9
0
        /// <summary>
        /// Starts a load operation for an asset from the given asset bundle and asset name.
        /// </summary>
        public static AssetLoadOperation LoadAssetAsync(string name, string assetName, Type type)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }

            if (enableLog && (!Level.loading || enableLoadingLog))
            {
                Logger.LogDetail("AssetManager: Loading {0} [{1}] from bundle {2}", string.IsNullOrEmpty(assetName) ? "all" : assetName, type.Name, name);
            }

            AssetLoadOperation operation = null;

#if UNITY_EDITOR
            if (simulateMode)
            {
                var assetPaths = string.IsNullOrEmpty(assetName) ? AssetDatabase.GetAssetPathsFromAssetBundle(name) : AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(name, assetName);

                if (!string.IsNullOrEmpty(assetName))
                {
                    var target = assetPaths.Length < 1 ? null : AssetDatabase.LoadMainAssetAtPath(assetPaths[0]);
                    if (!target || target.GetType() != type && !target.GetType().IsSubclassOf(type))
                    {
                        Logger.LogError("There is no asset with name \"{0}\" in {1} matche type {2}", assetName, name, type);
                        return(null);
                    }
                    operation = new AssetLoadOperation(name, target);
                    operation.Complete();
                    instance.ProcessSimulateOperation(operation);
                }
                else
                {
                    var targets = new Object[assetPaths.Length];
                    for (var i = 0; i < assetPaths.Length; ++i)
                    {
                        targets[i] = AssetDatabase.LoadMainAssetAtPath(assetPaths[i]);
                    }

                    if (targets.Length < 1)
                    {
                        Logger.LogError("Load asset {0} failed, bundle is empty", name);
                        return(null);
                    }

                    operation = new AssetLoadOperation(name, targets);
                    operation.Complete();
                    instance.ProcessSimulateOperation(operation);
                }
            }
            else
#endif
            {
                operation = m_operations.Find(op => op.name == name);

                if (operation != null)
                {
                    operation.refCount++;
                }
                else
                {
                    operation = new AssetLoadOperation(name, m_serverUrl, assetName, type);

                    _AddOperation(operation);
                }
            }

            return(operation);
        }
Example #10
0
        private static void _AddOperation(AssetLoadOperation op)
        {
            LoadDependencies(op.name);     // Load dependencies first

            m_operations.Add(op);
        }