# Unity3D

通過以下鏈接下載ProudChat Unity SDK。

## :open\_file\_folder: [Unity ProudChat SDK](https://github.com/Nettention/ProudChatSDK/tree/main/ChatClientSDK/Unity)

## 項目設定

### 新增Unity PackageFile

通過git下載的ProudChatUnity Package Unity編輯上端<mark style="color:orange;">Assets</mark> - <mark style="color:orange;">Import Package</mark> - <mark style="color:orange;">custom Package</mark>添加Package 。

<figure><img src="/files/MIq8lx6T75riDH2KQ3kw" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/8tcV4PAFWfCPz98oXvNM" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/XziF6ZpDyERxdcydOAyn" alt=""><figcaption><p>Package File全部導入。</p></figcaption></figure>

### 插件配置

{% hint style="info" %}
請參考[**插件設置**](/proudnet.cn/proudnet/2.setting/unity3d.md#mac)。
{% endhint %}

##

## ProudChatComponent

用戶可以通過<mark style="color:orange;">ProudChatComponent</mark>輕鬆使用聊天所需的各種功能。

{% hint style="danger" %}
請務必只註冊一個Component後使用。
{% endhint %}

### - ProudChat\_Init

進行ChatClient Initialize的部分。 用戶在使用前必須調用Init函數與服務器連接。

<table data-full-width="true"><thead><tr><th width="179">函數名</th><th width="406">參數</th><th>註釋</th></tr></thead><tbody><tr><td>ProudChat_Init</td><td><a href="https://console.nettention.com"><strong>Proud Console</strong></a>提供的<mark style="color:orange;">用戶的UUID</mark>、<mark style="color:orange;">用戶生成的項目的UUID</mark>、<mark style="color:orange;">用戶固有的UniqueID</mark></td><td>用戶將 ChatClient 作爲與服務器連接的函數來編寫此部分 。<br>參數接收三個字符串， 但它們內部調用 <mark style="color:orange;">ChatClientInitComplete</mark>, <mark style="color:orange;">ChatClientJoinFailed</mark> 函數， 可確認登錄成功還是失敗 。</td></tr></tbody></table>

### - 函數

<table data-full-width="true"><thead><tr><th width="217">函數名</th><th width="271">參數</th><th>註釋</th></tr></thead><tbody><tr><td>AddChannel</td><td>您想要訪問的頻道的固有Key</td><td>用於連接特定頻道時 。</td></tr><tr><td>Leave_Channel</td><td>想播出的頻道的固有Key</td><td>想退出連接的頻道時使用。</td></tr><tr><td>Send_Msg</td><td><p>特定對方固有的識別值， </p><p>要發送給特定對象的信息</p></td><td>用於向特定對象發送消息。</td></tr><tr><td>Send_ChannelMsg</td><td>特定渠道的獨特識別值， <br>要發送給特定頻道的消息</td><td>用於向特定頻道發送消息。</td></tr></tbody></table>

### - 事件變數

<table data-full-width="true"><thead><tr><th width="296">事件函數名</th><th>註釋</th></tr></thead><tbody><tr><td>m_ClientInitComplete_Event</td><td><mark style="color:orange;">ChatClient</mark>完成Init後發生的活動，用戶可以註冊使用。<br>實例包括，當調用<mark style="color:orange;">ChatClientInitComplete()</mark>函數時，會發生事件，輸出一個名爲'<strong>ProudChat Connection Success'</strong>的Unity日誌，並添加一個名爲"<strong>ALL</strong>"的通道。</td></tr><tr><td>m_ClientInitFailed_Event</td><td>在<mark style="color:orange;">ChatClient</mark>中成爲Init Failed後發生的事件，用戶可以註冊使用。<br>實例包括，如果調用<mark style="color:orange;">ChatClientJoinFailed()</mark>函數，則會發生事件，失敗時返回錯誤，並顯示"<strong>ProudChat Connection Failed</strong>"日誌。</td></tr><tr><td>m_SendMsg_Response_Event</td><td>用戶間Send Message到達時，會進行活動處理。<br>用戶可以註冊並使用Event，註冊時接收<mark style="color:orange;">產生信息的Unique ID</mark>和<mark style="color:orange;">對方發送的信息</mark>作爲參數。</td></tr><tr><td>m_ChannelMsg_Response_Event</td><td>Channel Message 到達時發生的事件 。<br>用戶可以註冊並使用Event，註冊時<mark style="color:orange;">接收消息通道的Unique ID</mark>、<mark style="color:orange;">產生消息的Unique ID</mark>、<mark style="color:orange;">對方發送的消息</mark>作爲參數。</td></tr><tr><td>m_Notice_Response_Event</td><td>Notice到達時，會進行活動處理。 用戶可以註冊Event使用。<br>示例中通過<mark style="color:orange;">Notice_Response()</mark>在Proud Console發送公告時打印公告內容。</td></tr></tbody></table>

### - 事件函數

<table data-full-width="true"><thead><tr><th width="244">函數名</th><th>註釋</th></tr></thead><tbody><tr><td>ChatClientInitComplete</td><td>完成Server Connection後，成功到Login後被呼叫的函數。</td></tr><tr><td>ChatClientJoinFailed</td><td>Server Login 失敗時調用的一個函數。 <br>使用此函數的時間是連接服務器成功但無法登錄賬戶時發生的事件 。 <br>這部分失敗時不會重試，因此需要確認設置。</td></tr><tr><td>SendMsg_Response</td><td>是其他用戶給我發信息的話，就會變成Delegate的函數。</td></tr><tr><td>ChannelMsg_Response</td><td>另一個用戶向頻道發送消息後成爲Delegate的函數。</td></tr><tr><td>Notice_Response</td><td>ProudConsle發送公告事項時成爲Delegate的函數，從服務器接收Message後打印公告事項內容。</td></tr></tbody></table>

## 構建

### - Android

{% hint style="success" %}
請參閱[**選擇Stripped文件夾中的插件**](/proudnet.cn/proudnet/2.setting/unity3d.md#stripped) 。
{% endhint %}

### - iOS

{% hint style="success" %}
請參考[**iOS的構建**](/proudnet.cn/proudnet/2.setting/unity3d/ios-jian-zhi.md)。
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.proudnet.com/proudnet.cn/proudchat/download/unity3d.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
