void onClick_SelectVersions() { SetPhase(Phase.SelectVersion); var menu = new GenericMenu(); var currentRefName = versionSelectButton.text; GenericMenu.MenuFunction2 callback = (x) => { var splited = x as string[]; versionSelectButton.text = splited[0]; packageNameLabel.text = splited[1]; refName = splited[2]; SetPhase(Phase.InstallPackage); }; var orderdVers = versions .OrderByDescending(x => x.Split(',')[1]).ToArray(); foreach (var t in orderdVers) { var splited = t.Split(','); var refName = splited[0]; var version = splited[1]; var packageName = splited[2]; var text = version == refName ? version : version + " - " + refName; var packageId = string.Format("{0}@{1}#{2}", packageName, PackageUtils.GetRepoUrl(repoUrlText.value), refName); menu.AddItem(new GUIContent(text), currentRefName == text, callback, new[] { text, packageName, refName }); } menu.DropDown(versionSelectButton.worldBound); }
void onClick_InstallPackage() { root.SetEnabled(false); var url = PackageUtils.GetRepoUrl(repoUrlText.value); var _packageId = string.Format("{0}@{1}#{2}", packageNameLabel.text, url, versionSelectButton.text); PackageUtils.AddPackage(_packageId, req => { root.SetEnabled(true); if (req.Status == StatusCode.Success) { onClick_Close(); } else if (req.Status == StatusCode.Failure) { installPackageError.tooltip = req.Error.message; installPackageError.visible = true; } }); }
void OnGUI() { EditorGUIUtility.labelWidth = 100; using (var ds = new EditorGUI.DisabledScope(PackageUtils.isBusy)) { using (var ccs = new EditorGUI.ChangeCheckScope()) using (new EditorGUILayout.HorizontalScope()) { GUI.SetNextControlName("Repogitory URL"); _url = EditorGUILayout.TextField("Repogitory URL", _url); if (!_focused) { EditorGUI.FocusTextInControl("Repogitory URL"); _focused = true; } if (ccs.changed) { _repoUrl = PackageUtils.GetRepoUrl(_url); _version = "-- Select Version --"; _packageId = ""; GitUtils.GetRefs(_url, _refs, () => { EditorApplication.delayCall += Repaint; }); } if (!PackageUtils.isBusy && !string.IsNullOrEmpty(_url) && _refs.Count == 0) { GUILayout.Label(_errorUrl, GUILayout.Width(20)); } } using (new EditorGUILayout.HorizontalScope()) { EditorGUILayout.PrefixLabel("Version"); using (new EditorGUI.DisabledScope(_refs.Count == 0)) { if (GUILayout.Button(_version, EditorStyles.popup)) { PopupVersions(ver => { _version = _refs.Contains(ver) ? ver : "HEAD"; _packageId = ""; GitUtils.GetPackageJson(_url, _version, name => { _packageId = string.IsNullOrEmpty(name) ? null : name + "@" + _repoUrl + "#" + _version; EditorApplication.delayCall += Repaint; }); }); } } using (new EditorGUI.DisabledScope(string.IsNullOrEmpty(_packageId))) { if (GUILayout.Button(new GUIContent("Add", "Add a package '" + _packageId + "' to the project."), EditorStyles.miniButton, GUILayout.Width(60))) { PackageUtils.AddPackage(_packageId, req => { if (req.Status == StatusCode.Success) { Close(); } }); } } if (_packageId == null) { GUILayout.Label(_errorBranch, GUILayout.Width(20)); } } } }