Example #1
0
        IEnumerator CollectAtlasInfo(AssetTreeModel <SpriteTrackData> dataModel, Dictionary <Sprite, HashSet <Object> > allUsed, Dictionary <Sprite, SimpleSpriteInfo> sprCache)
        {
            var displayRoot = CreateDisplayRoot("Atlas");

            displayRoot.ShowMode = SpriteShowMode.Atlas;
            dataModel.Add(ref displayRoot);
            dataModel.AddChild(dataModel.Root.Id, displayRoot.Id);

            Dictionary <string, Dictionary <Sprite, HashSet <Object> > > dict = GetAtlasInfo(allUsed, sprCache);

            int i = 0;

            foreach (var pair in dict)
            {
                SpriteTrackData sprData = new SpriteTrackData();
                sprData.ShowMode    = SpriteShowMode.Atlas;
                sprData.Id          = AssetTreeManager.mIns.GetUniqueId();
                sprData.DisplayName = pair.Key;
                sprData.IconName    = AssetTreeManager.mIns.GetIconName(AssetBundleResType.Image);

                dataModel.Add(ref sprData);
                dataModel.AddChild(ref displayRoot, ref sprData);


                BuildAtlasSprData(dataModel, pair.Value, sprCache, ref sprData);

                yield return(DisplayProgressBar("Parse Atlas", "Parsing " + pair.Key, (float)i / dict.Count));

                i++;
            }
        }
        public void Init()
        {
            if (_searchField == null)
            {
                _searchField = new SearchField();
            }
            if (_treeViewState == null)
            {
                _treeViewState = new TreeViewState();
            }

            //create Head
            RefreshHead();

            //tree view
            if (_treeView == null)
            {
                _treeView = new AssetTreeView <SpriteTrackData>(_treeViewState, _columnHeader, AssetWindow.WindowMode.ToolsSprite);
            }
            else
            {
                _columnHeader.Repaint();
                _treeView.Repaint();
            }

            //search field
            _searchField.downOrUpArrowKeyPressed -= PressSearch;
            _searchField.downOrUpArrowKeyPressed += PressSearch;

            _model = AssetTreeManager.mIns.GetModel <SpriteTrackData>();
        }
 public AssetTreeView(TreeViewState state, MultiColumnHeader header, AssetWindow.WindowMode md) : base(state, header)
 {
     header.sortingChanged += OnSortingChanged;
     _viewMode              = md;
     _model = AssetTreeManager.mIns.GetModel <T>();
     //Reload();
 }
Example #4
0
        void BuildAtlasSprData(AssetTreeModel <SpriteTrackData> dataModel, Dictionary <Sprite, HashSet <Object> > dict, Dictionary <Sprite, SimpleSpriteInfo> sprCache, ref SpriteTrackData displayRoot)
        {
            foreach (var pair in dict)
            {
                SpriteTrackData rootData = new SpriteTrackData();
                rootData.ShowMode    = SpriteShowMode.Atlas;
                rootData.Id          = AssetTreeManager.mIns.GetUniqueId();
                rootData.IconName    = AssetTreeManager.mIns.GetIconName(AssetBundleResType.Sprite);
                rootData.DisplayName = pair.Key.name;
                rootData.AtlasData.RefData.Target     = pair.Key;
                rootData.AtlasData.RefData.InstanceId = pair.Key.GetInstanceID();

                rootData.AtlasData.SprData = GetSpriteData(sprCache, pair.Key);

                dataModel.Add(ref rootData);

                foreach (var refTarget in pair.Value)
                {
                    SpriteTrackData refData = BuildData(pair.Key, refTarget, SpriteShowMode.Atlas, sprCache);
                    dataModel.Add(ref refData);
                    dataModel.AddChild(ref rootData, ref refData);
                }

                dataModel.AddChild(ref displayRoot, ref rootData);
            }
        }
Example #5
0
        IEnumerator CollectPrefabsInfo(AssetTreeModel <SpriteTrackData> dataModel, Dictionary <Sprite, HashSet <Object> > allUsed, Dictionary <Sprite, SimpleSpriteInfo> sprCache)
        {
            var displayRoot = CreateDisplayRoot("Prefabs");

            displayRoot.ShowMode = SpriteShowMode.Prefabs;
            dataModel.Add(ref displayRoot);
            dataModel.AddChild(dataModel.Root.Id, displayRoot.Id);
            yield return(DisplayProgressBar("Parse Prefab", "Start Parse ", 0));

            if (EditorContexts.mIns.GuiContext.SelectPaths != null && EditorContexts.mIns.GuiContext.SelectPaths.Count > 0)
            {
                List <string> selects = ListPool <string> .Get();

                foreach (var pair in EditorContexts.mIns.GuiContext.SelectPaths)
                {
                    if (pair.Value)
                    {
                        selects.Add(pair.Key);
                    }
                }

                if (selects.Count == 0)
                {
                    ListPool <string> .Release(selects);
                }
                else
                {
                    string[] guids = AssetDatabase.FindAssets("t:GameObject", selects.ToArray());
                    ListPool <string> .Release(selects);

                    yield return(DisplayProgressBar("Parse Prefab", "Start Parse Select Path", 0.05f));

                    HashSet <string> pathHashSet = new HashSet <string>();

                    for (int i = 0; i < guids.Length; i++)
                    {
                        string assetpath = AssetDatabase.GUIDToAssetPath(guids[i]);
                        pathHashSet.Add(assetpath);
                        yield return(DisplayProgressBar("Parse Prefab", "Add Path " + assetpath, (float)i / guids.Length));
                    }

                    int m = 0;
                    foreach (var assetpath in pathHashSet)
                    {
                        SpriteTrackData sprData = BuildGoData(dataModel, allUsed, sprCache, assetpath);

                        dataModel.Add(ref sprData);
                        dataModel.AddChild(ref displayRoot, ref sprData);

                        yield return(DisplayProgressBar("Parse Prefab", "Parse " + assetpath, (float)m / guids.Length));

                        m++;
                    }
                }
            }
        }
Example #6
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);
        }
        public AssetTreeModel <T> GetModel <T>() where T : ITreeData
        {
            ITreeModel model;

            if (_modelDictionary.TryGetValue(typeof(T), out model))
            {
                return((AssetTreeModel <T>)model);
            }
            model = new AssetTreeModel <T>();
            _modelDictionary.Add(typeof(T), model);
            return((AssetTreeModel <T>)model);
        }
        void TryAddChildren(AssetTreeItem <T> rootitem, List <TreeViewItem> list, AssetTreeModel <T> model, int depth)
        {
            if (model.HasChildren(rootitem.DataId))
            {
                List <T> children = model.GetChildren(rootitem.DataId);
                Stack <AssetTreeItem <T> > stack = StackPool <AssetTreeItem <T> > .Get();

                for (int i = children.Count - 1; i >= 0; i--)
                {
                    var child = children[i];

                    //create item
                    var childItem = CreateItem(ref child, depth + 1);
                    stack.Push(childItem);
                }

                ListPool <T> .Release(children);

                while (stack.Count > 0)
                {
                    var stackChild = stack.Pop();
                    list.Add(stackChild);
                    if (model.HasChildren(stackChild.DataId))
                    {
                        if (IsExpanded(stackChild.id))
                        {
                            children = model.GetChildren(stackChild.DataId);
                            //
                            //stackChild.children = new List<TreeViewItem>();
                            for (int i = children.Count - 1; i >= 0; i--)
                            {
                                var child = children[i];

                                //create item
                                var childItem = CreateItem(ref child, stackChild.depth + 1);
                                stack.Push(childItem);
                                //stackChild.children.Add(childItem);
                            }

                            ListPool <T> .Release(children);
                        }
                        else
                        {
                            stackChild.children = CreateChildListForCollapsedParent();
                        }
                    }
                }

                StackPool <AssetTreeItem <T> > .Release(stack);
            }
        }
Example #9
0
        public void Init()
        {
            if (_treeViewState == null)
            {
                _treeViewState = new TreeViewState();
            }

            //create Head
            RefreshHead();

            //tree view
            if (_treeView == null)
            {
                _treeView = new AssetTreeView <DependencyTreeData>(_treeViewState, _columnHeader, AssetWindow.WindowMode.AssetDependency);
            }

            _model = AssetTreeManager.mIns.GetModel <DependencyTreeData>();
        }
        IEnumerator CreateDepParent(AssetTreeModel <DependencyTreeData> datamodel, AssetTreeModel <AssetTreeData> treemodel, string filepath, int parentId)
        {
            var dependonlist = treemodel.GetDependParents(filepath);

            foreach (var element in dependonlist)
            {
                DependencyTreeData subdata = new DependencyTreeData();
                Convert(ref subdata, element);
                datamodel.Add(ref subdata);

                datamodel.AddChild(parentId, subdata.Id);
                _progress++;
                if (_progress % AssetWindowConfig.ParseStep == 0)
                {
#if !UNITY_EDITOR_OSX
                    yield return(DisplayProgressBar("Dependency-Parse", "Parse Dependency for :" + element.FilePath, 0));
#endif
                }
            }
        }
        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();
        }
        void SearchItem(List <TreeViewItem> list, AssetTreeModel <T> model, int itemid)
        {
            if (list != null && model != null && model.HasChildren(itemid))
            {
                List <T>  children = model.GetChildren(itemid);
                Stack <T> stack    = StackPool <T> .Get();

                for (int i = children.Count - 1; i >= 0; i--)
                {
                    stack.Push(children[i]);
                }

                ListPool <T> .Release(children);

                while (stack.Count > 0)
                {
                    T current = stack.Pop();

                    if (!string.IsNullOrEmpty(current.DisplayName) && current.DisplayName.IndexOf(searchString, StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        //Add result
                        var viewitem = CreateItem(ref current, 0);
                        list.Add(viewitem);
                    }

                    if (model.HasChildren(current.Id))
                    {
                        children = model.GetChildren(current.Id);
                        for (int i = children.Count - 1; i >= 0; i--)
                        {
                            stack.Push(children[i]);
                        }

                        ListPool <T> .Release(children);
                    }
                }

                StackPool <T> .Release(stack);
            }
        }
Example #13
0
        public static long GetSelfAssetSize <T>(ref T data, bool isroot, AssetTreeModel <T> datamodel) where T : ITreeData
        {
            long size = 0;

            if (isroot)
            {
                if (datamodel.HasChildren(ref data))
                {
                    var children = datamodel.GetChildren(ref data);
                    for (int i = 0; i < children.Count; i++)
                    {
                        size += children[i].EditorInfo.RuntimeInfo.AssetSize;
                    }

                    ListPool <T> .Release(children);
                }
            }
            else
            {
                size = data.EditorInfo.RuntimeInfo.AssetSize;
            }
            return(size);
        }
Example #14
0
        IEnumerator AddProfilerData(AssetTreeModel <RuntimeProfilerData> datamodel, FrameProfilerData data, RuntimeProfilerData taskroot, RuntimeProfilerData bundleroot)
        {
            int step = 5;

            if (data.Tasks != null)
            {
                for (int i = 0; i < data.Tasks.Count; i++)
                {
                    var task = data.Tasks[i];

                    RuntimeProfilerData folderdata = new RuntimeProfilerData();
                    folderdata.Id          = AssetTreeManager.mIns.GetUniqueId();
                    folderdata.DisplayName = Path.GetFileNameWithoutExtension(task.AssetPath);
                    folderdata.IconName    = AssetTreeManager.mIns.GetIconName("Folder");
                    folderdata.Task        = task;

                    datamodel.Add(ref folderdata);
                    datamodel.AddChild(ref taskroot, ref folderdata);

                    if (i % step == 0)
                    {
                        yield return(null);
                    }
                }
            }


            if (data.Histories != null)
            {
                for (int i = 0; i < data.Histories.Count; i++)
                {
                    var history = data.Histories[i];

                    RuntimeProfilerData folderdata = new RuntimeProfilerData();
                    folderdata.Id          = AssetTreeManager.mIns.GetUniqueId();
                    folderdata.DisplayName = history.AssetBundlename;
                    folderdata.IconName    = AssetTreeManager.mIns.GetIconName("Folder");
                    folderdata.History     = history;

                    datamodel.Add(ref folderdata);
                    datamodel.AddChild(ref bundleroot, ref folderdata);

                    if (history.AssetsList != null)
                    {
                        foreach (var sub in history.AssetsList)
                        {
                            RuntimeProfilerData subdata = new RuntimeProfilerData();
                            subdata.Id          = AssetTreeManager.mIns.GetUniqueId();
                            subdata.DisplayName = Path.GetFileNameWithoutExtension(sub.Path);
                            subdata.IconName    = AssetTreeManager.mIns.GetIconName("GameObject");
                            subdata.AssetInfo   = sub;

                            datamodel.Add(ref subdata);
                            datamodel.AddChild(ref folderdata, ref subdata);
                        }
                    }

                    if (i % step == 0)
                    {
                        yield return(null);
                    }
                }
            }

            yield return(null);
        }
Example #15
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);
        }
Example #16
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);
                }
            }
        }
Example #17
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();
        }
Example #18
0
        IEnumerator CollectSceneInfo(AssetTreeModel <SpriteTrackData> dataModel, Dictionary <Sprite, HashSet <Object> > allUsed, Dictionary <Sprite, SimpleSpriteInfo> sprCache)
        {
            var displayRoot = CreateDisplayRoot("Scene");

            displayRoot.ShowMode = SpriteShowMode.Scene;
            dataModel.Add(ref displayRoot);
            dataModel.AddChild(dataModel.Root.Id, displayRoot.Id);

            var allScripts = GameObject.FindObjectsOfType <MonoBehaviour>();

            Dictionary <Sprite, HashSet <Object> > allRecords = new Dictionary <Sprite, HashSet <Object> >();

            int i = 0;

            foreach (MonoBehaviour script in allScripts)
            {
                CollectSprite(script, allRecords);

                yield return(DisplayProgressBar("Parse Scene", "Parsing script " + script.name, (float)i / allScripts.Length));

                i++;
            }

            foreach (var pair in allRecords)
            {
                allUsed[pair.Key] = pair.Value;//new HashSet<Object>(pair.Value);
            }

            i = 0;

            Dictionary <Object, List <Sprite> > sprRefDictionary = Convert(allRecords);

            foreach (var pair in sprRefDictionary)
            {
                SpriteTrackData sprData = new SpriteTrackData();
                sprData.ShowMode               = SpriteShowMode.Scene;
                sprData.Id                     = AssetTreeManager.mIns.GetUniqueId();
                sprData.DisplayName            = pair.Key.name;
                sprData.IconName               = AssetTreeManager.mIns.GetIconName(AssetBundleResType.Cs);
                sprData.SceneData.CsReferences = pair.Key as MonoBehaviour;
                sprData.SceneData.InstanceId   = pair.Key.GetInstanceID();
                sprData.SceneData.MemSize      = AssetBundleEditorHelper.ConvertSize(Profiler.GetRuntimeMemorySizeLong(pair.Key));


                if (sprData.SceneData.CsReferences)
                {
                    sprData.SceneData.Path = GetPath(sprData.SceneData.CsReferences.gameObject);
                }

                dataModel.Add(ref sprData);

                HashSet <string> hashset = HashSetPool <string> .Get();

                foreach (var refsprite in pair.Value)
                {
                    SpriteTrackData refData = BuildData(refsprite, pair.Key, SpriteShowMode.Scene, sprCache);
                    refData.UsedRefCount = 1;

                    dataModel.Add(ref refData);
                    dataModel.AddChild(ref sprData, ref refData);

                    hashset.Add(refData.SceneData.SprData.PackingTag);
                }

                sprData.UsedRefCount = hashset.Count;
                //refresh
                dataModel.Add(ref sprData);

                HashSetPool <string> .Release(hashset);

                dataModel.AddChild(ref displayRoot, ref sprData);

                yield return(DisplayProgressBar("Parse Scene", "Parsing  Sprite", (float)i / sprRefDictionary.Count));

                i++;
            }
        }
Example #19
0
        SpriteTrackData BuildGoData(AssetTreeModel <SpriteTrackData> dataModel, Dictionary <Sprite, HashSet <Object> > allUsed, Dictionary <Sprite, SimpleSpriteInfo> sprCache, string assetpath)
        {
            GameObject gameObject = AssetDatabase.LoadAssetAtPath <GameObject>(assetpath);

            if (gameObject)
            {
                HashSet <string> allHashSet = HashSetPool <string> .Get();

                SpriteTrackData data = new SpriteTrackData();
                data.ShowMode    = SpriteShowMode.Prefabs;
                data.Id          = AssetTreeManager.mIns.GetUniqueId();
                data.IconName    = AssetTreeManager.mIns.GetIconName(AssetBundleResType.GameObject);
                data.DisplayName = Path.GetFileNameWithoutExtension(assetpath);

                data.GameObjectData.GoData = GetGoData(gameObject);

                string        bundleName = "";
                AssetImporter importer   = AssetImporter.GetAtPath(assetpath);
                if (importer)
                {
                    bundleName = importer.assetBundleName;
                }

                data.GameObjectData.SprData.BundleName = bundleName;
                data.GameObjectData.SprData.AssetPath  = assetpath;

                var allScripts = gameObject.GetComponentsInChildren <MonoBehaviour>(true);
                Dictionary <Sprite, HashSet <Object> > allRecords = new Dictionary <Sprite, HashSet <Object> >();

                foreach (MonoBehaviour script in allScripts)
                {
                    CollectSprite(script, allRecords);
                }

                foreach (var pair in allRecords)
                {
                    HashSet <Object> hashset;
                    if (allUsed.TryGetValue(pair.Key, out hashset))
                    {
                        foreach (var subdata in pair.Value)
                        {
                            hashset.Add(subdata);
                        }
                    }
                    else
                    {
                        allUsed[pair.Key] = pair.Value;//new HashSet<Object>(pair.Value);
                    }
                }

                HashSet <string> atlasHashset = HashSetPool <string> .Get();

                Dictionary <Object, List <Sprite> > sprRefDictionary = Convert(allRecords);
                foreach (var pair in sprRefDictionary)
                {
                    atlasHashset.Clear();

                    SpriteTrackData sprData = new SpriteTrackData();
                    sprData.ShowMode                          = SpriteShowMode.Prefabs;
                    sprData.Id                                = AssetTreeManager.mIns.GetUniqueId();
                    sprData.DisplayName                       = MonoScript.FromMonoBehaviour(pair.Key as MonoBehaviour).name;
                    sprData.IconName                          = AssetTreeManager.mIns.GetIconName(AssetBundleResType.Cs);
                    sprData.GameObjectData.GoData             = GetGoData(pair.Key);
                    sprData.GameObjectData.SprData.BundleName = bundleName;
                    sprData.GameObjectData.SprData.AssetPath  = AssetDatabase.GetAssetPath(pair.Key);

                    dataModel.Add(ref sprData);

                    foreach (var refsprite in pair.Value)
                    {
                        SpriteTrackData refData = BuildData(refsprite, pair.Key, SpriteShowMode.Prefabs, sprCache);
                        refData.UsedRefCount = 1;

                        dataModel.Add(ref refData);
                        dataModel.AddChild(ref sprData, ref refData);

                        atlasHashset.Add(refData.GameObjectData.SprData.PackingTag);
                        allHashSet.Add(refData.GameObjectData.SprData.PackingTag);
                    }

                    sprData.UsedRefCount = atlasHashset.Count;
                    //refresh
                    dataModel.Add(ref sprData);
                    //
                    dataModel.AddChild(ref data, ref sprData);
                }

                data.UsedRefCount = allHashSet.Count;
                //refresh
                dataModel.Add(ref data);

                HashSetPool <string> .Release(atlasHashset);

                HashSetPool <string> .Release(allHashSet);

                return(data);
            }
            else
            {
                SpriteTrackData data = new SpriteTrackData();
                data.ShowMode    = SpriteShowMode.Prefabs;
                data.Id          = AssetTreeManager.mIns.GetUniqueId();
                data.IconName    = AssetTreeManager.mIns.GetIconName(AssetBundleResType.Prefab);
                data.DisplayName = "Load Failed";

                return(data);
            }
        }