# Unity3D

如果將ProudNet安裝路徑中的<mark style="color:orange;">lib/Plugins</mark>資料夾和檔案放入Unity專案路徑中的<mark style="color:orange;">Assets/Plugins</mark>中，則ProudNet程式庫將包含在專案中。

詳細流程如下。

## 1. 複製並貼上 plugins

<figure><img src="https://content.gitbook.com/content/hhO5qj4oN2uLfVC5EG5W/blobs/tEOznlDQAm1J2Rw2NLxM/Unity_setting_1.png" alt=""><figcaption><p>進入ProudNet安裝路徑</p></figcaption></figure>

從 ProudNet 安裝路徑複製外掛程式。

<figure><img src="https://content.gitbook.com/content/hhO5qj4oN2uLfVC5EG5W/blobs/2R0k1bxaH6Gf4HGbfnry/Unity_setting_2.png" alt=""><figcaption><p>Unity專案路徑</p></figcaption></figure>

將複製的檔案貼到要使用 ProudNet 的 Unity 專案的 Plugins 資料夾中。

## 2.  插件常用設定

### - x86, x86\_64 插件選擇

{% hint style="info" %}
下圖是使用x86\_64外掛程式刪除x86資料夾的範例。
{% endhint %}

<figure><img src="https://content.gitbook.com/content/hhO5qj4oN2uLfVC5EG5W/blobs/0mDpqV9QNVKNhmJtEViq/Unity_setting_3.png" alt=""><figcaption><p>刪除Unity專案路徑中Plugins資料夾內的x86資料夾。</p></figcaption></figure>

{% hint style="danger" %}
刪除 x86 資料夾，因為如果保留未使用的 x86 資料夾，可能會與 <mark style="color:orange;">x86\_64</mark> 的內容重疊。
{% endhint %}

<figure><img src="https://content.gitbook.com/content/hhO5qj4oN2uLfVC5EG5W/blobs/Y2Sf6dpbLbuA0JtWu0XP/86.png" alt=""><figcaption></figcaption></figure>

<figure><img src="https://content.gitbook.com/content/hhO5qj4oN2uLfVC5EG5W/blobs/e490tCeQxMoesB61fLGJ/64.png" alt=""><figcaption></figcaption></figure>

透過更改 <mark style="color:orange;">x86\_64</mark> 內的插件檔案設定來使用它。

### -  在 Stripped 資料夾中選擇插件

如果你檢查Unity專案中的Plugins資料夾，會發現外掛程式如下圖。 剝離資料夾內的插件和外面的插件是一樣的，只是剝離資料夾內的插件帶有**符號**，兩種插件中只保留自己需要的插件，刪除即可您不使用的插件。

{% hint style="warning" %}
下圖是刪除剝離資料夾以使用不包含符號的插件的範例。
{% endhint %}

{% hint style="danger" %}
如果您不刪除已剝離資料夾中的插件以及外部插件之一，則可能會在建置時出現錯誤。
{% endhint %}

<figure><img src="https://content.gitbook.com/content/hhO5qj4oN2uLfVC5EG5W/blobs/cMSyNNjTXw00X5YhyDib/a-1.png" alt=""><figcaption><p>刪除 libs -> arm64-v8a -> stripped 資料夾。</p></figcaption></figure>

<figure><img src="https://content.gitbook.com/content/hhO5qj4oN2uLfVC5EG5W/blobs/P0c76mQxUTo3j6VVmBmt/a-2.png" alt=""><figcaption><p>刪除 libs ->armeabi-v7a ->stripped 資料夾。</p></figcaption></figure>

<figure><img src="https://content.gitbook.com/content/hhO5qj4oN2uLfVC5EG5W/blobs/6fyUDDvsKepyUPzzvtoz/a-3.png" alt=""><figcaption><p>libs -> x86 -> strippe刪除 libs -> x86 -> stripped 資料夾。</p></figcaption></figure>

## 3. 根據使用環境進行插件設置

### - Mac

<figure><img src="https://content.gitbook.com/content/hhO5qj4oN2uLfVC5EG5W/blobs/APkiCcqz2Yxxhnp6lLu8/plug0.png" alt=""><figcaption><p>Mac - ProudDotNetClientUnity</p></figcaption></figure>

<figure><img src="https://content.gitbook.com/content/hhO5qj4oN2uLfVC5EG5W/blobs/oWdPBC9FXD7SVLbRazA1/plug1.png" alt=""><figcaption><p>Mac - ProudDotNetClientUnity</p></figcaption></figure>

<figure><img src="https://content.gitbook.com/content/hhO5qj4oN2uLfVC5EG5W/blobs/1wEUXwjKte6cgexia1qN/plugin.png" alt=""><figcaption><p>Mac - ProudNetClientPlugin</p></figcaption></figure>

<figure><img src="https://content.gitbook.com/content/hhO5qj4oN2uLfVC5EG5W/blobs/BOJ8e6A3iCwjcpKIssSc/plug_ios.png" alt=""><figcaption><p>Mac - ProudDotNetClientUnity-IOS</p></figcaption></figure>

您可以使用預設設定的其他插件，但對於 iOS，您必須按照上圖所示設定插件。

### - Windows 或 Android

在 Windows 或 Android 環境中，插件設定如下進行。

<figure><img src="https://content.gitbook.com/content/hhO5qj4oN2uLfVC5EG5W/blobs/rFCOerE6lOISuvdJQWNN/win-ios.png" alt=""><figcaption><p>ProudDotNetClientUnity-IOS</p></figcaption></figure>

<figure><img src="https://content.gitbook.com/content/hhO5qj4oN2uLfVC5EG5W/blobs/Mv4AzYWNVxI2yE5uodNV/win-dotnet0.png" alt=""><figcaption><p>Window - ProudDotNetClientUnity</p></figcaption></figure>

<figure><img src="https://content.gitbook.com/content/hhO5qj4oN2uLfVC5EG5W/blobs/aMS8KzXPJ67ByXdU4xub/win-dotnet1.png" alt=""><figcaption><p>Window - ProudDotNetClientUnity</p></figcaption></figure>

<figure><img src="https://content.gitbook.com/content/hhO5qj4oN2uLfVC5EG5W/blobs/Bcx7MELMMOtPbbrmLeoW/win-plugin.png" alt=""><figcaption><p>Window - ProudDotClienPlugin</p></figcaption></figure>

### - WebGL

<mark style="color:orange;">/Assets/Plugins/WebGL</mark>下有<mark style="color:orange;">WebGL</mark>相關的插件。

Unity 將自動識別 <mark style="color:orange;">WebGL</mark> 以使用該插件進行建置。 如果不是<mark style="color:orange;">WebGL</mark>環境，則不應建置包括<mark style="color:orange;">WebGL</mark>在內的其他外掛程式。

如果出&#x73FE;***'XXX' could not be found.***&#x7B49;錯誤，則表示<mark style="color:orange;">WebGL</mark>相關插件沒有正確添加，如果出&#x73FE;***'XXX' already defined.***&#x7B49;錯誤，則表示與其他外掛程式有衝突。

選擇插件並設定要在建置 <mark style="color:orange;">WebGL</mark> 時包含的 <mark style="color:orange;">JSClient.jslib</mark> 和 <mark style="color:orange;">ProudNetClientPlugin-webgl.dll</mark>，如Inspector視窗中所示。

<figure><img src="https://content.gitbook.com/content/hhO5qj4oN2uLfVC5EG5W/blobs/sN3ZHbX84bqn9Gwxm2N2/webgl.png" alt=""><figcaption></figcaption></figure>

<figure><img src="https://content.gitbook.com/content/hhO5qj4oN2uLfVC5EG5W/blobs/syo3E1865hFHIKljslcf/webGL.png" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
為了防止在建立 WebGL 時包含其他插件，請停用任何平台並僅檢查所需的平台。
{% endhint %}

## 4. 創建腳本

<figure><img src="https://content.gitbook.com/content/hhO5qj4oN2uLfVC5EG5W/blobs/GWY0ZYLO0D0FT7wKd8NP/4_1.png" alt=""><figcaption></figcaption></figure>

一切設定完畢後，建立一個腳本來建立 <mark style="color:orange;">NetClient</mark>。

<figure><img src="https://content.gitbook.com/content/hhO5qj4oN2uLfVC5EG5W/blobs/qPQ2F8rqgqyexnDUVp0n/Unity_setting_6_%EC%9B%90%EB%B3%B8.png" alt=""><figcaption><p>用作客戶端的 cs 文件</p></figcaption></figure>

如上例，<mark style="color:orange;">NetClient</mark>可以正常創建，不會出現編譯錯誤。

<figure><img src="https://content.gitbook.com/content/hhO5qj4oN2uLfVC5EG5W/blobs/M3SLOEf7xlZr8qXCOxE8/Unity_setting_7.png" alt=""><figcaption><p>將 GameClient.cs 作為元件加入空遊戲物件的範例</p></figcaption></figure>

您可以使用以這種方式建立的腳本文件，將其作為組件添加到要用作客戶端的遊戲物件中。

## 5. IOS 建置

{% hint style="info" %}
有關 iOS，請參閱 [**iOS 建置**](https://docs.proudnet.com/proudnet.cn/proudnet/2.setting/unity3d/ios-jian-zhi)。
{% endhint %}

***

## :arrow\_left: [返回](https://docs.proudnet.com/proudnet.cn/proudnet/2.setting/..#2.-pidl)
