Ejemplo n.º 1
0
    protected override DragAndDropVisualMode HandleDragAndDrop(DragAndDropArgs args)
    {
        if (args.dragAndDropPosition == DragAndDropPosition.OutsideItems)
        {
            return(DragAndDropVisualMode.Rejected);
        }

        if (args.performDrop)
        {
            if (DragAndDrop.objectReferences.Length > 0)
            {//this is dropping asset into tree
                if (!isPreview)
                {
                    return(DragAndDropVisualMode.Rejected); //can only drop asset in the file list, not the folder structure
                }
                designer.GetAllAssetsDependency(DragAndDrop.objectReferences);
            }
            else
            {//this is dropping item from tree
                TreeViewItem dropTarget = args.parentItem;

                if (dropTarget is AssetTreeViewItem)
                {
                    return(DragAndDropVisualMode.Rejected);
                }


                for (int i = 0; i < m_Dragged.Count; ++i)
                {
                    TreeViewItem      itm       = FindItem(m_Dragged[i], rootItem);
                    AssetTreeViewItem assetItem = itm as AssetTreeViewItem;

                    if (assetItem != null)
                    {
                        string filename    = System.IO.Path.GetFileName(assetItem.fullAssetPath);
                        string newFilename = GetFullPath(dropTarget) + "/" + filename;

                        designer.currentlyEdited.outputPath[assetItem.dependencyIdx] = newFilename;
                    }
                    else
                    {
                        string originPath = GetFullPath(itm.parent);
                        string targetPath = GetFullPath(dropTarget);

                        for (int j = 0; j < itm.children.Count; ++j)
                        {
                            ReparentAssets(itm.children[j], originPath, targetPath);
                        }
                    }
                }

                designer.PopulateTreeview();
            }
        }

        return(DragAndDropVisualMode.Move);
    }
Ejemplo n.º 2
0
    protected override void SelectionChanged(IList <int> selectedIds)
    {
        List <AssetMode.AssetInfo> list = new List <AssetMode.AssetInfo>();

        foreach (int nodeId in selectedIds)
        {
            AssetTreeViewItem item = FindItem(nodeId, rootItem) as AssetTreeViewItem;
            if (item != null)
            {
                list.Add(item.asset);
            }
        }

        if (list.Count == 1)
        {
            mController.UpdateSelectedAssets(list);
        }
    }
    protected override void RowGUI(RowGUIArgs args)
    {
        GUI.color = Color.white;

        if (args.item.hasChildren == false)
        {
            AssetTreeViewItem itm = args.item as AssetTreeViewItem;
            if (itm != null)
            {
                if (designer.nonCompilingFiles.Contains(itm.fullAssetPath))
                {
                    GUI.color = Color.red;
                }
            }
        }

        base.RowGUI(args);
    }
Ejemplo n.º 4
0
        private void CellGUI(Rect cellRect, AssetTreeViewItem item, int column, ref RowGUIArgs args)
        {
            Color oldColor = GUI.color;

            CenterRectUsingSingleLineHeight(ref cellRect);
            //if (column != 3)
            //    GUI.color = item.itemColor;
            if (!File.Exists(item.asset.data.path))
            {
                GUI.color = Color.red;
            }

            switch ((MyColumns)column)
            {
            case MyColumns.Asset:
            {
                var iconRect = new Rect(cellRect.x + 1, cellRect.y + 1, cellRect.height - 2, cellRect.height - 2);
                if (item.icon != null)
                {
                    GUI.DrawTexture(iconRect, item.icon, ScaleMode.ScaleToFit);
                }

                var nameRect = new Rect(cellRect.x + iconRect.xMax + 1
                                        , cellRect.y, cellRect.width - iconRect.width, cellRect.height);

                DefaultGUI.Label(nameRect,
                                 item.displayName,
                                 args.selected,
                                 args.focused);
            }
            break;

            case MyColumns.Size:
                DefaultGUI.Label(cellRect, item.asset.GetSizeString(), args.selected, args.focused);
                break;

            case MyColumns.Path:
                DefaultGUI.Label(cellRect, item.asset.data.path, args.selected, args.focused);
                break;
            }

            GUI.color = oldColor;
        }
    void RecursiveAdd(TreeViewItem root, string value, string fullPath, int dependencyIdx)
    {
        int idx = value.IndexOf('/');

        if (idx > 0)
        {
            string node       = value.Substring(0, idx);
            string childValue = value.Substring(idx + 1);

            if (root.hasChildren)
            {
                for (int i = 0; i < root.children.Count; ++i)
                {
                    if (root.children[i].displayName == node)
                    {
                        RecursiveAdd(root.children[i], childValue, fullPath, dependencyIdx);
                        return;
                    }
                }
            }

            //we didn't find a children named that way, so create a new one
            TreeViewItem itm = new TreeViewItem(freeID);
            freeID         += 1;
            itm.displayName = node;
            itm.icon        = m_FolderIcone;
            root.AddChild(itm);
            RecursiveAdd(itm, childValue, fullPath, dependencyIdx);
        }
        else
        {//this is a leaf node, just create a new one and add it to the root
            AssetTreeViewItem itm = new AssetTreeViewItem(freeID);
            freeID += 1;

            itm.displayName   = value;
            itm.fullAssetPath = fullPath;
            itm.dependencyIdx = dependencyIdx;
            Object obj = AssetDatabase.LoadAssetAtPath(fullPath, typeof(UnityEngine.Object));
            itm.icon = AssetPreview.GetMiniThumbnail(obj);

            root.AddChild(itm);
        }
    }
    //this is to reimplify rename, it's easier to descend to each children and set their output path to the GetFullPath...
    void TriggerRename(TreeViewItem item)
    {
        if (item.hasChildren)
        {
            for (int i = 0; i < item.children.Count; ++i)
            {
                TriggerRename(item.children[i]);
            }
        }
        else
        {
            AssetTreeViewItem assetItem = item as AssetTreeViewItem;
            if (assetItem != null)
            {
                string p = GetFullPath(item);

                designer.currentlyEdited.outputPath[assetItem.dependencyIdx] = p;
            }
        }
    }
    protected override void SelectionChanged(IList <int> selectedIds)
    {
        base.SelectionChanged(selectedIds);

        assetPreviews = new GUIContent[0];

        IList <TreeViewItem> items = FindRows(selectedIds);

        for (int i = 0; i < items.Count; ++i)
        {
            if (!items[i].hasChildren)
            {
                AssetTreeViewItem itm = items[i] as AssetTreeViewItem;
                if (itm != null)
                {
                    GUIContent content = new GUIContent(AssetPreview.GetAssetPreview(AssetDatabase.LoadAssetAtPath(itm.fullAssetPath, typeof(Object))));
                    ArrayUtility.Add(ref assetPreviews, content);
                }
            }
        }
    }
    void ReparentAssets(TreeViewItem item, string rootPath, string newPath)
    {
        if (item.hasChildren)
        {
            for (int i = 0; i < item.children.Count; ++i)
            {
                ReparentAssets(item.children[i], rootPath, newPath);
            }
        }
        else
        {
            AssetTreeViewItem assetTreeItem = item as AssetTreeViewItem;
            if (assetTreeItem == null)
            {
                return;
            }

            string path = GetFullPath(assetTreeItem);
            path = path.Replace(rootPath, newPath);
            designer.currentlyEdited.outputPath[assetTreeItem.dependencyIdx] = path;
        }
    }
Ejemplo n.º 9
0
 public void AddRoot(string displayName, T currentData)
 {
     itemIndex = 1;
     root      = new AssetTreeViewItem <T>(0, -1, displayName, currentData);
 }