Exemplo n.º 1
0
        private FavouritesAsset LoadAsset()
        {
            string[] guids = AssetDatabase.FindAssets("t:FavouritesAsset");
            string   fn    = (guids.Length > 0 ? AssetDatabase.GUIDToAssetPath(guids[0]) : GetPackageFolder() + "FavouritesAsset.asset");

            asset = AssetDatabase.LoadAssetAtPath <FavouritesAsset>(fn);
            if (asset == null)
            {
                asset = CreateInstance <FavouritesAsset>();
                AssetDatabase.CreateAsset(asset, fn);
                AssetDatabase.SaveAssets();
            }

            return(asset);
        }
Exemplo n.º 2
0
        public void LoadAndUpdate(FavouritesAsset favsAsset = null)
        {
            if (favsAsset != null)
            {
                asset = favsAsset;
            }

            // add root
            FavouritesTreeElement treeRoot = new FavouritesTreeElement()
            {
                ID = 0, Depth = -1, Name = "Root"
            };

            model = new TreeModel <FavouritesTreeElement>(new List <FavouritesTreeElement>()
            {
                treeRoot
            });

            // add categories
            List <FavouritesTreeElement> categories = new List <FavouritesTreeElement>();
            Texture2D icon = EditorGUIUtility.IconContent(FolderIconName()).image as Texture2D;

            foreach (FavouritesCategory c in asset.categories)
            {
                FavouritesTreeElement ele = new FavouritesTreeElement()
                {
                    Name     = c.name,
                    Icon     = icon,
                    ID       = model.GenerateUniqueID(),
                    category = c
                };

                categories.Add(ele);
                model.QuickAddElement(ele, treeRoot);
            }

            // add favourites from project and scene(s)
            List <FavouritesElement> favs = new List <FavouritesElement>();

            favs.AddRange(asset.favs);

            // add from scene(s)
            foreach (FavouritesContainer c in FavouritesEd.Containers)
            {
                if (c == null || c.favs == null)
                {
                    continue;
                }
                favs.AddRange(c.favs);
            }

            // sort
            favs.Sort((a, b) =>
            {
                int r = a.categoryId.CompareTo(b.categoryId);
                if (r == 0 && a.obj != null && b.obj != null)
                {
                    r = a.obj.name.CompareTo(b.obj.name);
                }
                return(r);
            });

            // and add to tree
            foreach (FavouritesElement ele in favs)
            {
                if (ele == null || ele.obj == null)
                {
                    continue;
                }
                foreach (FavouritesTreeElement c in categories)
                {
                    if (c.category.id == ele.categoryId)
                    {
                        string     nm = ele.obj.name;
                        GameObject go = ele.obj as GameObject;
                        if (go != null && go.scene.IsValid())
                        {
                            nm = string.Format("{0} ({1})", nm, go.scene.name);
                        }
                        //else
                        //{
                        //	nm = string.Format("{0} ({1})", nm, AssetDatabase.GetAssetPath(ele.obj));
                        //}

                        icon = AssetPreview.GetMiniTypeThumbnail(ele.obj.GetType());

                        model.QuickAddElement(new FavouritesTreeElement()
                        {
                            Name = nm,
                            Icon = icon,
                            ID   = model.GenerateUniqueID(),
                            fav  = ele
                        }, c);

                        break;
                    }
                }
            }

            model.UpdateDataFromTree();
            Init(model);
            Reload();
            SetSelection(new List <int>());
        }