Exemple #1
0
        public void AddAssetToFolder(AssetInfo assetInfo, AssetFolderInfo folder)
        {
            if (folder.Assets == null)
            {
                folder.Assets = new List <AssetInfo>();
            }

            if (assetInfo.Folder != null)
            {
                if (!m_folders.Contains(folder))
                {
                    TreeView.treeModel.RemoveElements(new[] { assetInfo.id });
                }
                else if (TreeView.treeModel.Find(assetInfo.id) == null)
                {
                    AssetInfo parent = (AssetInfo)assetInfo.parent;
                    if (parent == null)
                    {
                        parent = TreeView.treeModel.root;
                    }

                    TreeView.treeModel.AddElement(assetInfo, parent, parent.hasChildren ? parent.children.Count : 0);
                }
                assetInfo.Folder.Assets.Remove(assetInfo);
            }

            assetInfo.Folder = folder;
            folder.Assets.Add(assetInfo);
        }
Exemple #2
0
        private bool Foreach(AssetFolderInfo folder, Func <AssetInfo, bool> callback)
        {
            if (folder.Assets != null)
            {
                for (int i = 0; i < folder.Assets.Count; ++i)
                {
                    AssetInfo assetInfo = folder.Assets[i];
                    if (assetInfo != null)
                    {
                        if (!callback(assetInfo))
                        {
                            return(false);
                        }
                    }
                }
            }

            if (folder.hasChildren)
            {
                for (int i = 0; i < folder.children.Count; ++i)
                {
                    AssetFolderInfo childFolder = folder.children[i] as AssetFolderInfo;
                    if (childFolder != null)
                    {
                        if (!Foreach(childFolder, callback))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Exemple #3
0
        private void Awake()
        {
            if (m_assetLibrary == null || m_assetLibrary.Folders.Count == 0)
            {
                AssetFolderInfo rootFolder = new AssetFolderInfo
                {
                    name  = "Root",
                    depth = -1,
                };

                AssetFolderInfo assetsFolder = new AssetFolderInfo("Assets", 0, 3);
                assetsFolder.IsEnabled = true;

                m_assetLibrary = new AssetLibraryInfo
                {
                    name    = "Root",
                    depth   = -1,
                    Folders = new List <AssetFolderInfo>
                    {
                        rootFolder,
                        assetsFolder
                    },
                };
            }
        }
Exemple #4
0
        private bool MoveToNewLocationDialog(UnityObject[] assets, AssetFolderInfo folder)
        {
            bool moveToNewLocation   = true;
            bool moveDialogDisplayed = false;

            foreach (UnityObject asset in assets)
            {
                if (!moveDialogDisplayed)
                {
                    AssetFolderInfo existingFolder;
                    AssetInfo       existingAsset;
                    if (m_asset.AssetLibrary.TryGetAssetInfo(asset, out existingFolder, out existingAsset))
                    {
                        if (existingFolder != folder)
                        {
                            moveToNewLocation = EditorUtility.DisplayDialog(
                                "Same asset already added",
                                "Same asset already added to asset library. Do you want to move it to new location?", "Yes", "No");
                            moveDialogDisplayed = true;
                        }
                    }
                }
            }

            return(moveToNewLocation);
        }
Exemple #5
0
        private void RemoveFromFolder(AssetInfo assetInfo, AssetFolderInfo folder)
        {
            List <AssetInfo> assetsToRemove = new List <AssetInfo>();

            FlattenItems(assetInfo, assetsToRemove);
            DoRemove(assetsToRemove.ToArray());
        }
        private int BuildSubtree(AssetFolderInfo parent, int startIndex)
        {
            parent.children = new List <TreeElement>();
            for (int i = startIndex; i < Folders.Count; ++i)
            {
                AssetFolderInfo folder = Folders[i];
                if (folder == null)
                {
                    continue;
                }

                if (folder.depth == parent.depth + 1)
                {
                    parent.children.Add(folder);
                }
                else if (folder.depth == parent.depth + 2)
                {
                    i = BuildSubtree(Folders[i - 1], i);
                }
                else if (folder.depth > parent.depth + 2)
                {
                    throw new InvalidOperationException("Unable to build AssetLibraryInfo tree -> folder.depth > parent.depth + 2");
                }
                else
                {
                    return(i - 1);
                }
            }

            return(Folders.Count);
        }
        private bool TryGetAssetInfo(AssetFolderInfo folder, UnityObject obj, out AssetFolderInfo resultFolder, out AssetInfo resultAsset)
        {
            if (folder.Assets != null)
            {
                for (int i = 0; i < folder.Assets.Count; ++i)
                {
                    AssetInfo asset = folder.Assets[i];
                    if (asset.Object == obj)
                    {
                        resultFolder = folder;
                        resultAsset  = asset;
                        return(true);
                    }
                }
            }

            if (folder.hasChildren)
            {
                for (int i = 0; i < folder.children.Count; ++i)
                {
                    AssetFolderInfo subfolder = (AssetFolderInfo)folder.children[i];
                    if (TryGetAssetInfo(subfolder, obj, out resultFolder, out resultAsset))
                    {
                        return(true);
                    }
                }
            }

            resultAsset  = null;
            resultFolder = null;
            return(false);
        }
        public void BuildTree()
        {
            if (Folders == null || Folders.Count == 0)
            {
                return;
            }
            AssetFolderInfo root = Folders[0];

            if (root.depth != -1)
            {
                throw new InvalidOperationException("Unable to build AssetLibraryInfo tree -> root.depth != -1");
            }
            BuildSubtree(root, 1);
        }
 public bool TryGetAssetInfo(UnityObject obj, out AssetFolderInfo resultFolder, out AssetInfo resultAsset)
 {
     for (int i = 0; i < Folders.Count; ++i)
     {
         AssetFolderInfo folder = Folders[i];
         if (folder != null && TryGetAssetInfo(folder, obj, out resultFolder, out resultAsset))
         {
             return(true);
         }
     }
     resultAsset  = null;
     resultFolder = null;
     return(false);
 }
Exemple #10
0
        private AssetFolderInfo CopyFolder(string path, TreeViewItem parent, int insertIndex)
        {
            string          lastFolderName = Path.GetFileName(path);
            AssetFolderInfo parentData     = GetAssetFolderInfo(parent);
            AssetFolderInfo folder         = CreateFolder(lastFolderName, parentData,
                                                          insertIndex == -1 ?
                                                          parentData.hasChildren ?
                                                          parentData.children.Count
                        : 0
                    : insertIndex);

            if (folder == null)
            {
                return(null);
            }

            TreeViewItem folderTreeViewItem = TreeView.FindItem(folder.id);

            string[] subfolders = AssetDatabase.GetSubFolders(path);

            string[] assetGuids = AssetDatabase.FindAssets("", new[] { path }).Distinct().ToArray();

            List <UnityObject> assets = new List <UnityObject>();

            foreach (string assetGuid in assetGuids)
            {
                string assetPath = AssetDatabase.GUIDToAssetPath(assetGuid);
                if (Path.GetFullPath(path) == Path.GetFullPath(Path.GetDirectoryName(assetPath)))
                {
                    UnityObject asset = AssetDatabase.LoadAssetAtPath(assetPath, typeof(UnityObject));
                    assets.Add(asset);
                }
            }

            UnityObject[] assetsArray = assets.ToArray();
            if (assetsArray.Length > 0)
            {
                MoveToNewLocationDialog(assetsArray);
                m_assetsGUI.InitIfNeeded();
                m_assetsGUI.AddAssetToFolder(assetsArray, folder, m_moveToNewLocation);
            }

            for (int i = 0; i < subfolders.Length; ++i)
            {
                CopyFolder(subfolders[i], folderTreeViewItem, i);
            }

            return(folder);
        }
Exemple #11
0
        public bool Foreach(Func <AssetInfo, bool> callback)
        {
            if (m_assetLibrary.Folders != null)
            {
                for (int i = 0; i < m_assetLibrary.Folders.Count; ++i)
                {
                    AssetFolderInfo folder = m_assetLibrary.Folders[i];
                    if (!Foreach(folder, callback))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemple #12
0
        private void CreateFolder()
        {
            Undo.RecordObject(m_asset, "Create Asset Folder");

            TreeView.EndRename();
            var             selection = TreeView.GetSelection();
            TreeElement     parent    = (selection.Count == 1 ? TreeView.treeModel.Find(selection[0]) : null) ?? TreeView.treeModel.root;
            AssetFolderInfo folder    = CreateFolder("Folder", parent, 0);

            if (folder == null)
            {
                return;
            }
            // Select newly created element
            TreeView.SetSelection(new[] { folder.id }, TreeViewSelectionOptions.RevealAndFrame);
            TreeView.BeginRename(folder.id);
        }
Exemple #13
0
        private AssetFolderInfo CreateFolder(string name, TreeElement parent, int insertPosition)
        {
            int depth = parent != null ? parent.depth + 1 : 0;

            if (m_asset.AssetLibrary.FolderIdentity >= AssetLibraryInfo.MAX_FOLDERS)
            {
                EditorUtility.DisplayDialog("Unable to add folder", string.Format("Max 'FolderIndentity' value reached. 'FolderIndentity' ==  {0}", AssetLibraryInfo.MAX_FOLDERS), "OK");
                return(null);
            }
            int id      = m_asset.AssetLibrary.FolderIdentity++;
            var element = new AssetFolderInfo(name, depth, id);

            TreeView.treeModel.AddElement(element, parent, insertPosition);

            TreeView.SetSelection(new[] { element.id }, TreeViewSelectionOptions.RevealAndFrame);

            return(element);
        }
Exemple #14
0
        public void LoadIDMappingTo(MappingInfo mapping, bool IIDtoPID, bool PIDtoObj)
        {
            if (!IIDtoPID && !PIDtoObj)
            {
                return;
            }

            if (m_assetLibrary == null || m_assetLibrary.Folders == null || m_assetLibrary.Folders.Count == 0)
            {
                return;
            }

            List <int> instanceIDs   = new List <int>();
            List <int> persistentIDs = new List <int>();

            for (int i = 0; i < m_assetLibrary.Folders.Count; ++i)
            {
                AssetFolderInfo folder = m_assetLibrary.Folders[i];
                if (folder != null)
                {
                    if (folder.Assets != null && folder.Assets.Count > 0)
                    {
                        for (int j = 0; j < folder.Assets.Count; ++j)
                        {
                            AssetInfo asset = folder.Assets[j];
                            if (asset.Object != null)
                            {
                                LoadIDMappingTo(asset, mapping, instanceIDs, persistentIDs, IIDtoPID, PIDtoObj);
                            }
                        }
                    }
                }
            }

            mapping.Add(this, instanceIDs, persistentIDs);
        }
Exemple #15
0
        private DragAndDropVisualMode PerformDrop(TreeViewItem parent, int insertIndex)
        {
            DragAndDrop.AcceptDrag();

            List <UnityObject> assets = new List <UnityObject>();

            foreach (UnityObject dragged_object in DragAndDrop.objectReferences)
            {
                string path = AssetDatabase.GetAssetPath(dragged_object);
                if (!string.IsNullOrEmpty(path) && File.Exists(path))
                {
                    assets.Add(dragged_object);
                }
            }


            AssetFolderInfo folder = m_folders[0];

            UnityObject[] assetsArray       = assets.ToArray();
            bool          moveToNewLocation = MoveToNewLocationDialog(assetsArray, folder);

            AddAssetToFolder(parent, insertIndex, assetsArray, folder, moveToNewLocation);
            return(DragAndDropVisualMode.Copy);
        }
        private static void CreateBuiltInAssetLibrary(int index, AssetLibraryAsset asset, AssetFolderInfo folder, HashSet <UnityObject> hs)
        {
            Dictionary <string, Type> builtInExtra = new Dictionary <string, Type>
            {
                { "Default-Line.mat", typeof(Material) },
                { "Default-Material.mat", typeof(Material) },
                { "Default-Particle.mat", typeof(Material) },
                { "Default-Skybox.mat", typeof(Material) },
                { "Sprites-Default.mat", typeof(Material) },
                { "Sprites-Mask.mat", typeof(Material) },
                { "UI/Skin/Background.psd", typeof(Sprite) },
                { "UI/Skin/Checkmark.psd", typeof(Sprite) },
                { "UI/Skin/DropdownArrow.psd", typeof(Sprite) },
                { "UI/Skin/InputFieldBackground.psd", typeof(Sprite) },
                { "UI/Skin/Knob.psd", typeof(Sprite) },
                { "UI/Skin/UIMask.psd", typeof(Sprite) },
                { "UI/Skin/UISprite.psd", typeof(Sprite) },
                { "Default-Terrain-Standard.mat", typeof(Material) },
                { "Default-Particle.psd", typeof(Texture2D) },
            };

            Dictionary <string, Type> builtIn = new Dictionary <string, Type>
            {
                { "New-Sphere.fbx", typeof(Mesh) },
                { "New-Capsule.fbx", typeof(Mesh) },
                { "New-Cylinder.fbx", typeof(Mesh) },
                { "Cube.fbx", typeof(Mesh) },
                { "New-Plane.fbx", typeof(Mesh) },
                { "Quad.fbx", typeof(Mesh) },
                { "Arial.ttf", typeof(Font) }
            };



            List <object> builtInAssets = new List <object>();

            foreach (KeyValuePair <string, Type> kvp in builtInExtra)
            {
                UnityObject obj = AssetDatabase.GetBuiltinExtraResource(kvp.Value, kvp.Key);
                if (obj != null)
                {
                    builtInAssets.Add(obj);
                }
            }

            foreach (KeyValuePair <string, Type> kvp in builtIn)
            {
                UnityObject obj = Resources.GetBuiltinResource(kvp.Value, kvp.Key);
                if (obj != null)
                {
                    builtInAssets.Add(obj);
                }
            }

            GameObject defaultTree = Resources.Load <GameObject>("Tree/RTT_DefaultTree");

            if (defaultTree != null)
            {
                builtInAssets.Add(defaultTree);
                Material barkMaterial = Resources.Load <Material>("Tree/Materials/RTT_DefaultTreeBark");
                if (barkMaterial != null)
                {
                    builtInAssets.Add(barkMaterial);
                }
                Material branchesMaterial = Resources.Load <Material>("Tree/Materials/RTT_DefaultTreeBranches");
                if (branchesMaterial != null)
                {
                    builtInAssets.Add(branchesMaterial);
                }
            }

            CreateAssetLibrary(builtInAssets.ToArray(), "BuiltInAssets", "BuiltInAssetLibrary", index, asset, folder, hs);
        }
        private static void CreateAssetLibraryForScene(Scene scene, int index, AssetLibraryAsset asset, AssetFolderInfo folder, HashSet <UnityObject> hs)
        {
            TypeMap <long>    typeMap    = new TypeMap <long>();
            AssetDB           assetDB    = new AssetDB();
            RuntimeShaderUtil shaderUtil = new RuntimeShaderUtil();

            IOC.Register <ITypeMap>(typeMap);
            IOC.Register <IAssetDB>(assetDB);
            IOC.Register <IAssetDB <long> >(assetDB);
            IOC.Register <IRuntimeShaderUtil>(shaderUtil);

            PersistentRuntimeScene <long> rtScene = new PersistentRuntimeScene <long>();

            GetDepsFromContext ctx = new GetDepsFromContext();

            rtScene.GetDepsFrom(scene, ctx);

            Queue <UnityObject> depsQueue  = new Queue <UnityObject>(ctx.Dependencies.OfType <UnityObject>());
            GetDepsFromContext  getDepsCtx = new GetDepsFromContext();

            while (depsQueue.Count > 0)
            {
                UnityObject uo = depsQueue.Dequeue();
                if (!uo)
                {
                    continue;
                }

                Type persistentType = typeMap.ToPersistentType(uo.GetType());
                if (persistentType != null)
                {
                    getDepsCtx.Clear();

                    try
                    {
                        IPersistentSurrogate persistentObject = (IPersistentSurrogate)Activator.CreateInstance(persistentType);
                        persistentObject.GetDepsFrom(uo, getDepsCtx);
                    }
                    catch (Exception e)
                    {
                        Debug.LogError(e);
                    }

                    foreach (UnityObject dep in getDepsCtx.Dependencies)
                    {
                        if (!ctx.Dependencies.Contains(dep))
                        {
                            ctx.Dependencies.Add(dep);
                            depsQueue.Enqueue(dep);
                        }
                    }
                }
            }

            IOC.Unregister <IRuntimeShaderUtil>(shaderUtil);
            IOC.Unregister <ITypeMap>(typeMap);
            IOC.Unregister <IAssetDB>(assetDB);
            IOC.Unregister <IAssetDB <long> >(assetDB);

            CreateAssetLibrary(ctx.Dependencies.ToArray(), "Scenes/" + scene.name, "SceneAssetLibrary", index, asset, folder, hs);
        }
 private static HashSet <UnityObject> ReadFromBuiltInAssetLibraries(out int index, out AssetLibraryAsset asset, out AssetFolderInfo folder)
 {
     if (!Directory.Exists(Path.GetFullPath(RTSLPath.UserRoot + "/" + RTSLPath.LibrariesFolder + "/Resources/BuiltInAssets")))
     {
         return(ReadFromAssetLibraries(new string[0], out index, out asset, out folder));
     }
     string[] guids = AssetDatabase.FindAssets("", new[] { RTSLPath.UserRoot + "/" + RTSLPath.LibrariesFolder + "/Resources/BuiltInAssets" });
     return(ReadFromAssetLibraries(guids, out index, out asset, out folder));
 }
        private static HashSet <UnityObject> ReadFromAssetLibraries(string[] guids, out int index, out AssetLibraryAsset asset, out AssetFolderInfo folder)
        {
            HashSet <UnityObject> hs = new HashSet <UnityObject>();

            List <AssetLibraryAsset> assetLibraries = new List <AssetLibraryAsset>();

            foreach (string guid in guids)
            {
                string path = AssetDatabase.GUIDToAssetPath(guid);

                AssetLibraryAsset assetLibrary = AssetDatabase.LoadAssetAtPath <AssetLibraryAsset>(path);
                if (assetLibrary != null)
                {
                    assetLibrary.Foreach(assetInfo =>
                    {
                        if (assetInfo.Object != null)
                        {
                            if (!hs.Contains(assetInfo.Object))
                            {
                                hs.Add(assetInfo.Object);
                            }

                            if (assetInfo.PrefabParts != null)
                            {
                                foreach (PrefabPartInfo prefabPart in assetInfo.PrefabParts)
                                {
                                    if (prefabPart.Object != null)
                                    {
                                        if (!hs.Contains(prefabPart.Object))
                                        {
                                            hs.Add(prefabPart.Object);
                                        }
                                    }
                                }
                            }
                        }
                        return(true);
                    });

                    assetLibraries.Add(assetLibrary);
                }
            }

            if (assetLibraries.Count == 0)
            {
                asset = ScriptableObject.CreateInstance <AssetLibraryAsset>();
                index = 0;
            }
            else
            {
                asset = assetLibraries.OrderBy(a => a.AssetLibrary.Identity).FirstOrDefault();
                index = assetLibraries.Count - 1;
            }

            folder = asset.AssetLibrary.Folders.Where(f => f.depth == 0).First();
            if (folder.Assets == null)
            {
                folder.Assets = new List <AssetInfo>();
            }
            return(hs);
        }
        private static void CreateAssetLibrary(object[] objects, string folderName, string assetLibraryName, int index, AssetLibraryAsset asset, AssetFolderInfo folder, HashSet <UnityObject> hs)
        {
            int identity = asset.AssetLibrary.Identity;

            foreach (object o in objects)
            {
                UnityObject obj = o as UnityObject;
                if (!obj)
                {
                    if (o != null)
                    {
                        Debug.Log(o.GetType() + " is not a UnityEngine.Object");
                    }
                    continue;
                }

                if (hs.Contains(obj))
                {
                    continue;
                }

                if (!AssetDatabase.Contains(obj))
                {
                    continue;
                }

                if (obj is GameObject)
                {
                    GameObject go        = (GameObject)obj;
                    AssetInfo  assetInfo = new AssetInfo(go.name, 0, identity);
                    assetInfo.Object = go;
                    hs.Add(go);

                    identity++;

                    List <PrefabPartInfo> prefabParts = new List <PrefabPartInfo>();
                    AssetLibraryAssetsGUI.CreatePefabParts(go, ref identity, prefabParts);
                    for (int i = prefabParts.Count - 1; i >= 0; --i)
                    {
                        PrefabPartInfo prefabPart = prefabParts[i];
                        if (hs.Contains(prefabPart.Object))
                        {
                            prefabParts.Remove(prefabPart);
                        }
                        else
                        {
                            hs.Add(prefabPart.Object);
                        }
                    }

                    if (prefabParts.Count >= AssetLibraryInfo.MAX_ASSETS - AssetLibraryInfo.INITIAL_ID)
                    {
                        EditorUtility.DisplayDialog("Unable Create AssetLibrary", string.Format("Max 'Indentity' value reached. 'Identity' ==  {0}", AssetLibraryInfo.MAX_ASSETS), "OK");
                        return;
                    }

                    if (identity >= AssetLibraryInfo.MAX_ASSETS)
                    {
                        SaveAssetLibrary(asset, folderName, assetLibraryName, index);
                        index++;

                        asset  = ScriptableObject.CreateInstance <AssetLibraryAsset>();
                        folder = asset.AssetLibrary.Folders.Where(f => f.depth == 0).First();
                        if (folder.Assets == null)
                        {
                            folder.Assets = new List <AssetInfo>();
                        }
                        identity = asset.AssetLibrary.Identity;
                    }

                    assetInfo.PrefabParts       = prefabParts;
                    asset.AssetLibrary.Identity = identity;
                    folder.Assets.Add(assetInfo);
                    assetInfo.Folder = folder;
                }
                else
                {
                    AssetInfo assetInfo = new AssetInfo(obj.name, 0, identity);
                    assetInfo.Object = obj;
                    identity++;

                    if (identity >= AssetLibraryInfo.MAX_ASSETS)
                    {
                        SaveAssetLibrary(asset, folderName, assetLibraryName, index);
                        index++;

                        asset  = ScriptableObject.CreateInstance <AssetLibraryAsset>();
                        folder = asset.AssetLibrary.Folders.Where(f => f.depth == 0).First();
                        if (folder.Assets == null)
                        {
                            folder.Assets = new List <AssetInfo>();
                        }
                        identity = asset.AssetLibrary.Identity;
                    }

                    asset.AssetLibrary.Identity = identity;
                    folder.Assets.Add(assetInfo);
                    assetInfo.Folder = folder;
                }
            }

            SaveAssetLibrary(asset, folderName, assetLibraryName, index);
            index++;

            //Selection.activeObject = asset;
            //EditorGUIUtility.PingObject(asset);
        }
Exemple #21
0
        private static void CreateAssetLibraryForScene(Scene scene, int index, AssetLibraryAsset asset, AssetFolderInfo folder, HashSet <UnityObject> hs)
        {
            TypeMap typeMap = new TypeMap();
            AssetDB assetDB = new AssetDB();

            IOC.Register <ITypeMap>(typeMap);
            IOC.Register <IAssetDB>(assetDB);

            PersistentRuntimeScene rtScene = new PersistentRuntimeScene();

            GetDepsFromContext ctx = new GetDepsFromContext();

            rtScene.GetDepsFrom(scene, ctx);

            IOC.Unregister <ITypeMap>(typeMap);
            IOC.Unregister <IAssetDB>(assetDB);


            CreateAssetLibrary(ctx.Dependencies.ToArray(), "Scenes/" + scene.name, "SceneAssetLibrary", index, asset, folder, hs);
        }
Exemple #22
0
 private static HashSet <UnityObject> ReadFromSceneAssetLibraries(Scene scene, out int index, out AssetLibraryAsset asset, out AssetFolderInfo folder)
 {
     if (!Directory.Exists(Application.dataPath + RTSLPath.UserRoot + "/" + RTSLPath.LibrariesFolder + "/Resources/Scenes/" + scene.name))
     {
         return(ReadFromAssetLibraries(new string[0], out index, out asset, out folder));
     }
     string[] guids = AssetDatabase.FindAssets("", new[] { "Assets" + RTSLPath.UserRoot + "/" + RTSLPath.LibrariesFolder + "/Resources/Scenes/" + scene.name });
     return(ReadFromAssetLibraries(guids, out index, out asset, out folder));
 }
Exemple #23
0
        private AssetInfo CreateAsset(string name, TreeElement parent, int insertIndex = -1, AssetFolderInfo folder = null)
        {
            int depth = parent != null ? parent.depth + 1 : 0;
            int id    = m_asset.AssetLibrary.Identity;

            m_asset.AssetLibrary.Identity++;
            var assetInfo = new AssetInfo(name, depth, id);

            if (folder != null)
            {
                if (IsFolderSelected(folder))
                {
                    TreeView.treeModel.AddElement(assetInfo, parent, insertIndex == -1 ?
                                                  parent.hasChildren ?
                                                  parent.children.Count
                        : 0
                        : insertIndex);

                    // Select newly created element

                    if (depth == 0)
                    {
                        TreeView.SetSelection(new[] { id }, TreeViewSelectionOptions.RevealAndFrame);
                    }
                }
            }

            return(assetInfo);
        }
Exemple #24
0
        private DragAndDropVisualMode PerformDrop(TreeViewItem parent, int insertIndex, bool outside)
        {
            DragAndDrop.AcceptDrag();

            var draggedRows = DragAndDrop.GetGenericData(AssetTreeView.k_GenericDragID) as List <TreeViewItem>;

            if (draggedRows != null)
            {
                foreach (TreeViewItem <AssetInfo> dragged_object in draggedRows)
                {
                    if (!outside)
                    {
                        AssetFolderInfo folder = GetAssetFolderInfo(parent);
                        m_assetsGUI.InitIfNeeded();
                        m_assetsGUI.AddAssetToFolder(dragged_object.data, folder);
                    }
                }
            }
            else
            {
                m_moveDialogDisplayed = false;
                m_moveToNewLocation   = true;

                List <UnityObject> assets = new List <UnityObject>();
                foreach (UnityObject dragged_object in DragAndDrop.objectReferences)
                {
                    string path = AssetDatabase.GetAssetPath(dragged_object);



                    if (!string.IsNullOrEmpty(path) && File.Exists(path))
                    {
                        if (!outside)
                        {
                            assets.Add(dragged_object);
                        }
                    }
                    else
                    {
                        if (!CanDrop(dragged_object))
                        {
                            continue;
                        }

                        m_assetsGUI.InitIfNeeded();

                        AssetFolderInfo folder = CopyFolder(path, parent, insertIndex);
                        if (folder == null)
                        {
                            return(DragAndDropVisualMode.Rejected);
                        }

                        TreeView.SetSelection(new[] { folder.id }, TreeViewSelectionOptions.RevealAndFrame);

                        SelectedFolders = new[] { folder };
                        if (SelectedFoldersChanged != null)
                        {
                            SelectedFoldersChanged(this, EventArgs.Empty);
                        }
                    }
                }

                UnityObject[] assetsArray = assets.ToArray();
                if (assetsArray.Length > 0)
                {
                    MoveToNewLocationDialog(assetsArray);
                    AssetFolderInfo folder = GetAssetFolderInfo(parent);
                    m_assetsGUI.InitIfNeeded();
                    m_assetsGUI.AddAssetToFolder(assetsArray, folder, m_moveToNewLocation);
                }
            }

            return(DragAndDropVisualMode.Copy);
        }
        private bool CreateAsset(UnityObject obj, AssetInfo parentAssetInfo, int insertIndex = -1, AssetFolderInfo folder = null)
        {
            if (obj is GameObject)
            {
                GameObject go = (GameObject)obj;

                int identity = m_asset.AssetLibrary.Identity + 1;
                List <PrefabPartInfo> prefabParts = new List <PrefabPartInfo>();
                CreatePefabParts(go, ref identity, prefabParts);


                string prefabPath = AssetDatabase.GetAssetPath(go);
                if (!string.IsNullOrEmpty(prefabPath))
                {
                    UnityObject[] assetRepresentations = AssetDatabase.LoadAllAssetRepresentationsAtPath(prefabPath);
                    foreach (UnityObject assetRepresentation in assetRepresentations)
                    {
                        //Add avatar or mesh as prefab part
                        if (assetRepresentation is Avatar || assetRepresentation is Mesh)
                        {
                            PrefabPartInfo prefabPart = new PrefabPartInfo();
                            prefabPart.ParentPersistentID = -1;
                            prefabPart.PersistentID       = identity;
                            prefabPart.Object             = assetRepresentation;
                            prefabPart.Depth = 0;
                            identity++;
                            prefabParts.Add(prefabPart);
                        }
                    }
                }

                if (identity >= AssetLibraryInfo.MAX_ASSETS)
                {
                    return(false);
                }

                AssetInfo assetInfo = CreateAsset(obj.name, parentAssetInfo, insertIndex, folder);
                assetInfo.Object = obj;
                AddAssetToFolder(assetInfo, folder);

                assetInfo.PrefabParts         = prefabParts;
                m_asset.AssetLibrary.Identity = identity;

                if (folder != null)
                {
                    if (IsFolderSelected(folder))
                    {
                        if (assetInfo.PrefabParts != null)
                        {
                            Dictionary <int, AssetInfo> assets = new Dictionary <int, AssetInfo>();
                            assets.Add(-1, assetInfo);

                            for (int i = 0; i < assetInfo.PrefabParts.Count; ++i)
                            {
                                PrefabPartInfo prefabPart = assetInfo.PrefabParts[i];
                                string         name;
                                if (prefabPart.Object == null)
                                {
                                    name = "<Null>";
                                }
                                else
                                {
                                    if (prefabPart.Object is Component)
                                    {
                                        name = prefabPart.Object.GetType().Name;
                                    }
                                    else
                                    {
                                        name = prefabPart.Object.name;
                                    }
                                }

                                AssetInfo prefabPartAssetInfo = new AssetInfo(name, assetInfo.depth + prefabPart.Depth, prefabPart.PersistentID);
                                prefabPartAssetInfo.Object = prefabPart.Object;

                                assets.Add(prefabPartAssetInfo.id, prefabPartAssetInfo);

                                TreeElement parent = assets[prefabPart.ParentPersistentID];
                                TreeView.treeModel.AddElement(prefabPartAssetInfo, parent, parent.children != null ? parent.children.Count : 0);
                            }
                        }
                    }
                }
            }
            else
            {
                AssetInfo assetInfo = CreateAsset(obj.name, parentAssetInfo, insertIndex, folder);
                assetInfo.Object = obj;
                AddAssetToFolder(assetInfo, folder);
            }
            return(true);
        }
Exemple #26
0
 public bool IsFolderSelected(AssetFolderInfo folder)
 {
     return(m_folders != null && m_folders.Contains(folder));
 }
Exemple #27
0
        private bool CreateAsset(UnityObject obj, AssetInfo parentAssetInfo, int insertIndex = -1, AssetFolderInfo folder = null)
        {
            if (obj is GameObject)
            {
                GameObject go = (GameObject)obj;

                int identity = m_asset.AssetLibrary.Identity + 1;
                List <PrefabPartInfo> prefabParts = new List <PrefabPartInfo>();
                CreatePefabParts(go, ref identity, prefabParts);
                if (identity >= AssetLibraryInfo.MAX_ASSETS)
                {
                    return(false);
                }

                AssetInfo assetInfo = CreateAsset(obj.name, parentAssetInfo, insertIndex, folder);
                assetInfo.Object = obj;
                AddAssetToFolder(assetInfo, folder);

                assetInfo.PrefabParts         = prefabParts;
                m_asset.AssetLibrary.Identity = identity;

                if (folder != null)
                {
                    if (IsFolderSelected(folder))
                    {
                        if (assetInfo.PrefabParts != null)
                        {
                            Dictionary <int, AssetInfo> assets = new Dictionary <int, AssetInfo>();
                            assets.Add(-1, assetInfo);

                            for (int i = 0; i < assetInfo.PrefabParts.Count; ++i)
                            {
                                PrefabPartInfo prefabPart = assetInfo.PrefabParts[i];
                                string         name;
                                if (prefabPart.Object == null)
                                {
                                    name = "<Null>";
                                }
                                else
                                {
                                    if (prefabPart.Object is Component)
                                    {
                                        name = prefabPart.Object.GetType().Name;
                                    }
                                    else
                                    {
                                        name = prefabPart.Object.name;
                                    }
                                }

                                AssetInfo prefabPartAssetInfo = new AssetInfo(name, assetInfo.depth + prefabPart.Depth, prefabPart.PersistentID);
                                prefabPartAssetInfo.Object = prefabPart.Object;

                                assets.Add(prefabPartAssetInfo.id, prefabPartAssetInfo);

                                TreeElement parent = assets[prefabPart.ParentPersistentID];
                                TreeView.treeModel.AddElement(prefabPartAssetInfo, parent, parent.children != null ? parent.children.Count : 0);
                            }
                        }
                    }
                }
            }
            else
            {
                AssetInfo assetInfo = CreateAsset(obj.name, parentAssetInfo, insertIndex, folder);
                assetInfo.Object = obj;
                AddAssetToFolder(assetInfo, folder);
            }
            return(true);
        }
Exemple #28
0
        private void AddAssetToFolder(TreeViewItem parent, int insertIndex, UnityObject[] objects, AssetFolderInfo folder, bool moveToNewLocation)
        {
            for (int i = 0; i < objects.Length; ++i)
            {
                UnityObject obj = objects[i];
                if (obj == null || obj.GetType().Assembly.FullName.Contains("UnityEditor"))
                {
                    continue;
                }
                AssetInfo       parentAssetInfo = GetAssetInfo(parent);
                AssetInfo       assetInfo;
                AssetFolderInfo existingFolder;
                AssetInfo       existingAsset;
                if (m_asset.AssetLibrary.TryGetAssetInfo(obj, out existingFolder, out existingAsset))
                {
                    assetInfo = existingAsset;
                    if (!moveToNewLocation)
                    {
                        continue;
                    }

                    AddAssetToFolder(assetInfo, folder);

                    TreeView.treeModel.SetData(GetData());
                    TreeView.Reload();
                }
                else
                {
                    if (m_asset.AssetLibrary.Identity >= AssetLibraryInfo.MAX_ASSETS)
                    {
                        EditorUtility.DisplayDialog("Unable to add asset", string.Format("Max 'Indentity' value reached. 'Identity' ==  {0}", AssetLibraryInfo.MAX_ASSETS), "OK");
                        return;
                    }

                    if (!CreateAsset(obj, parentAssetInfo, insertIndex, folder))
                    {
                        EditorUtility.DisplayDialog("Unable to add asset", string.Format("Max 'Indentity' value reached. 'Identity' ==  {0}", AssetLibraryInfo.MAX_ASSETS), "OK");
                    }
                }
            }
        }
Exemple #29
0
 public void AddAssetToFolder(UnityObject[] objects, AssetFolderInfo folder, bool moveToNewLocation)
 {
     AddAssetToFolder(null, -1, objects, folder, moveToNewLocation);
 }