Exemplo n.º 1
0
 static AssetDeleteResult OnWillDeleteAsset(string assetName, RemoveAssetOptions removeAssetOptions)
 {
     if (ProjectCuratorData.IsUpToDate)
     {
         ProjectCurator.RemoveAssetFromDatabase(assetName);
         ProjectCurator.SaveDatabase();
     }
     return(AssetDeleteResult.DidNotDelete);
 }
Exemplo n.º 2
0
 static AssetMoveResult OnWillMoveAsset(string sourcePath, string destinationPath)
 {
     if (ProjectCuratorData.IsUpToDate)
     {
         Actions.Enqueue(() => {
             ProjectCurator.RemoveAssetFromDatabase(sourcePath);
             ProjectCurator.AddAssetToDatabase(destinationPath);
             ProjectCurator.SaveDatabase();
         });
     }
     return(AssetMoveResult.DidNotMove);
 }
Exemplo n.º 3
0
 static string[] OnWillSaveAssets(string[] paths)
 {
     if (ProjectCuratorData.IsUpToDate)
     {
         Actions.Enqueue(() => {
             foreach (string path in paths)
             {
                 ProjectCurator.RemoveAssetFromDatabase(path);
                 ProjectCurator.AddAssetToDatabase(path);
             }
             ProjectCurator.SaveDatabase();
         });
     }
     return(paths);
 }
Exemplo n.º 4
0
        private void OnGUI()
        {
            string selectedPath = AssetDatabase.GetAssetPath(UnityEditor.Selection.activeObject);

            if (string.IsNullOrEmpty(selectedPath))
            {
                return;
            }

            // Standard spacing to mimic Unity's Inspector header
            GUILayout.Space(2);

            Rect rect;

            GUILayout.BeginHorizontal("In BigTitle");
            GUILayout.Label(AssetDatabase.GetCachedIcon(selectedPath), GUILayout.Width(36), GUILayout.Height(36));
            GUILayout.BeginVertical();
            GUILayout.Label(Path.GetFileName(selectedPath), TitleStyle);
            // Display directory (without "Assets/" prefix)
            GUILayout.Label(Regex.Match(Path.GetDirectoryName(selectedPath), "(\\\\.*)$").Value);
            rect = GUILayoutUtility.GetLastRect();
            GUILayout.EndVertical();
            GUILayout.Space(44);
            GUILayout.EndHorizontal();

            if (Directory.Exists(selectedPath))
            {
                return;
            }

            AssetInfo selectedAssetInfo = ProjectCurator.GetAsset(selectedPath);

            if (selectedAssetInfo == null)
            {
                bool rebuildClicked = HelpBoxWithButton(new GUIContent("You must rebuild database to obtain information on this asset", EditorGUIUtility.IconContent("console.warnicon").image), new GUIContent("Rebuild Database"));
                if (rebuildClicked)
                {
                    ProjectCurator.RebuildDatabase();
                }
                return;
            }

            var content = new GUIContent(selectedAssetInfo.IsIncludedInBuild ? ProjectIcons.LinkBlue : ProjectIcons.LinkBlack, selectedAssetInfo.IncludedStatus.ToString());

            GUI.Label(new Rect(position.width - 20, rect.y + 1, 16, 16), content);

            scroll = GUILayout.BeginScrollView(scroll);

            dependenciesOpen = EditorGUILayout.Foldout(dependenciesOpen, $"Dependencies ({selectedAssetInfo.dependencies.Count})");
            if (dependenciesOpen)
            {
                foreach (var dependency in selectedAssetInfo.dependencies)
                {
                    if (GUILayout.Button(Path.GetFileName(dependency), ItemStyle))
                    {
                        UnityEditor.Selection.activeObject = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(dependency);
                    }
                    rect = GUILayoutUtility.GetLastRect();
                    GUI.DrawTexture(new Rect(rect.x - 16, rect.y, rect.height, rect.height), AssetDatabase.GetCachedIcon(dependency));
                    AssetInfo depInfo = ProjectCurator.GetAsset(dependency);
                    content = new GUIContent(depInfo.IsIncludedInBuild ? ProjectIcons.LinkBlue : ProjectIcons.LinkBlack, depInfo.IncludedStatus.ToString());
                    GUI.Label(new Rect(rect.width + rect.x - 20, rect.y + 1, 16, 16), content);
                }
            }

            GUILayout.Space(6);

            referencesOpen = EditorGUILayout.Foldout(referencesOpen, $"Referencers ({selectedAssetInfo.referencers.Count})");
            if (referencesOpen)
            {
                foreach (var referencer in selectedAssetInfo.referencers)
                {
                    if (GUILayout.Button(Path.GetFileName(referencer), ItemStyle))
                    {
                        UnityEditor.Selection.activeObject = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(referencer);
                    }
                    rect = GUILayoutUtility.GetLastRect();
                    GUI.DrawTexture(new Rect(rect.x - 16, rect.y, rect.height, rect.height), AssetDatabase.GetCachedIcon(referencer));
                    AssetInfo refInfo = ProjectCurator.GetAsset(referencer);
                    content = new GUIContent(refInfo.IsIncludedInBuild ? ProjectIcons.LinkBlue : ProjectIcons.LinkBlack, refInfo.IncludedStatus.ToString());
                    GUI.Label(new Rect(rect.width + rect.x - 20, rect.y + 1, 16, 16), content);
                }
            }

            GUILayout.Space(5);

            GUILayout.EndScrollView();

            if (!selectedAssetInfo.IsIncludedInBuild)
            {
                bool deleteClicked = HelpBoxWithButton(new GUIContent("This asset is not referenced and never used. Would you like to delete it ?", EditorGUIUtility.IconContent("console.warnicon").image), new GUIContent("Delete Asset"));
                if (deleteClicked)
                {
                    File.Delete(selectedPath);
                    AssetDatabase.Refresh();
                    ProjectCurator.RemoveAssetFromDatabase(selectedPath);
                }
            }
        }