Exemplo n.º 1
0
        /// <summary>
        /// 异步从AssetBundle加载资源;
        /// </summary>
        /// <param name="assetType">资源类型</param>
        /// <param name="assetName">资源名字</param>
        /// <param name="progress">加载进度</param>
        /// <param name="isUsePool">资源是否使用对象池</param>
        /// <returns>异步代理</returns>
        public AsyncAssetProxy LoadAssetProxy(AssetType assetType, string assetName, Action <float> progress, bool isUsePool)
        {
            AsyncAssetProxy     proxy    = PoolMgr.Instance.GetCsharpObject <AsyncAssetProxy>();
            AssetBundleLoadNode loadNode = AssetBundleMgr.Instance.GetAssetBundleLoadNode(assetType, assetName);

            loadNode.AddLoadProgressCallBack(progress);
            proxy.InitProxy(assetType, assetName, loadNode, isUsePool);
            _asyncProxyQueue.Enqueue(proxy);
            return(proxy);
        }
Exemplo n.º 2
0
        public AssetBundleLoadNode GetAssetBundleLoadNode(AssetType assetType, string assetName)
        {
            if (assetType == AssetType.Non || string.IsNullOrEmpty(assetName))
            {
                return(null);
            }
            string assetBundlePath = FilePathHelper.GetAssetBundlePath(assetType, assetName);

            if (assetBundlePath == null)
            {
                return(null);
            }
            string assetBundleName = FilePathHelper.GetAssetBundleFileName(assetType, assetName);

            Queue <AssetBundleLoadNode> nodeQueue = null;

            //返回AssetBundleName;
            string[] DependentAssetBundle = Manifest.GetAllDependencies(assetBundleName);
            if (DependentAssetBundle.Length > 0)
            {
                nodeQueue = new Queue <AssetBundleLoadNode>();
            }
            foreach (string tempAssetBundle in DependentAssetBundle)
            {
                if (tempAssetBundle == FilePathHelper.GetAssetBundleFileName(AssetType.Shader, "Shaders"))
                {
                    continue;
                }
                string tempPtah = FilePathHelper.AssetBundlePath + tempAssetBundle;
                AssetBundleLoadNode tempNode = PoolMgr.Instance.GetCsharpObject <AssetBundleLoadNode>();
                tempNode.Init(tempPtah);
                nodeQueue.Enqueue(tempNode);
            }
            AssetBundleLoadNode node = PoolMgr.Instance.GetCsharpObject <AssetBundleLoadNode>();

            node.Init(assetBundlePath, nodeQueue);
            return(node);
        }
Exemplo n.º 3
0
 public void InitProxy(AssetType assetType, string assetName, AssetBundleLoadNode LoadNode
                       , bool isUsePool = true)
 {
     base.InitProxy(assetType, assetName, isUsePool);
     this.LoadNode = LoadNode;
 }
Exemplo n.º 4
0
 protected override void OnReleaseEx()
 {
     base.OnReleaseEx();
     PoolMgr.Instance.ReleaseCsharpObject <AssetBundleLoadNode>(LoadNode);
     LoadNode = null;
 }
Exemplo n.º 5
0
        public void Update()
        {
            switch (_nodeState)
            {
            case AssetBundleNodeState.Non:
                LogHelper.PrintError("[AssetBundleLoadNode]AssetBundleLoadNode is not init!");
                _nodeState = AssetBundleNodeState.Finish;
                break;

            case AssetBundleNodeState.Waitting:
                _nodeState = AssetBundleNodeState.Loading;
                Update();
                break;

            case AssetBundleNodeState.Loading:
                _stopwatch.Reset();
                _stopwatch.Start();
                AssetBundleLoadNode _curNode = null;
                while (true && _dependNodeQueue != null)
                {
                    if (_dependNodeQueue.Count < 1 && null == _curNode)
                    {
                        _stopwatch.Stop();
                        break;
                    }
                    if (_dependNodeQueue.Count > 0)
                    {
                        if (null == _curNode)
                        {
                            _curNode = _dependNodeQueue.Dequeue();
                        }
                    }
                    if (_curNode.NodeState == AssetBundleNodeState.Finish)
                    {
                        PoolMgr.Instance.ReleaseCsharpObject <AssetBundleLoadNode>(_curNode);
                        _curNode = null;
                        _loadCount++;
                        UpdateProgress();
                    }
                    else
                    {
                        _curNode.Update();
                    }
                    if (_stopwatch.Elapsed.Milliseconds >= ResourceMgr.Instance.MAX_LOAD_TIME)
                    {
                        _stopwatch.Stop();
                        return;
                    }
                }
                _stopwatch.Stop();
                assetBundle = AssetBundleMgr.Instance.LoadAssetBundleSync(AssetBundlePath);
                _nodeState  = AssetBundleNodeState.Finish;
                _loadCount++;
                UpdateProgress();
                break;

            case AssetBundleNodeState.Error:
                LogHelper.PrintError(string.Format("[AssetBundleLoadNode]AssetBundleLoadNode load asset:{0} error!"
                                                   , AssetBundlePath));
                _nodeState = AssetBundleNodeState.Finish;
                break;

            case AssetBundleNodeState.Finish:
                break;

            default:
                LogHelper.PrintError("[AssetBundleLoadNode]AssetBundleLoadNode error state!");
                _nodeState = AssetBundleNodeState.Finish;
                break;
            }
            return;
        }