Beispiel #1
0
        private void OnEnable()
        {
            try
            {
                // reload the NuGet.config file, in case it was changed after Unity opened, but before the manager window opened (now)
                NugetHelper.ForceReloadNugetConfig();

                // set the window title
                titleContent = new GUIContent("Dependencies");

                EditorUtility.DisplayProgressBar("Building Dependency Tree", "Reading installed packages...", 0.5f);

                NugetHelper.UpdateInstalledPackages();
                installedPackages = NugetHelper.InstalledPackages.ToList();
                var installedPackageNames = new List <string>();

                foreach (var package in installedPackages)
                {
                    if (!expanded.ContainsKey(package))
                    {
                        expanded.Add(package, false);
                    }
                    else
                    {
                        //Debug.LogErrorFormat("Expanded already contains {0} {1}", package.Id, package.Version);
                    }

                    installedPackageNames.Add(package.Id);
                }

                installedPackageIds = installedPackageNames.ToArray();

                BuildTree();
            }
            catch (System.Exception e)
            {
                Debug.LogErrorFormat("{0}", e.ToString());
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Draws the preferences GUI inside the Unity preferences window in the Editor.
        /// </summary>
        public static void PreferencesGUI()
        {
            EditorGUILayout.LabelField($"Version: {NuGetForUnityVersion}");

            var conf = NugetHelper.NugetConfigFile;

            EditorGUI.BeginChangeCheck();

            conf.InstallFromCache = EditorGUILayout.Toggle("Install From the Cache", conf.InstallFromCache);

            conf.ReadOnlyPackageFiles = EditorGUILayout.Toggle("Read-Only Package Files", conf.ReadOnlyPackageFiles);

            conf.Verbose = EditorGUILayout.Toggle("Use Verbose Logging", conf.Verbose);

            conf.SavedRepositoryPath = EditorGUILayout.TextField("Packages Directory", conf.SavedRepositoryPath);

            conf.AllowUninstallAll = EditorGUILayout.Toggle("Allow Uninstall All", conf.AllowUninstallAll);

            EditorGUILayout.LabelField("Package Sources:");

            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);

            NugetPackageSource sourceToMoveUp   = null;
            NugetPackageSource sourceToMoveDown = null;
            NugetPackageSource sourceToRemove   = null;

            foreach (var source in conf.PackageSources)
            {
                EditorGUILayout.BeginVertical();
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.BeginVertical(GUILayout.Width(20));
                        {
                            GUILayout.Space(10);
                            source.IsEnabled = EditorGUILayout.Toggle(source.IsEnabled, GUILayout.Width(20));
                        }
                        EditorGUILayout.EndVertical();

                        EditorGUILayout.BeginVertical();
                        {
                            source.Name = EditorGUILayout.TextField(source.Name);

                            EditorGUI.BeginChangeCheck();
                            source.SavedPath = EditorGUILayout.TextField(source.SavedPath);
                            if (EditorGUI.EndChangeCheck())
                            {
                                source.SavedPath = source.SavedPath.Trim();
                            }
                        }
                        EditorGUILayout.EndVertical();
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    {
                        GUILayout.Space(29);
                        EditorGUIUtility.labelWidth = 75;
                        EditorGUILayout.BeginVertical();
                        source.HasPassword = EditorGUILayout.Toggle("Credentials", source.HasPassword);
                        if (source.HasPassword)
                        {
                            source.UserName      = EditorGUILayout.TextField("User Name", source.UserName);
                            source.SavedPassword = EditorGUILayout.PasswordField("Password", source.SavedPassword);
                        }
                        else
                        {
                            source.UserName = null;
                        }
                        EditorGUIUtility.labelWidth = 0;
                        EditorGUILayout.EndVertical();
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    {
                        if (GUILayout.Button("Move Up"))
                        {
                            sourceToMoveUp = source;
                        }

                        if (GUILayout.Button("Move Down"))
                        {
                            sourceToMoveDown = source;
                        }

                        if (GUILayout.Button("Remove"))
                        {
                            sourceToRemove = source;
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.EndVertical();
            }

            if (sourceToMoveUp != null)
            {
                var index = conf.PackageSources.IndexOf(sourceToMoveUp);
                if (index > 0)
                {
                    conf.PackageSources[index]     = conf.PackageSources[index - 1];
                    conf.PackageSources[index - 1] = sourceToMoveUp;
                    GUI.changed = true;
                }
            }

            if (sourceToMoveDown != null)
            {
                var index = conf.PackageSources.IndexOf(sourceToMoveDown);
                if (index < conf.PackageSources.Count - 1)
                {
                    conf.PackageSources[index]     = conf.PackageSources[index + 1];
                    conf.PackageSources[index + 1] = sourceToMoveDown;
                    GUI.changed = true;
                }
            }

            if (sourceToRemove != null)
            {
                conf.PackageSources.Remove(sourceToRemove);
                GUI.changed = true;
            }

            if (GUILayout.Button("Add New Source"))
            {
                conf.PackageSources.Add(new NugetPackageSource("New Source", "source_path"));
                GUI.changed = true;
            }

            EditorGUILayout.EndScrollView();

            if (GUILayout.Button("Reset To Default"))
            {
                NugetConfigFile.CreateDefaultFile(NugetHelper.NugetConfigFilePath);
                NugetHelper.ForceReloadNugetConfig();
                GUI.changed = true;
            }

            if (EditorGUI.EndChangeCheck())
            {
                conf.Save(NugetHelper.NugetConfigFilePath);
            }
        }