去掉不必要的依赖
This commit is contained in:
parent
e228240212
commit
64e2e1f8c2
@ -4,7 +4,6 @@ using System.Collections.Generic;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Networking;
|
using UnityEngine.Networking;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Unity.EditorCoroutines.Editor;
|
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
|
||||||
|
|
||||||
@ -80,6 +79,29 @@ namespace AlicizaX.PackageManager.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal class PackageManagerCoroutines : MonoBehaviour
|
||||||
|
{
|
||||||
|
public static PackageManagerCoroutines Coroutines;
|
||||||
|
|
||||||
|
public static void CreateCoroutines()
|
||||||
|
{
|
||||||
|
if (Coroutines == null)
|
||||||
|
{
|
||||||
|
Coroutines = new GameObject("Coroutines").AddComponent<PackageManagerCoroutines>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DestroyCoroutines()
|
||||||
|
{
|
||||||
|
if (Coroutines != null)
|
||||||
|
{
|
||||||
|
Coroutines.StopAllCoroutines();
|
||||||
|
DestroyImmediate(Coroutines.gameObject);
|
||||||
|
Coroutines = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class RepositoryDataFetcher
|
public static class RepositoryDataFetcher
|
||||||
{
|
{
|
||||||
private const string BaseApiUrl = "http://101.34.252.46:3000/api/v1/repos/search?q=unity&topic=false";
|
private const string BaseApiUrl = "http://101.34.252.46:3000/api/v1/repos/search?q=unity&topic=false";
|
||||||
@ -88,22 +110,25 @@ namespace AlicizaX.PackageManager.Editor
|
|||||||
|
|
||||||
public static void FetchRepositoryData(Action<List<RepositoryPackageData>> callback)
|
public static void FetchRepositoryData(Action<List<RepositoryPackageData>> callback)
|
||||||
{
|
{
|
||||||
|
PackageManagerCoroutines.CreateCoroutines();
|
||||||
EditorPrefs.SetString("PackageUpdateDate", DateTime.Now.ToString());
|
EditorPrefs.SetString("PackageUpdateDate", DateTime.Now.ToString());
|
||||||
EditorCoroutineUtility.StartCoroutineOwnerless(FetchDataRoutine(callback));
|
PackageManagerCoroutines.Coroutines.StartCoroutine(FetchDataRoutine(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IEnumerator FetchDataRoutine(Action<List<RepositoryPackageData>> callback)
|
private static IEnumerator FetchDataRoutine(Action<List<RepositoryPackageData>> callback)
|
||||||
{
|
{
|
||||||
|
Debug.Log("Fetching repository data...");
|
||||||
// 第一阶段:获取仓库列表
|
// 第一阶段:获取仓库列表
|
||||||
using (var request = CreateWebRequest(BaseApiUrl))
|
using (var request = CreateWebRequest(BaseApiUrl))
|
||||||
{
|
{
|
||||||
yield return request.SendWebRequest();
|
|
||||||
|
|
||||||
|
yield return request.SendWebRequest();
|
||||||
if (!HandleRequestError(request, "Repository request failed"))
|
if (!HandleRequestError(request, "Repository request failed"))
|
||||||
{
|
{
|
||||||
callback?.Invoke(null);
|
callback?.Invoke(null);
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
Debug.Log(request.downloadHandler.text);
|
||||||
|
|
||||||
var repoResponse = JsonConvert.DeserializeObject<RepoApiResponse>(request.downloadHandler.text);
|
var repoResponse = JsonConvert.DeserializeObject<RepoApiResponse>(request.downloadHandler.text);
|
||||||
if (!repoResponse.ok || repoResponse.data == null)
|
if (!repoResponse.ok || repoResponse.data == null)
|
||||||
@ -123,6 +148,8 @@ namespace AlicizaX.PackageManager.Editor
|
|||||||
var packageData = CreateBaseRepositoryData(repo);
|
var packageData = CreateBaseRepositoryData(repo);
|
||||||
|
|
||||||
var packageUrl = repo.html_url + PackageJsonPath;
|
var packageUrl = repo.html_url + PackageJsonPath;
|
||||||
|
Debug.Log(packageUrl);
|
||||||
|
|
||||||
using (var packageRequest = CreateWebRequest(packageUrl))
|
using (var packageRequest = CreateWebRequest(packageUrl))
|
||||||
{
|
{
|
||||||
yield return packageRequest.SendWebRequest();
|
yield return packageRequest.SendWebRequest();
|
||||||
@ -144,12 +171,10 @@ namespace AlicizaX.PackageManager.Editor
|
|||||||
|
|
||||||
results.Add(packageData);
|
results.Add(packageData);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 防止同时发起太多请求,每帧处理一个
|
|
||||||
yield return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
callback?.Invoke(results);
|
callback?.Invoke(results);
|
||||||
|
PackageManagerCoroutines.DestroyCoroutines();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -46,6 +46,11 @@ namespace AlicizaX.PackageManager.Editor
|
|||||||
GetWindow<FrameworkPackageManagerWindow>().Show();
|
GetWindow<FrameworkPackageManagerWindow>().Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnDestroy()
|
||||||
|
{
|
||||||
|
PackageManagerCoroutines.DestroyCoroutines();
|
||||||
|
}
|
||||||
|
|
||||||
private void CreateGUI()
|
private void CreateGUI()
|
||||||
{
|
{
|
||||||
VisualTreeAsset visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(VisualAssetPath);
|
VisualTreeAsset visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(VisualAssetPath);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user