Beispiel #1
0
        public void SetEnabled(bool isEnabled)
        {
            enabled = isEnabled;

            if (children != null)
            {
                foreach (var child in children)
                {
                    AssetTreeItem asset = child as AssetTreeItem;

                    if (asset != null)
                    {
                        asset.SetEnabled(isEnabled);
                    }
                }
            }

            var upstream = parent;

            while (upstream != null)
            {
                var up = upstream as AssetTreeItem;

                if (up != null && up.children != null)
                {
                    AssetTreeItem firstChild = up.children.FirstOrDefault() as AssetTreeItem;

                    if (firstChild != null)
                    {
                        up.m_IsMixedState = up.children.Any(x =>
                        {
                            var y = x as AssetTreeItem;
                            return(y.enabled != firstChild.enabled);
                        });

                        if (!up.m_IsMixedState)
                        {
                            up.enabled = firstChild.enabled;
                        }
                    }
                    else
                    {
                        up.m_IsMixedState = false;
                    }
                }

                upstream = upstream.parent;
            }
        }
Beispiel #2
0
        protected override void RowGUI(RowGUIArgs args)
        {
            CenterRectUsingSingleLineHeight(ref args.rowRect);
            args.rowRect.xMin += GetContentIndent(args.item);

            AssetTreeItem item = args.item as AssetTreeItem;

            m_TempContent.text    = item.relativePath;
            m_TempContent.tooltip = item.fullPath;
            m_ToggleRect.x        = args.rowRect.xMin;
            m_ToggleRect.y        = args.rowRect.yMin;
            m_ToggleRect.width    = 16;
            m_ToggleRect.height   = args.rowRect.height;
            args.rowRect.xMin    += m_ToggleRect.width;

            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = item.isMixedState;
            item.enabled             = EditorGUI.Toggle(m_ToggleRect, "", item.enabled);
            EditorGUI.showMixedValue = false;

            if (EditorGUI.EndChangeCheck())
            {
                if (GetSelection().Any(x => FindItem(x, rootItem) == item))
                {
                    foreach (int id in GetSelection())
                    {
                        var sel = FindItem(id, rootItem) as AssetTreeItem;

                        if (sel != null)
                        {
                            sel.SetEnabled(item.enabled);
                        }
                    }
                }
                else
                {
                    item.SetEnabled(item.enabled);
                }
            }

            bool guiEnabled = GUI.enabled;

            GUI.enabled = item.enabled;
            GUI.Label(args.rowRect, m_TempContent);
            GUI.enabled = guiEnabled;
        }
Beispiel #3
0
        void GatherTreeItems(AssetTreeItem node, List <AssetTreeItem> list)
        {
            if (node == null)
            {
                return;
            }

            list.Add(node);

            if (node.children != null)
            {
                foreach (var child in node.children)
                {
                    if (child is AssetTreeItem)
                    {
                        GatherTreeItems(child as AssetTreeItem, list);
                    }
                }
            }
        }
Beispiel #4
0
        void PopulateAssetTree(string directory, AssetTreeItem parent, ref int nodeIdIndex)
        {
            string unixDirectory = directory.Replace("\\", "/");

            AssetTreeItem leaf = new AssetTreeItem(
                nodeIdIndex++,
                unixDirectory,
                unixDirectory.Replace(parent.fullPath, "").Trim('/'))
            {
                enabled = true
            };

            parent.AddChild(leaf);

            foreach (string path in Directory.GetFiles(directory, "*", SearchOption.TopDirectoryOnly))
            {
                if (path.StartsWith(".") || path.EndsWith(".meta"))
                {
                    continue;
                }

                string unixPath = path.Replace("\\", "/");

                leaf.AddChild(new AssetTreeItem(
                                  nodeIdIndex++,
                                  unixPath,
                                  unixPath.Replace(unixDirectory, "").Trim('/'))
                {
                    enabled = true
                });
            }

            foreach (string dir in Directory.GetDirectories(directory, "*", SearchOption.TopDirectoryOnly))
            {
                PopulateAssetTree(dir, leaf, ref nodeIdIndex);
            }
        }
Beispiel #5
0
        bool RemoveAssetStoreFiles(TreeViewItem root, StringBuilder log)
        {
            AssetTreeItem node = root as AssetTreeItem;

            if (node != null && (node.enabled && !node.isMixedState))
            {
                if (!AssetDatabase.MoveAssetToTrash(node.fullPath))
                {
                    if (!AssetDatabase.DeleteAsset(node.fullPath))
                    {
                        if (Directory.Exists(node.fullPath))
                        {
                            Directory.Delete(node.fullPath, true);

                            if (Directory.Exists(node.fullPath))
                            {
                                Debug.LogError("Directory.Delete failed, giving up. (" + node.fullPath + ")");
                                return(false);
                            }
                            else
                            {
                                File.Delete(node.fullPath.Trim('/') + ".meta");
                            }
                        }
                        else if (File.Exists(node.fullPath))
                        {
                            File.Delete(node.fullPath);

                            if (File.Exists(node.fullPath))
                            {
                                Debug.LogError("File.Delete failed, giving up (" + node.fullPath + ")");
                                return(true);
                            }
                            else
                            {
                                File.Delete(node.fullPath + ".meta");
                            }
                        }
                    }
                }

                log.AppendLine("  - " + node.fullPath);

                return(true);
            }

            if (node.children != null)
            {
                bool success = true;

                foreach (var branch in node.children)
                {
                    if (!RemoveAssetStoreFiles(branch, log))
                    {
                        success = false;
                    }
                }

                return(success);
            }

            return(true);
        }