Skip to content

Commit

Permalink
Merge pull request #926 from Cysharp/feature/UpdateDocs25021301
Browse files Browse the repository at this point in the history
Update docs
  • Loading branch information
mayuki authored Feb 13, 2025
2 parents 71f8fc9 + 5aa85c2 commit 931b118
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 2 deletions.
104 changes: 103 additions & 1 deletion docs/docs/quickstart-unity.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,72 @@ This guide assumes the following environment to create a server and client:
Some versions of Unity 6 have issues with Source Generator, so use 6000.0.34f1 or later.
:::


## Use a pre-configured template (optional)
This guide shows how to create a project, install packages, and other steps. You can get a template in the completed state of this guide from the [MagicOnion.Template.Unity](https://github.com/Cysharp/MagicOnion.Template.Unity) repository.

You can start development using the template by downloading the repository as an archive file from GitHub or by creating a repository from the GitHub template. For more information, see [How to create a repository from a template on GitHub](https://docs.github.com/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template).

<details>
<summary>How to use the template</summary>

This template based on the "Universal 3D" template using Unity 6000.0.36f1.

### How to set up

You can download the archive file from GitHub and extract it, or create a repository from the GitHub template feature. The following is an example command to extract the template to the `MyApp` directory.

<Tabs groupId="shell">
<TabItem value="cmd" label="Windows (cmd.exe)" default>
```bash
mkdir MyApp
cd MyApp
curl.exe -L -o - https://github.com/Cysharp/MagicOnion.Template.Unity/archive/refs/heads/main.tar.gz | tar xz -C . --strip-component 1
```
</TabItem>
<TabItem value="pwsh" label="Windows (PowerShell)" default>
```powershell
mkdir MyApp
cd MyApp
curl.exe -L -o - https://github.com/Cysharp/MagicOnion.Template.Unity/archive/refs/heads/main.tar.gz | tar xz -C . --strip-component 1
```
</TabItem>
<TabItem value="unix-shell" label="Bash, zsh">
```bash
mkdir MyApp
cd MyApp
curl -L -o - https://github.com/Cysharp/MagicOnion.Template.Unity/archive/refs/heads/main.tar.gz | tar xz -C . --strip-component 1
```
</TabItem>
</Tabs>

After extracting the source code, run `init.cmd` or `init.sh` with an arbitrary project name (e.g., `MyApp`). This script performs preparation such as renaming projects and files in the repository root.

<Tabs groupId="shell">
<TabItem value="cmd" label="Windows (cmd.exe)" default>
```bash
init.cmd MyApp
```
</TabItem>
<TabItem value="pwsh" label="Windows (PowerShell)" default>
```bash
init.cmd MyApp
```
</TabItem>
<TabItem value="unix-shell" label="Bash, zsh">
```bash
bash init.sh MyApp
```
</TabItem>
</Tabs>

After running the script, you can delete `init.sh` and `init.cmd` and `tools/RepoInitializer` that actually perform the rewriting process.

### License
The repository is provided under the [CC0 - Public Domain](https://creativecommons.org/publicdomain/zero/1.0/) license.

</details>

## Setup the projects

First, create a .NET server and Unity client, and a project to share code between them. The .NET server is created as a solution (`.sln`) and project (`.csproj`) like a typical .NET application, and the Unity client is created as a Unity project from Unity Hub.
Expand Down Expand Up @@ -42,7 +108,7 @@ First, create a .NET server and shared library project. Here, we will create an

You can create a solution, server project, and shared library project, and add MagicOnion-related packages and references between projects at once by running the following command:

<Tabs>
<Tabs groupId="shell">
<TabItem value="cmd" label="Windows (cmd.exe)" default>
```cmd
Set MO_PROJECT_NAME=MyApp
Expand Down Expand Up @@ -595,6 +661,42 @@ Enter Play mode in the Unity Editor to call the `Start` method, connect to the s
- `IOException: client error (Connect): invalid peer certificate: UnknownIssuer`
- This error occurs when trying to connect to `https://...`. This error occurs because the development certificate is not recognized. Connect using `http://...` (be careful with the port number).


## Integrate Unity and .NET server solutions

When you open C# code or projects from Unity Editor in a development environment such as Visual Studio or Rider, the solution generated by Unity Editor is opened (e.g., `MyApp.Unity.sln`). However, the .NET server project is not included in the solution generated by Unity Editor, so you need to open a separate solution (e.g., `MyApp.sln`) for server development and debugging.

Using the [SlnMerge](https://github.com/Cysharp/SlnMerge) editor extension, you can integrate the Unity and .NET server solutions to enable seamless development.

![](/img/docs/fig-quickstart-unity-slnmerge.png)

### Install SlnMerge

To install SlnMerge, specify the following URL in the Package Manager's `Add package from git URL...`:

```plaintext
https://github.com/Cysharp/SlnMerge.git?path=src
```

![](/img/docs/fig-quickstart-unity-upm-slnmerge.png)

### Configure SlnMerge

After installing SlnMerge, you need to create a SlnMerge configuration for the integration of solutions.
You need to create a configuration file with the name of the Unity Editor-generated solution file with `.mergesettings` appended.

For example, if you have `MyApp.Unity` project, `MyApp.Unity.sln` will be generated, so create a configuration file named `MyApp.Unity.sln.mergesettings`.

```xml title="src/MyApp.Unity/MyApp.Unity.sln.mergesettings"
<SlnMergeSettings>
<MergeTargetSolution>..\..\MyApp.sln</MergeTargetSolution>
</SlnMergeSettings>
```

### Open the solution

To open the solution, double-click the C# file in the Unity Editor or select `Assets``Open C# Project` from the menu.

## Related resources
- [Works with Unity](/installation/unity): Setting up MagicOnion in Unity
- [Project structure](/fundamentals/project-structure): A guide to the project structure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,72 @@ import TabItem from '@theme/TabItem';
Unity 6 の一部バージョンでは Source Generator に関する不具合があるため 6000.0.34f1 以降を使用してください
:::

## セットアップ済みテンプレートを使用する (オプション)
このガイドではプロジェクトの作成やパッケージのインストールといった手順を解説しています。この手順を完了した状態のテンプレートを [MagicOnion.Template.Unity](https://github.com/Cysharp/MagicOnion.Template.Unity) リポジトリから取得できます。

テンプレートを使用した開発は GitHub からリポジトリをアーカイブファイルとしてダウンロードするか、[GitHub のテンプレートからリポジトリーを作成する方法](https://docs.github.com/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template)で開始できます。

<details>
<summary>テンプレートを使用する手順</summary>

このテンプレートの Unity プロジェクトは Unity 6000.0.36f1 を使用した "Universal 3D" テンプレートをベースとしています。

### 使用方法

GitHub からアーカイブファイルをダウンロードして展開するか、GitHub のテンプレート機能からリポジトリーを作成してください。下記は `MyApp` ディレクトリーにテンプレートを展開するコマンド例です。

<Tabs groupId="shell">
<TabItem value="cmd" label="Windows (cmd.exe)" default>
```bash
mkdir MyApp
cd MyApp
curl.exe -L -o - https://github.com/Cysharp/MagicOnion.Template.Unity/archive/refs/heads/main.tar.gz | tar xz -C . --strip-component 1
```
</TabItem>
<TabItem value="pwsh" label="Windows (PowerShell)" default>
```powershell
mkdir MyApp
cd MyApp
curl.exe -L -o - https://github.com/Cysharp/MagicOnion.Template.Unity/archive/refs/heads/main.tar.gz | tar xz -C . --strip-component 1
```
</TabItem>
<TabItem value="unix-shell" label="Bash, zsh">
```bash
mkdir MyApp
cd MyApp
curl -L -o - https://github.com/Cysharp/MagicOnion.Template.Unity/archive/refs/heads/main.tar.gz | tar xz -C . --strip-component 1
```
</TabItem>
</Tabs>

ソースコードを手元に用意した後、リポジトリールートに含まれる `init.cmd` または `init.sh` に任意のプロジェクト名 (例 `MyApp` など) 指定して実行してください。このスクリプトはリポジトリのプロジェクトやファイルのリネームなどの準備処理を行います。

<Tabs groupId="shell">
<TabItem value="cmd" label="Windows (cmd.exe)" default>
```bash
init.cmd MyApp
```
</TabItem>
<TabItem value="pwsh" label="Windows (PowerShell)" default>
```bash
init.cmd MyApp
```
</TabItem>
<TabItem value="unix-shell" label="Bash, zsh">
```bash
bash init.sh MyApp
```
</TabItem>
</Tabs>

実行後は `init.sh` および `init.cmd`、実際の書き換え処理を行う `tools/RepoInitializer` を削除できます。

### ライセンス
テンプレートは [CC0 - パブリックドメイン](https://creativecommons.org/publicdomain/zero/1.0/) で提供されます。

</details>


## プロジェクトの準備

まず初めに .NET サーバーと Unity クライアント、そしてそれらでコードを共有するためのプロジェクトを作成します。.NET サーバーは一般的な .NET アプリケーションと同様にソリューション (`.sln`) とプロジェクト (`.csproj`) を作成し、Unity クライアントは Unity Hub から Unity プロジェクトとして作成します。
Expand Down Expand Up @@ -42,7 +108,7 @@ Unity 6 の一部バージョンでは Source Generator に関する不具合が

下記のコマンドを実行することでソリューション、サーバープロジェクト、共有ライブラリープロジェクトの作成とMagicOnion 関連のパッケージの参照、プロジェクト間の参照設定を一度に行えます。

<Tabs>
<Tabs groupId="shell">
<TabItem value="cmd" label="Windows (cmd.exe)" default>
```cmd
Set MO_PROJECT_NAME=MyApp
Expand Down Expand Up @@ -594,6 +660,43 @@ Unity Editor で Play モードに入ることで `Start` メソッドが呼び
- `IOException: client error (Connect): invalid peer certificate: UnknownIssuer`
- `https://` に接続しようとしてる場合に発生するエラーです。開発向け証明書を認識できないため発生します。`http://...` で接続してください(その際ポート番号には注意してください)。

## Unity と .NET サーバーのソリューションを統合する

Unity Editor から C# コードやプロジェクトを Visual Studio や Rider など開発環境で開くと、Unity Editor の生成したソリューションが開かれます (例:`MyApp.Unity.sln`)。

しかし Unity Editor の生成されたソリューションには .NET サーバーのプロジェクトが含まれていないため、サーバーの開発やデバッグ実行を行うためには別途ソリューション (例:`MyApp.sln`)を開く必要があります。
[SlnMerge](https://github.com/Cysharp/SlnMerge) エディター拡張を使用すると Unity と .NET サーバーのソリューションを統合し、シームレスな開発が行えるようになります。

![](/img/docs/fig-quickstart-unity-slnmerge.png)

### SlnMerge のインストール

SlnMerge をインストールするには Package Manager の `Add package from git URL...` に下記の URL を指定します。

```plaintext
https://github.com/Cysharp/SlnMerge.git?path=src
```

![](/img/docs/fig-quickstart-unity-upm-slnmerge.png)

### SlnMerge の設定

SlnMerge をインストールした後、ソリューションの統合について SlnMerge の設定を作成する必要があります。
SlnMerge の設定は Unity Editor の生成するソリューションファイル名の `.mergesettings` を付けた名前のファイルを作成します。

これは例えば `MyApp.Unity` プロジェクトであれば `MyApp.Unity.sln` が生成されるので、`MyApp.Unity.sln.mergesettings` という名前で設定ファイルを作成します。

```xml title="src/MyApp.Unity/MyApp.Unity.sln.mergesettings"
<SlnMergeSettings>
<MergeTargetSolution>..\..\MyApp.sln</MergeTargetSolution>
</SlnMergeSettings>
```

### ソリューションを開く

ソリューションを開くには Unity Editor から C# ファイルを選択してダブルクリックで開くか、メニューの `Assets``Open C# Project` を選択してください。


## 関連リソース
- [Unity での利用](/installation/unity): Unity でのセットアップ手順
- [プロジェクト構成](/fundamentals/project-structure): Unity と .NET のプロジェクト構成について
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 931b118

Please sign in to comment.