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 void OnWillCreateAsset(string assetName)
 {
     if (ProjectCuratorData.IsUpToDate)
     {
         Actions.Enqueue(() => {
             ProjectCurator.AddAssetToDatabase(assetName);
             ProjectCurator.SaveDatabase();
         });
     }
 }
Exemplo n.º 3
0
 static AssetMoveResult OnWillMoveAsset(string sourcePath, string destinationPath)
 {
     if (ProjectCuratorData.IsUpToDate)
     {
         Actions.Enqueue(() => {
             ProjectCurator.RemoveAssetFromDatabase(sourcePath);
             ProjectCurator.AddAssetToDatabase(destinationPath);
             ProjectCurator.SaveDatabase();
         });
     }
     return(AssetMoveResult.DidNotMove);
 }
 private static void ProjectWindowItemOnGUI(string guid, Rect rect)
 {
     if (enabled)
     {
         AssetInfo assetInfo = ProjectCurator.GetAsset(AssetDatabase.GUIDToAssetPath(guid));
         if (assetInfo != null)
         {
             var content = new GUIContent(assetInfo.IsIncludedInBuild ? ProjectIcons.LinkBlue : ProjectIcons.LinkBlack, assetInfo.IncludedStatus.ToString());
             GUI.Label(new Rect(rect.width + rect.x - 20, rect.y + 1, 16, 16), content);
         }
         else
         {
         }
     }
 }
Exemplo n.º 5
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.º 6
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)
            {
                if (selectedPath.StartsWith("Assets"))
                {
                    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();
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("Project Curator ignores assets that are not in the Asset folder.", MessageType.Warning);
                }

                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(new GUIContent(Path.GetFileName(dependency), 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(new GUIContent(Path.GetFileName(referencer), 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);
                }
            }
        }
Exemplo n.º 7
0
        private IncludedInBuild CheckIncludedStatus()
        {
            foreach (var referencer in referencers)
            {
                AssetInfo refInfo = ProjectCurator.GetAsset(referencer);
                if (refInfo.IsIncludedInBuild)
                {
                    return(IncludedInBuild.Referenced);
                }
            }

            bool isInEditor = false;

            string[] directories = path.ToLower().Split('/');
            for (int i = 0; i < directories.Length - 1; i++)
            {
                switch (directories[i])
                {
                case "editor":
                    isInEditor = true;
                    break;

                case "resources":
                    return(IncludedInBuild.ResourceAsset);

                case "plugins":
                    break;

                default:
                    break;
                }
            }

            string extension = System.IO.Path.GetExtension(path);

            switch (extension)
            {
            case ".cs":
                if (isInEditor)
                {
                    return(IncludedInBuild.NotIncludable);
                }
                else
                {
                    return(IncludedInBuild.RuntimeScript);
                }

            case ".unity":
                if (EditorBuildSettings.scenes.Select(x => x.path).Contains(path))
                {
                    return(IncludedInBuild.SceneInBuild);
                }
                break;

            // Todo : Handle DLL
            // https://docs.unity3d.com/ScriptReference/Compilation.Assembly-compiledAssemblyReferences.html
            // CompilationPipeline
            // Assembly Definition
            default:
                break;
            }

            return(IncludedInBuild.NotIncluded);
        }