Exemplo n.º 1
0
 protected virtual void Convert(ref DependencyTreeData dpdata, AssetTreeData treeData)
 {
     dpdata.Id          = AssetTreeManager.mIns.GetUniqueId();
     dpdata.FilePath    = treeData.FilePath;
     dpdata.IconName    = treeData.IconName;
     dpdata.EditorInfo  = treeData.EditorInfo;
     dpdata.DisplayName = treeData.DisplayName;
 }
Exemplo n.º 2
0
        //default
        protected virtual void CreateAssetBundleInfo(ref AssetTreeData treeData, string assetpath, string assetbundlename)
        {
            AssetBundleInfo       runtimeInfo     = new AssetBundleInfo();
            EditorAssetBundleInfo assetBundleInfo = new EditorAssetBundleInfo();
            Object unityObject = AssetDatabase.LoadAssetAtPath <Object>(assetpath);

            assetBundleInfo.EditorInstanceId = unityObject.GetInstanceID();
            //assetbundle info

            runtimeInfo.AssetBundleName = assetbundlename;
            runtimeInfo.AssetName       = Path.GetFileNameWithoutExtension(assetpath);
            runtimeInfo.UnityPath       = assetpath;
            runtimeInfo.AssetResType    = AssetBundleFunction.TypeToResType(assetpath);
            //size
            runtimeInfo.AssetSize = Profiler.GetRuntimeMemorySizeLong(unityObject);
            if (runtimeInfo.AssetResType == AssetBundleResType.Image)//editor 下双倍内存
            {
                runtimeInfo.AssetSize /= 2;
            }
            FileInfo fileInfo = new FileInfo(assetpath);

            runtimeInfo.FileSize = fileInfo.Length;

            //dependency
            List <string> collectList = ListPool <string> .Get();

            List <string> editordependList = ListPool <string> .Get();

            GenerateDependencies(collectList, editordependList, unityObject);

            //set dependencies
            runtimeInfo.DependNames         = collectList.ToArray();
            runtimeInfo.DepAssetBundleNames = new string[runtimeInfo.DependNames.Length];
            for (int i = 0; i < runtimeInfo.DependNames.Length; i++)
            {
                var import = AssetImporter.GetAtPath(runtimeInfo.DependNames[i]);
                if (import != null)
                {
                    runtimeInfo.DepAssetBundleNames[i] = import.assetBundleName;
                }
            }

            assetBundleInfo.EditorDependencies = editordependList.ToArray();

            assetBundleInfo.RuntimeInfo = runtimeInfo;
            treeData.EditorInfo         = assetBundleInfo;

            //set icon
            treeData.IconName    = AssetTreeManager.mIns.GetIconName(runtimeInfo.AssetResType);
            treeData.FilePath    = assetpath;
            treeData.DisplayName = Path.GetFileNameWithoutExtension(assetpath);


            ListPool <string> .Release(collectList);

            ListPool <string> .Release(editordependList);
        }
Exemplo n.º 3
0
        AssetTreeData CreateSubAssetBundle(AssetTreeModel <AssetTreeData> dataModel, int parentid, string assetpath, string assetbundlename)
        {
            AssetTreeData data = new AssetTreeData();

            data.Id = AssetTreeManager.mIns.GetUniqueId();

            CreateAssetBundleInfo(ref data, assetpath, assetbundlename);
            dataModel.Add(ref data);
            dataModel.AddChild(parentid, data.Id);
            return(data);
        }
Exemplo n.º 4
0
        AssetTreeData CreateNoAssetBundleNameAsset(string path, string assetbundlename)
        {
            AssetTreeData data = new AssetTreeData();

            data.Id          = AssetTreeManager.mIns.GetUniqueId();
            data.DisplayName = Path.GetFileNameWithoutExtension(path);
            data.FilePath    = path;

            CreateAssetBundleInfo(ref data, path, assetbundlename);
            return(data);
        }
Exemplo n.º 5
0
        AssetTreeData CreateBaseAssetBundle(string[] assetpaths, string assetbundlename, AssetTreeModel <AssetTreeData> dataModel)
        {
            AssetTreeData folderData = new AssetTreeData();

            folderData.Id          = AssetTreeManager.mIns.GetUniqueId();
            folderData.DisplayName = assetbundlename;
            folderData.IconName    = AssetTreeManager.mIns.GetIconName("Folder");
            folderData.FilePath    = Path.GetDirectoryName(assetpaths[0]);

            //set Folder
            var info        = folderData.EditorInfo;
            var runtimeinfo = info.RuntimeInfo;

            runtimeinfo.UnityPath   = folderData.FilePath;
            runtimeinfo.DependNames = assetpaths;

            runtimeinfo.DepAssetBundleNames = new string[assetpaths.Length];
            for (int i = 0; i < assetpaths.Length; i++)
            {
                var import = AssetImporter.GetAtPath(assetpaths[i]);
                if (import != null)
                {
                    runtimeinfo.DepAssetBundleNames[i] = import.assetBundleName;
                }
            }

            //hash
            if (EditorContexts.mIns.SystemContext.Manifests != null)
            {
                AssetBundleBuildInfo buildinfo;
                if (EditorContexts.mIns.SystemContext.Manifests.TryGetValue(assetbundlename, out buildinfo))
                {
                    runtimeinfo.HashCode = buildinfo.AssetBundleHash;
                    runtimeinfo.Crc      = buildinfo.Crc;
                }
            }

            info.RuntimeInfo      = runtimeinfo;
            folderData.EditorInfo = info;

            dataModel.AddChild(dataModel.Root.Id, folderData.Id);
            dataModel.Add(ref folderData);
            return(folderData);
        }
Exemplo n.º 6
0
        bool HasNoAssetBundleName(ref AssetTreeData data)
        {
            bool ret = false;

            if (_model.HasChildren(ref data))
            {
                var children = _model.GetChildren(ref data);

                for (int i = 0; i < children.Count; i++)
                {
                    var child = children[i];
                    if (_model.HasChildren(ref child))
                    {
                        ret = true;
                        break;
                    }
                }

                ListPool <AssetTreeData> .Release(children);
            }
            return(ret);
        }
Exemplo n.º 7
0
        IEnumerator ParseAssetBundle(AssetTreeModel <AssetTreeData> dataModel, Dictionary <string, string[]> assetbundleDictionary, int total)
        {
            //create root
            AssetTreeData rootData = new AssetTreeData();

            rootData.Id    = AssetTreeManager.mIns.GetUniqueId();
            dataModel.Root = rootData;
            dataModel.Add(ref rootData);

            //Editor Ui
            int progress = 0;

            float totalprogress = total + 2;

            yield return(DisplayProgressBar("Asset-Parse AssetBundle", "Start Parseing", 0f));

            foreach (var assetbundleinfo in assetbundleDictionary)
            {
                var assetbundlename = assetbundleinfo.Key;
                var assetpaths      = assetbundleinfo.Value;

                if (assetpaths.Length > 0)
                {
                    AssetTreeData folderData = CreateBaseAssetBundle(assetpaths, assetbundlename, dataModel);
                    folderData.IsAssetBundleViewData = true;

                    foreach (var assetpath in assetpaths)
                    {
                        CreateSubAssetBundle(dataModel, folderData.Id, assetpath, assetbundlename);
                        //Editor Ui
                        progress++;
                        if (progress % AssetWindowConfig.ParseStep == 0)
                        {
                            yield return(DisplayProgressBar("Asset-Parse AssetBundle", "Parseing " + assetpath, progress / totalprogress));
                        }
                    }
                }
            }

            yield return(DisplayProgressBar("Asset-Parse AssetBundle", "Set Dependency", (progress + 1) / totalprogress));

            List <AssetTreeData>  nonamelist = new List <AssetTreeData>();
            Stack <AssetTreeData> itemStack  = StackPool <AssetTreeData> .Get();

            var allTreeDatas = dataModel.GetAllItems();

            //set dependency references
            for (int i = 0; i < allTreeDatas.Count; i++)
            {
                var info = allTreeDatas[i];
                itemStack.Push(info);
                //SetAssetDependRef(ref info,dataModel,nonamelist);
            }

            ListPool <AssetTreeData> .Release(allTreeDatas);

            yield return(SetAssetDependRef(itemStack, dataModel, nonamelist));

            StackPool <AssetTreeData> .Release(itemStack);

            yield return(DisplayProgressBar("Asset-Parse AssetBundle", "Assigning NoAssetName", 1f));

            for (int i = 0; i < nonamelist.Count; i++)
            {
                var nonameitem = nonamelist[i];

                var deplist = dataModel.GetDependParents(nonameitem.FilePath);
                for (int j = 0; j < deplist.Count; j++)
                {
                    var dep = deplist[j];
                    if (j == 0)
                    {
                        dataModel.AddChild(dep.Id, nonameitem.Id);
                    }
                    else
                    {
                        nonameitem.Id = AssetTreeManager.mIns.GetUniqueId();
                        dataModel.Add(ref nonameitem);
                        //dataModel.AddViewData(ref nonameitem);
                        dataModel.AddChild(dep.Id, nonameitem.Id);
                    }
                }
            }

            yield return(null);

            EditorUtility.ClearProgressBar();
        }
Exemplo n.º 8
0
        IEnumerator ParseSelect(AssetTreeModel <DependencyTreeData> datamodel, AssetTreeModel <AssetTreeData> treemodel, AssetTreeData data)
        {
#if !UNITY_EDITOR_OSX
            yield return(DisplayProgressBar("Dependency-Parse", "Parse Dependency for :" + data.FilePath, 0f));
#endif

            DependencyTreeData root = new DependencyTreeData();
            root.Id          = AssetTreeManager.mIns.GetUniqueId();
            root.DisplayName = "root";

            //empty;
            datamodel.Root = root;
            datamodel.Add(ref root);

            _progress = 0;
            if (EditorContexts.mIns.GuiContext.SelectDepth == 0)
            {
                foreach (var dependency in data.EditorInfo.Dependencies)
                {
                    DependencyTreeData depdata = new DependencyTreeData();
                    depdata.Id = AssetTreeManager.mIns.GetUniqueId();
                    depdata.IsAssetBundleViewData = true;
                    CreateDependencyInfo(ref depdata, dependency);


                    datamodel.Add(ref depdata);
                    yield return(CreateDepParent(datamodel, treemodel, depdata.FilePath, depdata.Id));

                    datamodel.AddChild(ref root, ref depdata);
                }
            }
            else
            {
                yield return(CreateDepParent(datamodel, treemodel, data.FilePath, root.Id));
            }

            yield return(null);

            Inited = true;
            EditorUtility.ClearProgressBar();
        }
Exemplo n.º 9
0
        public bool Write(string filepath)
        {
            try
            {
                var dirname = Path.GetDirectoryName(filepath);
                if (Directory.Exists(dirname) == false)
                {
                    Directory.CreateDirectory(dirname);
                }

                using (var fs = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    //clear
                    fs.SetLength(0);
                    var datamodel = AssetTreeManager.mIns.GetModel <AssetTreeData>();
                    var allitems  = datamodel.GetAllItems();
                    using (var ms = new MemoryStream())
                    {
                        using (var bs = new BinaryWriter(ms))
                        {
                            bs.Write(AssetBundleConfig.Version);

                            List <AssetTreeData> tempList = new List <AssetTreeData>();
                            for (int i = 0; i < allitems.Count; i++)
                            {
                                AssetTreeData item = allitems[i];
                                if (File.Exists(item.FilePath))
                                {
                                    var existindex = tempList.FindIndex(it => it.FilePath.Equals(item.FilePath));
                                    if (existindex == -1)
                                    {
                                        tempList.Add(item);
                                    }
                                }
                            }

                            bs.Write(tempList.Count);
                            for (int i = 0; i < tempList.Count; i++)
                            {
                                AssetTreeData item = tempList[i];
                                var           data = item.EditorInfo.RuntimeInfo;
                                string        hash = null;
                                uint          crc  = 0;

                                var parent = datamodel.GetParent(ref item);
                                if (parent.Count > 0)
                                {
                                    hash = parent[0].EditorInfo.RuntimeInfo.HashCode;
                                    crc  = parent[0].EditorInfo.RuntimeInfo.Crc;
                                }
                                ListPool <AssetTreeData> .Release(parent);

                                //
                                bs.Write(hash ?? "");
                                bs.Write(crc);
                                bs.Write(data.AssetName);
                                bs.Write(data.UnityPath ?? "");
                                bs.Write(data.AssetBundleName ?? "");
                                bs.Write(data.AssetSize);
                                bs.Write(data.FileSize);
                                bs.Write((int)data.AssetResType);

                                WriteArray(bs, data.DependNames);
                                WriteArray(bs, data.DepAssetBundleNames);
                            }

                            ms.WriteTo(fs);
                            bs.Close();
                        }

                        ms.Close();
                        fs.Flush();
                        fs.Close();
                    }

                    ListPool <AssetTreeData> .Release(allitems);
                }

                return(true);
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                return(false);
            }
        }