Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve dependencies using UnityNuGet scoped registry #9

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 47 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,35 @@ Architecture/Platform | Windows | macOS | Linux | Android | iOS
## Installation
### Unity

To install this library, specify the following URL in `Add package from git URL...` of Package Manager on Unity.
> This library depends on the following additional libraries:
>
> - [System.IO.Pipelines](https://www.nuget.org/packages/System.IO.Pipelines) (netstandard2.1)
> - [System.Runtime.CompilerServices.Unsafe](https://www.nuget.org/packages/System.Runtime.CompilerServices.Unsafe) (netstandard2.1)

#### Method 1: using UnityNuGet scope registry

1. Add the [UnityNuget](https://github.com/xoofx/UnityNuGet) scope registry:

```
https://github.com/xoofx/UnityNuGet#add-scope-registry-manifestjson
```

2. Specify the following URL in `Add package from git URL...` of Package Manager on Unity.

```
https://github.com/Cysharp/YetAnotherHttpHandler.git?path=src/YetAnotherHttpHandler#v0.1.0
```

Additionally, this library depends on the following additional libraries.
#### Method 2: without additional scope registries

- [System.IO.Pipelines](https://www.nuget.org/packages/System.IO.Pipelines) (netstandard2.1)
- [System.Runtime.CompilerServices.Unsafe](https://www.nuget.org/packages/System.Runtime.CompilerServices.Unsafe) (netstandard2.1)
1. Please download and install [Cysharp.Net.Http.YetAnotherHttpHandler.Dependencies.unitypackage
from the dependency redistribution on the release page](https://github.com/Cysharp/YetAnotherHttpHandler/releases/tag/redist-20230728-01).

Please download and install [Cysharp.Net.Http.YetAnotherHttpHandler.Dependencies.unitypackage
from the dependency redistribution on the release page](https://github.com/Cysharp/YetAnotherHttpHandler/releases/tag/redist-20230728-01), or obtain the library from NuGet.
2. Specify the following URL in `Add package from git URL...` of Package Manager on Unity.

📦 **Tips:** You can download NuGet packages from the "Download package" link on the right side of the package page on NuGet.org. The downloaded .nupkg file can be opened as a Zip archive, allowing you to extract individual assemblies from the `lib` directory.
```
https://github.com/Cysharp/YetAnotherHttpHandler.git?path=src/YetAnotherHttpHandler#v0.1.0
```

## Usage

Expand All @@ -96,7 +110,7 @@ Create an instance of YetAnotherHttpHandler and pass it to HttpClient.
using Cysharp.Net.Http;

using var handler = new YetAnotherHttpHandler();
var httpCilent = new HttpClient(handler);
var httpClient = new HttpClient(handler);

var result = await httpClient.GetStringAsync("https://www.example.com");
```
Expand All @@ -109,16 +123,32 @@ However, since it does not have features such as connection control by the numbe

### Using gRPC (grpc-dotnet) library

To use grpc-dotnet (Grpc.Net.Client), add the following additional libraries:
> To use grpc-dotnet (Grpc.Net.Client), add the following additional libraries:
>
> - Grpc.Core.Api
> - Grpc.Net.Client
> - Grpc.Net.Common
> - Microsoft.Extensions.Logging.Abstractions
> - System.Buffers
> - System.Diagnostics.DiagnosticSource
> - System.Memory
> - System.Numerics.Vectors

#### Method 1: using UnityNuget scope registry

To use grpc-dotnet (Grpc.Net.Client), add the following additional library to `manifest.json`:

```json
{
"dependencies": {
"org.nuget.grpc.net.client": "{version}"
}
}
```

> Replace `{version}` with the latest version available in NuGet: https://www.nuget.org/packages/Grpc.Net.Client#versions-body-tab

- Grpc.Core.Api
- Grpc.Net.Client
- Grpc.Net.Common
- Microsoft.Extensions.Logging.Abstractions
- System.Buffers
- System.Diagnostics.DiagnosticSource
- System.Memory
- System.Numerics.Vectors
#### Method 2: without additional scope registries

Please download and install [Grpc.Net.Client.Dependencies.unitypackage
from the dependency redistribution on the release page](https://github.com/Cysharp/YetAnotherHttpHandler/releases/tag/redist-20230728-01), or obtain the library from NuGet.
Expand Down
18 changes: 18 additions & 0 deletions src/YetAnotherHttpHandler.Unity/Assets/Editor/Editor.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "Editor",
"rootNamespace": "",
"references": [
"GUID:1ef0bbeee4c5c164fadb7031fd63e223"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,34 +1,67 @@
#if UNITY_EDITOR

using Needle.HybridPackages;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEditor.PackageManager.Requests;

public static class PackageExporter
{
private static ListRequest s_listRequest;

[MenuItem("Tools/Export Unitypackage")]
public static void Export()
{
PackDependencies("Cysharp.Net.Http.YetAnotherHttpHandler.Dependencies", "YetAnotherHttpHandler.deps.txt");
PackDependencies("Grpc.Net.Client.Dependencies", "Grpc.Net.Client.deps.txt");
EditorUtility.DisplayProgressBar("Packges", "Exporting packages, please wait...", 0);

s_listRequest = UnityEditor.PackageManager.Client.List(offlineMode: false, includeIndirectDependencies: true);

EditorApplication.update += OnEditorUpdate;
}

private static void OnEditorUpdate()
{
if (s_listRequest == null || !s_listRequest.IsCompleted)
{
return;
}

EditorApplication.update -= OnEditorUpdate;

ExportPackage("com.cysharp.yetanotherhttphandler", "Cysharp.Net.Http.YetAnotherHttpHandler.Dependencies");
ExportPackage("org.nuget.grpc.net.client", "Grpc.Net.Client.Dependencies");
bdovaz marked this conversation as resolved.
Show resolved Hide resolved

EditorUtility.ClearProgressBar();
}

static void PackDependencies(string unityPackageName, string dependenciesListFileName)
private static void ExportPackage(string packageName, string unityPackageName)
{
Debug.Log($"Creating package '{unityPackageName}'...");
var pluginsDir = Path.Combine(Application.dataPath, "Plugins");
var libraryNames = File.ReadAllLines(Path.Combine(pluginsDir, dependenciesListFileName));
Debug.Log($"Includes library: {string.Join(';', libraryNames)}");

var exportPath = $"./{unityPackageName}.unitypackage";
AssetDatabase.ExportPackage(
libraryNames.Select(x => $"Assets/Plugins/{x}").ToArray(),
exportPath,
ExportPackageOptions.Recurse);

UnityEngine.Debug.Log("Export complete: " + Path.GetFullPath(exportPath));
List<UnityEditor.PackageManager.PackageInfo> dependencies = new();

UnityEditor.PackageManager.PackageInfo packageInfo = s_listRequest.Result.First(p => p.name.Equals(packageName, StringComparison.Ordinal));

GetAllDependencies(packageInfo, dependencies);

string exportPath = $"./{unityPackageName}.unitypackage";

UnitypackageExporter.ExportUnitypackage(dependencies, exportPath);
bdovaz marked this conversation as resolved.
Show resolved Hide resolved

UnityEngine.Debug.Log($"Export complete: {Path.GetFullPath(exportPath)}");
}

private static void GetAllDependencies(UnityEditor.PackageManager.PackageInfo packageInfo, ICollection<UnityEditor.PackageManager.PackageInfo> dependencies)
{
foreach (UnityEditor.PackageManager.DependencyInfo dependency in packageInfo.dependencies)
{
UnityEditor.PackageManager.PackageInfo resolvedPackageInfo = s_listRequest.Result.First(p => p.name.Equals(dependency.name, StringComparison.Ordinal));

dependencies.Add(resolvedPackageInfo);

GetAllDependencies(resolvedPackageInfo, dependencies);
}
}
}

Expand Down
8 changes: 0 additions & 8 deletions src/YetAnotherHttpHandler.Unity/Assets/Plugins.meta

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
Loading