Exemplo n.º 1
0
            static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
            {
                if (EditorPrefs.GetBool("UniGit_DisablePostprocess"))
                {
                    return;
                }
                if (GitManager.Repository != null)
                {
                    if (GitManager.Settings != null && GitManager.Settings.AutoStage)
                    {
                        if (importedAssets != null && importedAssets.Length > 0)
                        {
                            string[] importedAssetsToStage = importedAssets.Where(a => !GitManager.IsEmptyFolder(a)).SelectMany(g => GitManager.GetPathWithMeta(g)).Where(g => GitManager.CanStage(GitManager.Repository.RetrieveStatus(g))).ToArray();
                            if (importedAssetsToStage.Length > 0)
                            {
                                GitManager.Repository.Stage(importedAssetsToStage);
                                GitManager.MarkDirty(importedAssetsToStage);
                            }
                        }

                        if (movedAssets != null && movedAssets.Length > 0)
                        {
                            string[] movedAssetsFinal = movedAssets.Where(a => !GitManager.IsEmptyFolder(a)).SelectMany(g => GitManager.GetPathWithMeta(g)).Where(g => GitManager.CanStage(GitManager.Repository.RetrieveStatus(g))).ToArray();
                            if (movedAssetsFinal.Length > 0)
                            {
                                GitManager.Repository.Stage(movedAssetsFinal);
                                GitManager.MarkDirty(movedAssetsFinal);
                            }
                        }
                    }

                    //automatic deletion of previously moved asset is necessary even if AutoStage is off
                    if (movedFromAssetPaths != null && movedFromAssetPaths.Length > 0)
                    {
                        string[] movedFromAssetPathsFinal = movedFromAssetPaths.SelectMany(g => GitManager.GetPathWithMeta(g)).Where(g => GitManager.CanUnstage(GitManager.Repository.RetrieveStatus(g))).ToArray();
                        if (movedFromAssetPathsFinal.Length > 0)
                        {
                            GitManager.Repository.Unstage(movedFromAssetPathsFinal);
                            GitManager.MarkDirty(movedFromAssetPathsFinal);
                        }
                    }

                    //automatic deletion is necessary even if AutoStage is off
                    if (deletedAssets != null && deletedAssets.Length > 0)
                    {
                        string[] deletedAssetsFinal = deletedAssets.SelectMany(g => GitManager.GetPathWithMeta(g)).Where(g => GitManager.CanUnstage(GitManager.Repository.RetrieveStatus(g))).ToArray();
                        if (deletedAssetsFinal.Length > 0)
                        {
                            GitManager.Repository.Unstage(deletedAssetsFinal);
                            GitManager.MarkDirty(deletedAssetsFinal);
                        }
                    }
                }
            }