private void showUnusedAssets()
    {
        EditorGUILayout.Separator();
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Collapse All", GUILayout.Width(200)))
        {
            foreach (ProjectFolderInfo folder in m_ProjectFolderList)
            {
                folder.FoldOut = false;
            }
        }
        if (GUILayout.Button("Expand All", GUILayout.Width(200)))
        {
            foreach (ProjectFolderInfo folder in m_ProjectFolderList)
            {
                folder.FoldOut = true;
            }
        }
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Separator();
        EditorGUILayout.Separator();
        int indentLevel = 0;

        drawAssetFolderInfoRecursively(m_ProjectFolderList[0], indentLevel);

        if (m_assetMarkedForDeletion != null)
        {
            if (EditorUtility.DisplayDialog("Delete asset", "Are you sure you want to delete " + m_assetMarkedForDeletion.m_Name, "Yes", "No"))
            {
                m_assetMarkedForDeletion.Delete(m_unusedTypeDict);
                //Delete potential empty folders
                processDirectory(getSystemFolderPath(m_assetMarkedForDeletion.m_ParentPath));
                m_assetMarkedForDeletion = null;
            }
            else
            {
                m_assetMarkedForDeletion = null;
            }
        }
        else if (m_folderMarkedForDeletion != null)
        {
            if (EditorUtility.DisplayDialog("Delete all child assets", "Are you sure you want to delete all " + m_folderMarkedForDeletion.GetAssetCountInChildren() + " child assets", "Yes", "No"))
            {
                List <AssetObjectInfo> objectsToDelete = new List <AssetObjectInfo>();
                getObjectsMarkedForDeletion(m_folderMarkedForDeletion, ref objectsToDelete);

                deleteSelected(objectsToDelete);
                //Delete potential empty folders
                processDirectory(getSystemFolderPath(m_folderMarkedForDeletion.DirectoryName));
                m_folderMarkedForDeletion = null;
                refreshUnusedAssets();
            }
            else
            {
                m_folderMarkedForDeletion = null;
            }
        }
    }
Example #2
0
 public void Init(SerializeAssetV09 serializeAsset)
 {
     AssetVersion = serializeAsset.header.Version;
     UnityVersion = serializeAsset.UnityVersion;
     ObjectInfos = new AssetObjectInfo[serializeAsset.numOfObjects];
     for (int i = 0; i < serializeAsset.numOfObjects; i++) {
         ObjectInfos[i] = new AssetObjectInfo();
         ObjectInfos[i].PathID = (ulong)serializeAsset.objectInfos[i].PathID;
         ObjectInfos[i].classID = serializeAsset.objectInfos[i].classID;
         ObjectInfos[i].typeID = serializeAsset.objectInfos[i].typeID;
         ObjectInfos[i].isDestroyed = serializeAsset.objectInfos[i].isDestroyed == 1;
         ObjectInfos[i].length = serializeAsset.objectInfos[i].length;
         ObjectInfos[i].data = serializeAsset.objectInfos[i].data;
     }
     ExternalFiles = new FileIdentifier[serializeAsset.numOfFileIdentifiers];
     for (int i = 0; i < serializeAsset.numOfFileIdentifiers; i++) {
         ExternalFiles[i] = new FileIdentifier();
         ExternalFiles[i].filePath = serializeAsset.fileIdentifiers[i].filePath;
     }
 }
Example #3
0
 public void Init(SerializeAssetV09 serializeAsset)
 {
     AssetVersion = serializeAsset.header.Version;
     UnityVersion = serializeAsset.UnityVersion;
     ObjectInfos  = new AssetObjectInfo[serializeAsset.numOfObjects];
     for (int i = 0; i < serializeAsset.numOfObjects; i++)
     {
         ObjectInfos[i]             = new AssetObjectInfo();
         ObjectInfos[i].PathID      = (ulong)serializeAsset.objectInfos[i].PathID;
         ObjectInfos[i].classID     = serializeAsset.objectInfos[i].classID;
         ObjectInfos[i].typeID      = serializeAsset.objectInfos[i].typeID;
         ObjectInfos[i].isDestroyed = serializeAsset.objectInfos[i].isDestroyed == 1;
         ObjectInfos[i].length      = serializeAsset.objectInfos[i].length;
         ObjectInfos[i].data        = serializeAsset.objectInfos[i].data;
     }
     ExternalFiles = new FileIdentifier[serializeAsset.numOfFileIdentifiers];
     for (int i = 0; i < serializeAsset.numOfFileIdentifiers; i++)
     {
         ExternalFiles[i]          = new FileIdentifier();
         ExternalFiles[i].filePath = serializeAsset.fileIdentifiers[i].filePath;
     }
 }
Example #4
0
    private void drawAssetFolderInfoRecursively(ProjectFolderInfo assetFolder, int indentLevel)
    {
        EditorGUI.indentLevel = indentLevel;

        if (!assetFolder.ShouldBeListed(m_unusedTypeDict))
        {
            return;
        }
        else
        {
            int assetCount = assetFolder.GetAssetCountInChildren();
            EditorGUILayout.BeginHorizontal();

            Color initialColor = GUI.color;
            GUI.color = Color.yellow;
            float buttonSizeSelect = 60;
            float buttonSizeDelete = 100;

            if (GUILayout.Button("Delete all " + assetCount, GUILayout.Width(buttonSizeDelete)))
            {
                m_folderMarkedForDeletion = assetFolder;
            }

            //Add space to align UI elements
            GUILayout.Space(buttonSizeSelect);

            //Create new style to have a bold foldout
            GUIStyle  style         = EditorStyles.foldout;
            FontStyle previousStyle = style.fontStyle;
            style.fontStyle = FontStyle.Bold;

            //Show foldout
            assetFolder.FoldOut = EditorGUILayout.Foldout(assetFolder.FoldOut, assetFolder.DirectoryName + " (" + assetCount + ")", style);

            //Reset style
            style.fontStyle = previousStyle;

            //Reset color
            GUI.color = initialColor;

            EditorGUILayout.EndHorizontal();
            if (assetFolder.FoldOut)
            {
                foreach (AssetObjectInfo aInfo in assetFolder.AssetList)
                {
                    if ((m_unusedTypeDict.ContainsKey(aInfo.m_Type) && m_unusedTypeDict[aInfo.m_Type] == false))
                    {
                        continue;
                    }

                    EditorGUI.indentLevel = (indentLevel + 1);
                    EditorGUILayout.BeginHorizontal();
                    GUI.color = Color.grey;
                    if (GUILayout.Button("Delete", GUILayout.Width(buttonSizeDelete)))
                    {
                        m_assetMarkedForDeletion = aInfo;
                    }
                    GUI.color = initialColor;
                    if (GUILayout.Button("Select", GUILayout.Width(buttonSizeSelect)))
                    {
                        Selection.activeObject = AssetDatabase.LoadAssetAtPath(aInfo.m_Path, aInfo.m_Type.SystemType);
                    }

                    EditorGUILayout.LabelField(aInfo.m_Name, GUILayout.MaxWidth(600));
                    EditorGUILayout.EndHorizontal();
                }

                foreach (int childFolder in assetFolder.ChildFolderIndexers)
                {
                    drawAssetFolderInfoRecursively(m_ProjectFolderList[childFolder], (indentLevel + 1));
                }
            }
        }
    }
    /*private void OnUnusedScriptsUIUpdate()
     * {
     *  if (m_UsedScriptList == null || m_UsedScriptList.Count <= 0)
     *      return;
     *
     *  scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
     *  EditorGUILayout.BeginVertical();
     *
     *  EditorGUILayout.LabelField("List of unused scripts", EditorStyles.boldLabel);
     *  showUnusedScriptsUI();
     *
     *  EditorGUILayout.EndVertical();
     *  EditorGUILayout.EndScrollView();
     * }*/

    /*private void showUnusedScriptsUI()
     * {
     *
     *  //TODO
     *  //HERE IS A WAY TO FIND ALL CLASSES, Used, and Unused
     *  //http://answers.unity3d.com/questions/30382/editor-assembly.html
     *
     *  foreach (Type t in m_UnusedScriptList)
     *  {
     *      GUILayout.BeginHorizontal();
     *      MonoScript script = null;
     *
     *      if (GUILayout.Button(t.ToString(), GUILayout.Width(btnMinWidth * 2 + 14)))
     *      {
     *          MonoScript[] scripts = (MonoScript[])Resources.FindObjectsOfTypeAll(typeof(MonoScript));
     *          foreach (MonoScript m in scripts)
     *          {
     *              if (m.GetClass() == t)
     *                  script = m;
     *          }
     *          Selection.activeObject = script;
     *      }
     *      GUILayout.EndHorizontal();
     *  }
     * }*/

    #endregion

    private void showUnusedAssets()
    {
        EditorGUILayout.Separator();
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Collapse All", GUILayout.Width(btnMinWidth)))
        {
            foreach (ProjectFolderInfo folder in m_ProjectFolderList)
            {
                folder.FoldOut = false;
            }
        }

        EditorGUILayout.Space();

        if (GUILayout.Button("Expand All", GUILayout.Width(btnMinWidth)))
        {
            foreach (ProjectFolderInfo folder in m_ProjectFolderList)
            {
                folder.FoldOut = true;
            }
        }
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Separator();
        EditorGUILayout.Separator();
        int indentLevel = 0;

        drawAssetFolderInfoRecursively(m_ProjectFolderList[0], indentLevel);

        if (m_assetMarkedForDeletion != null)
        {
            if (EditorUtility.DisplayDialog("Delete asset", "Are you sure you want to delete " + m_assetMarkedForDeletion.m_Name, "Yes", "No"))
            {
                m_assetMarkedForDeletion.Delete(m_unusedTypeDict);
                //Delete potential empty folders
                int deleteCount = 0;
                deleteEmptyDirectories(getSystemFolderPath(m_assetMarkedForDeletion.m_ParentPath), ref deleteCount);
                m_assetMarkedForDeletion = null;
            }
            else
            {
                m_assetMarkedForDeletion = null;
            }
        }
        else if (m_folderMarkedForDeletion != null)
        {
            int dialogChoice = EditorUtility.DisplayDialogComplex(
                "Clean all assets in folder",
                "You can delete all assets below this folder, or you can choose to make a backup first. That will create a unitypackage with all your deleted assets, but it will be slow",
                "Delete all",
                "Backup and delete (Slow!)",
                "Cancel");

            switch (dialogChoice)
            {
            //Normal delete
            case 0:
                deleteAllInFolder(m_folderMarkedForDeletion, false);
                break;

            //Delete with backup
            case 1:
                deleteAllInFolder(m_folderMarkedForDeletion, true);
                break;

            //Cancel
            case 2:
                m_folderMarkedForDeletion = null;
                break;

            default:
                Debug.LogError("Unrecognized option.");
                break;
            }
        }
    }
    //run Time usage
    public bool ReadAssetBundleInfo(string fileText)
    {
        ClearData();

        try
        {
            string[] block = fileText.Split(new string[]{"<<Version>>", "<<AssetInfo>>", "<<PackInfo>>"}, System.StringSplitOptions.RemoveEmptyEntries );
            version = System.Convert.ToInt32( block[0] );

            if(block.Length > 1)
            {
                string[] dataSet = block[1].Split('#');
                foreach(string s in dataSet){
                    string[] values = s.Split(',');
                    AssetBundleInfo info = new AssetBundleInfo();
                    info.Name = values[0];
                    info.version = System.Convert.ToInt32( values[1] );
                    AssetBundleInfos.Add(info.Name, info);
                    //Debug.LogError("assetbundle :" + info.Name + " " + info.version.ToString());
                }
            }

            if(block.Length > 2)
            {
                string[] dataSet = block[2].Split('#');
                foreach(string s in dataSet){
                    string[] values = s.Split(',');
                    AssetObjectInfo info = new AssetObjectInfo();
                    info.Name = values[0];
                    string packNames = values[1];
                    foreach(string pks in packNames.Split('+')){
                        info.PackName.Add(pks);
                    }
                    info.version = System.Convert.ToInt32( values[2] );
                    info.MD5 = values[3];
                    AssetObjectInfos.Add(info.Name, info);
                    foreach(string packname in info.PackName){
                        AssetBundleInfos[packname].objs.Add(info.Name);
                    }
                }
            }
        }
        catch(System.Exception e)
        {
            Debug.LogError( "local assetinfo format error" );
            return false;
        }

        return true;
    }
    public void AddAssetObjectInfo(string ObjectName, string PackName, Object obj)
    {
        AssetBundleInfoData.AssetObjectInfo info = null;
        if(AssetObjectInfos.ContainsKey(ObjectName))
            info = AssetObjectInfos[ObjectName];
        else
            info = new AssetObjectInfo();
        info.Name = ObjectName;
        info.PackName.Add(PackName);
        info.obj = obj;
        info.MD5 = GetMD5HashFromFile( AssetDatabase.GetAssetPath(obj) );

        if(AssetObjectInfos.ContainsKey(ObjectName)){
            if(AssetObjectInfos[ObjectName].obj != obj){
                Debug.LogError( "Adding different object with the same name " + info.Name + " to Assetbundle builder, please try different name. ");
                return;
            }
        }
        else
            AssetObjectInfos.Add(ObjectName, info);

        if(System.String.IsNullOrEmpty(PackName)){
            AssetBundleInfo Ainfo = new AssetBundleInfo();
            Ainfo.Name = info.Name;
            Ainfo.objs.Add(info.Name);
            AssetBundleInfos.Add(Ainfo.Name, Ainfo);
        }
        else{
            if(AssetBundleInfos.ContainsKey(PackName)){
                AssetBundleInfos[PackName].objs.Add(ObjectName);
            }
            else{
                AssetBundleInfo Ainfo = new AssetBundleInfo();
                Ainfo.Name = PackName;
                Ainfo.objs.Add(info.Name);
                AssetBundleInfos.Add(Ainfo.Name, Ainfo);
            }
        }
    }
 public bool Equals(AssetObjectInfo info)
 {
     return (MD5 == info.MD5);
 }