Beispiel #1
0
 private void LogWarning(string format, params object[] args)
 {
     if (ShowLog)
     {
         Debuger.LogWarning(LOG_TAG, format, args);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Dispose是有引用检查的, DoDispose一般用于继承重写
        /// </summary>
        public void Dispose()
        {
            if (DisposeEvent != null)
            {
                DisposeEvent();
            }
            DisposeEvent = null;

            if (!IsForceNew)
            {
                bool bRemove = LoaderCache.RemoveLoader(this);
                if (!bRemove)
                {
                    Debuger.LogWarning("[{0}:Dispose], No Url: {1}, Cur RefCount: {2}", GetType().Name, AssetPath, RefCount);
                }
            }

            if (IsCompleted)
            {
                DoDispose();
            }
            else
            {
                // 未完成,在OnFinish时会执行DoDispose
            }
        }
Beispiel #3
0
        public override T Get()
        {
            if (_prefab == null)
            {
                Debuger.LogWarning("No object in pool, you'd better to set a prefab to enable pool instantiate auto.");
                return(base.Get());
            }

            T value;

            if (_stack.Count == 0)
            {
                value = Object.Instantiate(_prefab);
            }
            else
            {
                value = _stack.Pop();
            }

            if (_onGet != null)
            {
                _onGet.Invoke(value);
            }

            return(value);
        }
Beispiel #4
0
 /// <summary>
 /// 强制进行Dispose,无视Ref引用数,建议用在RefCount为1的Loader上
 /// </summary>
 public virtual void ForceDispose()
 {
     if (RefCount != 1)
     {
         Debuger.LogWarning(LOG_TAG, "[ForceDisose]Use force dispose to dispose loader, recommend this loader RefCount == 1");
     }
     Dispose();
 }
Beispiel #5
0
 public static void LogWarn(string msg)
 {
     Debuger.LogWarning(LogTag, msg);
 }
Beispiel #6
0
        IEnumerator Start()
        {
            Object getAsset = null;

#if UNITY_EDITOR
            if (IsEditorLoadAsset)
            {
                getAsset = UnityEditor.AssetDatabase.LoadAssetAtPath <Object>(AssetConfig.GetEditorAssetPathRoot() + AssetPath);
                if (getAsset == null)
                {
                    Debuger.LogError("Asset is NULL(from {0} Folder): {1}", AssetConfig.GetEditorAssetPathRoot(), AssetPath);
                }


                OnFinish(getAsset);
            }
            else
#endif
            if (!IsLoadAssetBundle)
            {
                string extension = Path.GetExtension(AssetPath);
                string path      = AssetPath.Substring(0, AssetPath.Length - extension.Length); // remove extensions

                // 去掉 "GameAssets/"
                if (path.StartsWith(AssetConfig.GameAssetsFolder))
                {
                    path = path.Replace(AssetConfig.GameAssetsFolder, "");
                }

                getAsset = Resources.Load <Object>(path);
                if (getAsset == null)
                {
                    Debuger.LogError("Asset is NULL(from Resources Folder): {0}", path);
                }
                OnFinish(getAsset);
            }
            else
            {
                _bundleLoader = BaseLoader.Load <AssetBundleLoader>(AssetBundlePath, "", loadMode, null);

                while (!_bundleLoader.IsCompleted)
                {
                    if (IsReadyDisposed) // 中途释放
                    {
                        _bundleLoader.Release();
                        OnFinish(null);
                        yield break;
                    }
                    yield return(null);
                }

                if (!_bundleLoader.IsSuccess)
                {
                    Debuger.LogError(LOG_TAG, "Load bundle Failed(Error) when Finished: {0}", AssetBundlePath);
                    _bundleLoader.Release();
                    OnFinish(null);
                    yield break;
                }

                var assetBundle = _bundleLoader.assetBundle;

                var assetName = AssetPath;
                if (!assetBundle.isStreamedSceneAssetBundle)
                {
                    if (loadMode == LoadMode.Sync)
                    {
                        getAsset = assetBundle.LoadAsset(assetName);

                        if (getAsset != null)
                        {
                            _bundleLoader.PushLoadedAsset(assetName, getAsset);
                        }
                    }
                    else
                    {
                        var request = assetBundle.LoadAssetAsync(assetName);
                        while (!request.isDone)
                        {
                            yield return(null);
                        }

                        getAsset = request.asset;

                        if (getAsset != null)
                        {
                            _bundleLoader.PushLoadedAsset(assetName, getAsset);
                        }
                    }
                }
                else
                {
                    // if it's a scene in asset bundle, do nothing
                    // but set a default Object as the result

                    //TODO:
                    Debuger.LogWarning(LOG_TAG, "Can't load any assets from A scene asset bundle");
                    getAsset = null;
                }

                if (getAsset == null)
                {
                    Debuger.LogError(LOG_TAG, "Asset is NULL(From asset bundle): {0}", AssetPath);
                }
            }

            if (Application.isEditor)
            {
                if (getAsset != null)
                {
                    LoadedAssetDebugger.Create(getAsset.GetType().Name, GetUniqueKey(), getAsset);
                }
            }

            OnFinish(getAsset);
        }