Пример #1
0
    public void LoadAssetAsync <T>(AssetLoaderRequest request) where T : Object
    {
        string assetBundlePath = RemoveSuffix(request.AssetPath);
        string assetBundleName = GetAssetBundleNameByAssetMaps(assetBundlePath);

        AssetBundleInfo abInfo = null;

        if (_asset_bundles.TryGetValue(assetBundleName, out abInfo))
        {
            if (abInfo.IsLoader)
            {
                abInfo.AsyncLoadAsset <T>(request.AssetPath, request);
            }
            else
            {
                AssetBundleLoaderRequest abRequest = AssetBundleLoaderRequest.New(assetBundlePath);
                abRequest.OnCompleted += (rt) =>
                {
                    rt.AsyncLoadAsset <T>(request.AssetPath, request);
                };

                InternalLoadAssetBundleAsync(abInfo, abRequest);
            }
        }
    }
Пример #2
0
    public void AsynLoadFromFile(
        AssetBundleLoaderRequest async,
        System.Action <AssetBundleInfo> loaderDependency = null)
    {
        if (_is_loader)
        {
            return;
        }

        string fileName = BuildFileName();
        AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(fileName);

        async.Setup(request, this);
        request.completed += (rt) =>
        {
            _bundle = request.assetBundle;
            if (loaderDependency != null)
            {
                loaderDependency(this);
            }
            if (async.OnCompleted != null)
            {
                async.OnCompleted(this);
            }
        };
        _is_loader = true;
    }
Пример #3
0
    public void LoadAssetBundleAsync(AssetBundleLoaderRequest request)
    {
        string assetBundleName = GetAssetBundleNameByAssetMaps(request.AssetPath);

        AssetBundleInfo abInfo = null;

        if (_asset_bundles.TryGetValue(assetBundleName, out abInfo))
        {
            if (abInfo.IsLoader)
            {
                return;
            }
            InternalLoadAssetBundleAsync(abInfo, request);
        }
    }
Пример #4
0
    IEnumerator LoadDependency(string assetBundleName, AssetBundleLoad load)
    {
        List <string> dependencys = load.GetDependencys(assetBundleName);

        if (dependencys == null)
        {
            yield break;
        }
        for (int i = 0; i < dependencys.Count; i++)
        {
            AssetBundleLoaderRequest request = AssetBundleLoaderRequest.New(dependencys[i]);
            load.LoadAssetBundleAsync(request);
            while (!request.IsDone)
            {
                yield return(null);
            }
            UpdateProgress();
        }
    }
Пример #5
0
    void InternalLoadAssetBundleAsync(
        AssetBundleInfo abInfo, AssetBundleLoaderRequest request)
    {
        abInfo.AsynLoadFromFile(request, (mainAB) =>
        {
            _is_current_loader.Add(abInfo);

            List <string> dependencys = _dependency.GetDependency(mainAB.GetAssetBundleName());
            for (int i = 0; i < dependencys.Count; i++)
            {
                AssetBundleLoaderRequest deRequest = AssetBundleLoaderRequest.New(dependencys[i]);
                LoadAssetBundleAsync(deRequest);

                deRequest.OnCompleted = (ab) =>
                {
                    ab.AddReferenceCount();
                };
            }
        });
    }
Пример #6
0
    public void LoadAssetAsyncByName <T>(AssetAllLoaderRequest request) where T : Object
    {
        AssetBundleInfo abInfo = null;

        if (_asset_bundles.TryGetValue(request.AssetBundleName, out abInfo))
        {
            if (abInfo.IsLoader)
            {
                abInfo.AsyncLoadAllAssets <T>(request);
            }
            else
            {
                AssetBundleLoaderRequest abRequest =
                    AssetBundleLoaderRequest.New(request.AssetBundleName);
                abRequest.OnCompleted += (rt) =>
                {
                    abInfo.AsyncLoadAllAssets <T>(request);
                };
                InternalLoadAssetBundleAsync(abInfo, abRequest);
            }
        }
    }
Пример #7
0
    public IEnumerator StartLoadSceneAsync(AssetBundleLoad load)
    {
        if (!_uninstallable_scene.ContainsKey(_scene_name))
        {
            _uninstallable_scene.Add(_scene_name, false);
        }

        _current    = 0;
        _totalCount = 2;  //最少有2个,一个ab,一个场景加载

        CalculationDependencyCount(_asset_bundle_name, load);

        TextAsset xmlInfo = load.LoadAsset <TextAsset>(_xml_asset_bundle_name);

        Dictionary <XmlNode, XmlNodeList> sceneObjects = GetSceneObjects(xmlInfo);

        AssetBundleLoaderRequest abRequest = AssetBundleLoaderRequest.New(_asset_bundle_name);

        load.LoadSingleAssetBundleAsync(abRequest);
        while (!abRequest.IsDone)
        {
            yield return(null);
        }

        UpdateProgress();

        // 加载场景依赖项
        yield return(LoadDependency(_asset_bundle_name, load));

        yield return(SceneManager.LoadSceneAsync(_scene_name, _load_mode));

        UpdateProgress();

        // 复位Object对象
        if (sceneObjects != null)
        {
            var itr = sceneObjects.Keys.GetEnumerator();
            while (itr.MoveNext())  // 遍历Object的节点
            {
                XmlElement objectNode = itr.Current as XmlElement;
                string     objectPath = objectNode.GetAttribute("Path");
                string     objectName = objectNode.GetAttribute("Name");

                AssetLoaderRequest request = AssetLoaderRequest.New(objectPath);
                load.LoadAssetAsync <Object>(request);

                while (!request.IsDone)
                {
                    yield return(null);
                }
                UpdateProgress();

                GameObject gameObject = (GameObject)GameObject.Instantiate(request.asset);
                gameObject.name = objectName;

                foreach (XmlElement el in objectNode.ChildNodes)
                {
                    float x = float.Parse(el.GetAttribute("X"));
                    float y = float.Parse(el.GetAttribute("Y"));
                    float z = float.Parse(el.GetAttribute("Z"));

                    if (el.Name.Equals("Position"))
                    {
                        gameObject.transform.position = new Vector3(x, y, z);
                    }
                    else if (el.Name.Equals("Rotate"))
                    {
                        gameObject.transform.eulerAngles = new Vector3(x, y, z);
                    }
                    else if (el.Name.Equals("Scale"))
                    {
                        gameObject.transform.localScale = new Vector3(x, y, z);
                    }
                }
            }

            itr.Dispose();
        }

        UpdateProgress();
        IsDone = true;
        if (loadCompleted != null)
        {
            loadCompleted(this);
        }

        _uninstallable_scene[_scene_name] = true;
    }