Esempio n. 1
0
        IEnumerator SetAssetDependRef(Stack <AssetTreeData> stack, AssetTreeModel <AssetTreeData> dataModel, List <AssetTreeData> nonamelist)
        {
            while (stack.Count > 0)
            {
                var info = stack.Pop();

                yield return(DisplayProgressBar("Asset-Parse AssetBundle", "Set Dependency :" + info.DisplayName, 1f / (stack.Count + 1)));

                if (info.EditorInfo.RuntimeInfo.DependNames != null)
                {
                    List <AssetBundleInfo> infoList = ListPool <AssetBundleInfo> .Get();

                    for (int j = 0; j < info.EditorInfo.RuntimeInfo.DependNames.Length; j++)
                    {
                        string path = info.EditorInfo.RuntimeInfo.DependNames[j];

                        AssetTreeData assetdata;
                        if (dataModel.GetItem(path, out assetdata))
                        {
                            infoList.Add(assetdata.EditorInfo.RuntimeInfo);
                        }
                        else
                        {
                            AssetImporter importer = AssetImporter.GetAtPath(path);
                            if (importer != null && !string.IsNullOrEmpty(importer.assetBundleName))
                            {
                                AssetTreeData folderData;
                                if (!dataModel.GetItemByAssetBundleName(importer.assetBundleName, out folderData))
                                {
                                    string[] paths = AssetDatabase.GetAssetPathsFromAssetBundle(importer.assetBundleName);
                                    folderData = CreateBaseAssetBundle(paths, importer.assetBundleName, dataModel);

                                    foreach (var assetpath in paths)
                                    {
                                        var itemdata = CreateSubAssetBundle(dataModel, folderData.Id, assetpath, importer.assetBundleName);
                                        stack.Push(itemdata);
                                    }
                                }
                                infoList.Add(folderData.EditorInfo.RuntimeInfo);
                            }
                            else
                            {
                                bool needcreate = !IsResourceRes(path);
                                if (needcreate && path.EndsWith(".shader", StringComparison.OrdinalIgnoreCase))
                                {
                                    Shader shader = AssetDatabase.LoadAssetAtPath <Shader>(path);
                                    if (shader != null)
                                    {
                                        for (int i = 0; i < _alwayShaders.Count; i++)
                                        {
                                            var includeshader = _alwayShaders[i];
                                            if (includeshader != null && includeshader.name.Equals(shader.name))
                                            {
                                                needcreate = false;
                                                break;
                                            }
                                        }
                                    }
                                }

                                if (needcreate)
                                {
                                    Debug.LogWarningFormat("not found assetbundleInfo :{0}", path);

                                    //will pack into assetbundle
                                    assetdata = CreateNoAssetBundleNameAsset(path, info.EditorInfo.RuntimeInfo.AssetBundleName);
                                    dataModel.Add(ref assetdata);
                                    nonamelist.Add(assetdata);
                                    infoList.Add(assetdata.EditorInfo.RuntimeInfo);
                                }
                            }
                        }
                    }

                    //assign
                    var editordata = info.EditorInfo;

                    editordata.Dependencies = infoList.ToArray();

                    info.EditorInfo = editordata;

                    dataModel.Add(ref info);
                    ListPool <AssetBundleInfo> .Release(infoList);
                }
            }
        }