<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by YUNJU on Medium]]></title>
        <description><![CDATA[Stories by YUNJU on Medium]]></description>
        <link>https://medium.com/@YUNJU?source=rss-ce8079bb57ed------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*VdyXmKUmARaD3am-_bovMQ.png</url>
            <title>Stories by YUNJU on Medium</title>
            <link>https://medium.com/@YUNJU?source=rss-ce8079bb57ed------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 01:13:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@YUNJU/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Jetpack Compose 筆記 (二) - 狀態管理]]></title>
            <link>https://medium.com/@YUNJU/jetpack-compose-%E7%AD%86%E8%A8%98-%E4%BA%8C-%E7%8B%80%E6%85%8B%E7%AE%A1%E7%90%86-c98ca1aaa3f0?source=rss-ce8079bb57ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/c98ca1aaa3f0</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[YUNJU]]></dc:creator>
            <pubDate>Thu, 04 May 2023 09:11:57 GMT</pubDate>
            <atom:updated>2023-05-11T01:40:26.073Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*DhXDLXCnZaMHAYVy" /><figcaption>Jetpack Compose Status</figcaption></figure><p>本文同步刊登至：<a href="https://www.yunserve.dev/jetpack-compose-note-status/">Jetpack Compose 筆記 (二) — 狀態管理</a></p><pre>@OptIn(ExperimentalMaterial3Api::class)<br>@Composable<br>fun HelloContent() {<br>    Column(modifier = Modifier.padding(16.dp)) {<br>        Text(<br>            text = &quot;Hello&quot;,<br>            modifier = Modifier.padding(bottom = 8.dp),<br>            style = MaterialTheme.typography.bodyMedium<br>        )<br>        OutlinedTextField(<br>            value = &quot;&quot;,<br>            onValueChange = {},<br>            label = { Text(&quot;Name&quot;) }<br>        )<br>    }<br>}</pre><p>上面這一個段程式目前執行起來，將沒有任何的作用，輸入欄位也無法輸入，但其實這樣的狀況並不是無法輸入，而是 value 的數值並不會自動的更改，它會在 value 的數值變更後自動的重組 UI。所以我們這邊就會需要建立一個表示該狀態的值，然後再 onValueChange 事件當中去更新我們的值。</p><pre>// by 委派需要 import 以下<br>import androidx.compose.runtime.getValue<br>import androidx.compose.runtime.setValue<br><br>@OptIn(ExperimentalMaterial3Api::class)<br>@Composable<br>fun HelloContent() {<br>    Column(modifier = Modifier.padding(16.dp)) {<br><br>        var name: String by remember { mutableStateOf(&quot;&quot;) }<br><br>        Text(<br>            text = &quot;Hello&quot;,<br>            modifier = Modifier.padding(bottom = 8.dp),<br>            style = MaterialTheme.typography.bodyMedium<br>        )<br>        OutlinedTextField(<br>            value = name,<br>            onValueChange = { name = it },<br>            label = { Text(&quot;Name&quot;) }<br>        )<br>    }<br>}</pre><p>這裡使用 MutableStateOf 建立一個可變狀態，它是 Compose 中的一種可觀察類型，對於該值做任何的修改，都將對於讀取該值的 Composable 進行重組作業，而 remember 的作用在於重組時保留該值狀態，若沒有 remember 每次重組時，都將初始化成空字串狀態。</p><blockquote>雖然 remember 可協助您在各次重組間保留狀態，但只要設定有所變更，狀態就無法保留。針對這種情況，您必須使用 rememberSaveable。rememberSaveable 會自動儲存可儲存在 Bundle 中的任何值。其他值可在自訂儲存器物件中傳送。</blockquote><h3>狀態提升</h3><p>在說明狀態提升前，先談談有狀態及無狀態，上面的 HelloContent 這個 Composable 是屬於有狀態的組合項，利用了 remember 在內部來保留 name 的狀態。這樣的優點是當呼叫端不需要管理狀態也可以使用，但缺點是不易重覆使用，以及難以測試。</p><p>而無狀態的組合項指的是不含任何狀態的 Composable，達成無狀態的方式就是使用狀態提升。</p><blockquote>開發可重複使用的可組合項時，通常會想同時提供有狀態和無狀態的版本。有狀態版本對於不考慮狀態的呼叫端來說很方便，而對於需要控制或提升狀態的呼叫端來說，則一定要使用無狀態版本。</blockquote><p>Jetpack Compose 中最常使用的狀態提升是將狀態變數替換成兩個參數</p><ul><li>value: T ：目前顯示的數值</li><li>onValueChange: (T) -&gt; Unit<strong>：</strong>要求變更值的事件，其中 T 是提議的新值</li></ul><p>以下是官方說明這種方式的重要屬性</p><ul><li><strong>單一真實資訊來源</strong>：採用移動而非複製的方式處理狀態，以確保真實資訊來源只有一個。這有助於避免錯誤。</li><li><strong>封裝：</strong>必須是「有狀態」的可組合項才能修改狀態。這完全屬於內部。</li><li><strong>可共用：</strong>提升過的狀態可讓多個可組合項共用。使用提升即可在其他可組合項中讀取 name。</li><li><strong>可攔截：</strong>無狀態可組合項的呼叫端可在變更狀態前決定忽略或修改事件。</li><li><strong>已分離：</strong>無狀態 ExpandingCard 的狀態可以儲存在任何位置。舉例來說，現在可以將 name 移至 ViewModel 中。</li></ul><pre>@Composable<br>fun HelloScreen() {<br>    var name by rememberSaveable { mutableStateOf(&quot;&quot;) }<br><br>    HelloContent(name = name, onNameChange = { name = it })<br>}<br><br>@Composable<br>fun HelloContent(name: String, onNameChange: (String) -&gt; Unit) {<br>    Column(modifier = Modifier.padding(16.dp)) {<br>        Text(<br>            text = &quot;Hello, $name&quot;,<br>            modifier = Modifier.padding(bottom = 8.dp),<br>            style = MaterialTheme.typography.h5<br>        )<br>        OutlinedTextField(<br>            value = name,<br>            onValueChange = onNameChange,<br>            label = { Text(&quot;Name&quot;) }<br>        )<br>    }<br>}</pre><p>將狀態從 HelloContent 分離出來可以更輕易的重覆使用。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/0*optaiU8iBMpIOpov" /><figcaption>Google 對狀態向下移動而事件向上移動稱為「單向資料流」。</figcaption></figure><p><strong>重點：</strong>提升狀態時，以下三項規則可協助釐清狀態的移動方向：</p><ol><li>狀態「至少」該提升至使用該狀態的所有可組合項的<strong>最低共同父項</strong> (讀取)。</li><li>狀態「至少」該提升至<strong>該狀態可以變更的最高層級</strong> (寫入)。</li><li>如果<strong>兩個狀態為了回應同一事件而變更</strong>，則應<strong>一併提升</strong>。</li></ol><p>您可以將狀態提升到比規則要求更高的層級，但降低狀態會導致難以或無法跟隨單向資料流。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c98ca1aaa3f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jetpack Compose 筆記 (一)]]></title>
            <link>https://medium.com/@YUNJU/%E5%AD%B8%E7%BF%92-jetpack-compose-%E7%AD%86%E8%A8%98-%E4%B8%80-90b1c318cb2e?source=rss-ce8079bb57ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/90b1c318cb2e</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <dc:creator><![CDATA[YUNJU]]></dc:creator>
            <pubDate>Thu, 04 May 2023 05:45:03 GMT</pubDate>
            <atom:updated>2023-05-04T05:46:17.461Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vkcnr9b7Hdf58c7HMWJtzA.png" /><figcaption>Jetpack Compose</figcaption></figure><p>目前工作上開發的 Android 都是採用 Java + XML Layout 來開發，即使是 Side Project 也多是採用 Kotlin + MVVM + XML Layout，觀望 Jetpack Compose 一段時間了，由於習慣了舊有的 UI 架構，對於宣告式的 UI 架構學習曲線有一點高。</p><p>會記錄一下是因為 Jetpack Compose 好像改了很多版，網路上大多查到的 API 在現在的版本不是改名了，就是找不到，而且採用 Material3 開發時，發現官方的文件也是寫得不清不楚。</p><h3>Declarative UI — 聲明式UI</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BOYFCgNHle4M4mVpVdTexg.png" /><figcaption>傳統命令式 UI 更新狀態</figcaption></figure><p>上圖式命令式 UI 收到新的狀態時，需要執行的流程。</p><p>而 Compose 將狀態轉變為 UI，在生成 UI 之後就無法改變，所以當有新的狀態的改變時候，Compose 是直接將整個 UI 重新產生，但官方聲稱這個過程是很智慧化的，會跳過沒有改變的 UI 來提升效率，整體來說程式碼只需要描述介面外觀，不用告訴系統該如何實做。</p><h3>What is @Composable</h3><p>在過往使用 Layout.xml 時，我們定義一個元件或是介面，都會產生一個 xml 來定義版面或使用 include 來引入另一個 xml 來排列，在 Compose 中會使用 @Composable 來標記 function 以表示這是一個 Compose 元件，這個函數可有參數但不帶回傳值，用意是產生出介面，從而實現 UI 重用。</p><pre>@Composable<br>fun MessageList(messages: List&lt;String&gt;) {<br>    Column {<br>        if (messages.size == 0) {<br>            Text(text = &quot;No messages&quot;)<br>        } else {<br>            messages.forEach { message -&gt;<br>                Text(text = message)<br>            }<br>        }<br>    }<br>}</pre><p>以上是一個簡單的 Composable 元件，可以傳入一個字串集合來顯示所有的字串。這樣之所以可以做到資料狀態改變時 UI 重新繪製是因為底層的機制使用了與 MVVM 中一樣的觀察者機制。</p><pre>val viewModel: ConversationViewModel = viewModel()<br>val messages by viewModel.messages.observeAsState()<br>MessageList(messages)</pre><p>它利用了觀察者模式來監看資料的狀態，當資料發生變化時，UI 就會被呼叫重新繪製，Compose 稱之為「<strong>重組</strong>」。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uzjjeJqB6Hpf5Man" /><figcaption>資料的更新是由上往下傳遞</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WIq7C-fLWSRUozvW" /><figcaption>事件的狀態是右下往上通知</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90b1c318cb2e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unreal 啟用 HTTP Listener 來處理社群登入]]></title>
            <link>https://medium.com/@YUNJU/unreal-%E5%95%9F%E7%94%A8-http-listener-%E4%BE%86%E8%99%95%E7%90%86%E7%A4%BE%E7%BE%A4%E7%99%BB%E5%85%A5-497acd0a0760?source=rss-ce8079bb57ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/497acd0a0760</guid>
            <category><![CDATA[unreal-engine]]></category>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[http-client]]></category>
            <dc:creator><![CDATA[YUNJU]]></dc:creator>
            <pubDate>Tue, 25 Apr 2023 03:28:31 GMT</pubDate>
            <atom:updated>2023-04-25T03:33:57.545Z</atom:updated>
            <content:encoded><![CDATA[<p>Unreal 啟用 HTTP Listener 來處理社群登入</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VpPdAJzZxUwBAQ74-VIHHQ.jpeg" /><figcaption>UNREAL ENGINE</figcaption></figure><h3><strong>前言</strong></h3><p>之前的文章有說到我的工作是處理 iOS、Android 的原生功能串接，但其實還負責了遊戲專案的會員系統功能，讓遊戲專案可以完全不用處理玩家的帳號、修改密碼、驗證等工作。</p><h3><strong>需求</strong></h3><p>原先我們提供的所有 UI 都是僅有雙手機平台的，Unity 跟 Unreal 要輸出非手機平台都是要由各專案自行實作，我們提供 API 呼叫而已，但不知道是什麼緣故下，長官們希望也可以提供 UI 讓專案選擇。</p><h3>架構</h3><p>整個設計的邏輯，由於考量到部分平台限制內嵌網頁的形式，所以使用了外開瀏覽器進行登入，再將資料以 localhost 的形式傳回給 Client，所以 Client 這邊需要開一個 Http Listner 來監聽回傳資料。</p><p>實作時發現相關的文章還蠻少的，ChatGPT 提供的方法也怪怪的，還常常給一堆不存在的 function，希望留下這篇文章給有需要的人，或日後還要再用時可以回顧。</p><p>由於我的專案是寫 Plugin ，所以可能有無法直接使用的地方。</p><h3><strong>Module</strong></h3><p>以下是我有使用到的 Module，先加進 Build.cs 裡</p><pre>PublicDependencyModuleNames.AddRange(<br>  new string[]<br>  {<br>    &quot;Http&quot;,<br>    &quot;HTTPServer&quot;,<br>    &quot;Networking&quot;,<br>    &quot;Sockets&quot;,<br>    &quot;VaRest&quot;, // 我的專案是使用這個處理 Json<br>  }<br>);</pre><h3><strong>Launcher</strong></h3><p>在網路上有看過有人使用 Actor 實作，但因為我不是遊戲專案，沒辦法控制 Actor 是否存在，所以我改用另一種方式是寫 UGameInstanceSubsystem 物件來實作一個啟動器，再生成一個 HttpListener 的 UObject。</p><pre>#pragma once<br><br>#include &quot;CoreMinimal.h&quot;<br>#include &quot;Sybsystems/GameInstanceSybsystem.h&quot;<br>#include &quot;HttpLauncher.generated.h&quot;<br><br>UCLASS()<br>class API_NAME UHttpLauncher : public UGameInstanceSubsystem<br>{<br>  GENERATED_BODY()<br><br>private:<br>  static TWeakObjectPtr&lt;UHttpLauncher&gt; _instance;<br>public:<br>  static UHttpLauncher* Instance();<br><br>public:<br>  virtual void Initialize(FSubsystemCollectionBase&amp; Collection) override;<br>  /// &lt;summary&gt;<br>  /// 啟動<br>  /// &lt;/summary&gt;<br>  void Touch();<br><br>public:<br>  // 強指針，避免 GC<br>  UPROPERTY()<br>  class UHttpListener* _httpListener;<br>}</pre><pre>#include &quot;HttpLauncher.h&quot;<br><br>TWeakObjectPtr&lt;UHttpLauncher&gt; UHttpLauncher::_instance == nullptr;<br>UHttpLauncher* UHttpLauncher::Instance() { return _instance.Get(); }<br><br>void UHttpLauncher::Initialize(FSubsystemCollectionBase&amp; Collection)<br>{<br>  _instance = this;<br>}<br><br>void UHttpLauncher::Touch()<br>{<br>  if (!_instance.IsValid())<br>  {<br>    return;<br>  }<br><br>  _httpListener = NewObject&lt;UHttpListener&gt;();<br>  if (IsValid(_httpListener))<br>  {<br>    _httpListener-&gt;Initialize();<br>  }<br>}</pre><h3><strong>Listener</strong></h3><p>監聽器上可以針對需求來修改，因為我們的 port 不打算固定，主要是可以避免被佔用問題。</p><pre>#pragma once<br><br>#include &quot;CoreMinimal.h&quot;<br>#include &quot;HttpServerRequest.h&quot;<br>#include &quot;HttpResultCallback.h&quot;<br>#include &quot;UHttpListener.generated.h&quot;<br><br>UCLASS()<br>class API_NAME UHttpListener : public UObject<br>{<br>  GENERATED_BODY()<br><br>private:<br>  static TWeakObjectPtr&lt;UHttpListener&gt; _instance;<br>public:<br>  static UHttpListener* Instance();<br><br>public:<br>  UHttpListener();<br>  ~UHttpListener();<br><br>private:<br>  int32 _serverPort = 0;<br>  bool _isServerStarted = false;<br><br>public:<br>  /// &lt;summary&gt;<br>  /// 初始化<br>  /// &lt;/summary&gt;<br>  void Initialize();<br><br>  /// &lt;summary&gt;<br>  /// 取得 HTTP Server 使用的 port<br>  /// &lt;/summary&gt;<br>  /// &lt;returns&gt; HTTP Server port &lt;/returns&gt;<br>  int32 GetServerPort() const { return _serverPort; }<br><br>  /// &lt;summary&gt;<br>  /// 取得 HTTP Server 是否啟動中<br>  /// &lt;/summary&gt;<br>  /// &lt;returns&gt; HTTP Server enable&lt;/returns&gt;<br>  bool IsServerStarted() const { return _isServerStarted; }<br><br>private:<br>  /// &lt;summary&gt;<br>  /// 啟動 HTTP Server<br>  /// &lt;/summary&gt;<br>  void StartServer();<br><br>  /// &lt;summary&gt;<br>  /// 關閉 HTTP Server<br>  /// &lt;/summary&gt;<br>  void StopServer();<br><br>  /// &lt;summary&gt;<br>  /// HTTP 請求回呼<br>  /// &lt;/summary&gt;<br>  bool RequestCallback(const FHttpServerRequest&amp; request, const FHttpResultCallback&amp; OnComplete);<br><br>  /// &lt;summary&gt;<br>  /// 尋找可以使用的 Port<br>  /// &lt;/summary&gt;<br>  /// &lt;returns&gt;可以使用的 Port &lt;/returns&gt;<br>  int32 FindAvaliablePort();<br>}</pre><pre>#include &quot;HttpPath.h&quot;<br>#include &quot;IHttpRouter.h&quot;<br>#include &quot;HttpServerHttpVersion.h&quot;<br>#include &quot;HttpServerModule.h&quot;<br>#include &quot;HttpServerResponse.h&quot;<br>#include &quot;Sockets.h&quot;<br>#include &quot;SocketSubsystem.h&quot;<br><br>UHttpListener::UHttpListener()<br>{<br>  if (this-&gt;HasAnyFlags(RF_ClassDefaultObject)) { return; }<br>  <br>  // 想在這裡加上偵測前景後景偵測，判斷玩家是否回到遊戲中<br>  // 但還沒有找到方法<br><br>  _instance = this;<br>}<br><br>UHttpListener::~UHttpListener()<br>{<br>  StopServer();<br>}<br><br>TWeakObjectPtr&lt;UHttpListener&gt; UHttpListener::_instance;<br>UHttpListener* UHttpListener::Instance() { return _instance.Get(); }<br><br>void UHttpListener::Initialize()<br>{<br>  StartServer();<br>}<br><br>void UHttpListener::StartServer()<br>{<br>  // 取得可用的 Port<br>  while (_serverPort == 0)<br>  {<br>    _serverPort = FindAvaliablePort();<br>  }<br><br>  FHttpServerModule&amp; httpServerModule = FHttpServerModule::Get();<br>  TSharedPtr&lt;IHttpRouter&gt; httpRouter = httpServerModule.GetHttpRouter(GetServerPort());<br>  <br>  // 註冊或綁定路由<br>  <br>  // 1. 方法一：綁定單一路由例如 www.example.com/data method = Get<br>  httpRouter-&gt;BindRouter(<br>    FHttpPath(TEXT(&quot;/data&quot;)), <br>    EHttpServerRequestVerbs::VERB_GET,<br>    [this](const FHttpServerRequest&amp; Request, const FHttpResultCallback&amp; OnComplete) { });<br><br>  // 2. 方法二：綁定 root 路由<br>  httpRouter-&gt;RegisterRequestPreprocessor(<br>    [this](const FHttpServerRequest&amp; Request, const FHttpResultCallback&amp; OnComplete) { <br>       return RequestCallback(Request, OnComplete);<br>    }<br>  );<br><br>  httpServerModule.StartAllListeners();<br>  _isServerStarted = true;<br>}<br><br>void UHttpListener::StopServer()<br>{<br>  FHttpServerModule&amp; httpServerModule = FHttpServerModule::Get();<br>  _isServerStarted = false;<br>  _serverPort = 0;<br>}<br><br>bool UHttpListener::RequestCallback(const FHttpServerRequest&amp; Request, const FHttpResultCallback&amp; OnComplete)<br>{<br>  for (const auto&amp; queryParam : Request.QueryParams)<br>  {<br>    // 針對需求處理 query key and value<br>  }<br><br>  // 處理 Response HTML，我們這裡是塞個轉址轉回伺服器指定頁面<br>  FString responseHTML = FString::Printf(TEXT(&quot;&lt;html&gt;&lt;/html&gt;&quot;));<br><br>  TUniquePtr&lt;FHttpServerResponse&gt; response = FHttpServerResponse::Create(responseHTML, TEXT(&quot;text/html&quot;));<br>  OnComplete(MoveTemp(response));<br>  return true;<br>}<br><br>int32 UHttpListener::FindAvaliablePort()<br>{<br>  ISocketSubsystem* SocketSubsystem = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM);<br>  TSharedRef&lt;FInternetAddr&gt; Addr = SocketSubsystem-&gt;CreateInternetAddr();<br><br>  // 設定 Port = 0 會使 Socket 自動分配可使用的 Port<br>  Addr-&gt;SetAnyAddress();<br>  Addr-&gt;SetPort(0);<br>  <br>  // 建立 Socket<br>  FSocket* Socket = SocketSubsystem-&gt;CreateSocket(NAME_Stream, TEXT(&quot;FindAvailablePort&quot;), flase);<br>  <br>  // 綁定<br>  bool bBindSuccess = Socket-&gt;Bind(*Addr);<br>  <br>  // 如果端口已被佔用，會綁定失敗<br>  if (!bBindSuccess)<br>  {<br>    Socket-&gt;Close();<br>    return 0;<br>  }<br><br>  // 獲取 Socket 分配的端口<br>  int32 Port = Socket-&gt;GetPortNo();<br>  <br>  Socket-&gt;Close();<br>  return Port;<br>}</pre><p>最後開啟後端驗證網址，進行 Google、Facebook、Twitter、Apple 等相關登入，再將 token 等資訊加密傳回 localhost:Port 解密處理</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=497acd0a0760" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[物聯網開發筆記 (二) ESP32 實作]]></title>
            <link>https://medium.com/@YUNJU/%E7%89%A9%E8%81%AF%E7%B6%B2%E9%96%8B%E7%99%BC%E7%AD%86%E8%A8%98-%E4%BA%8C-esp32-%E5%AF%A6%E4%BD%9C-bf40434d8ac7?source=rss-ce8079bb57ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf40434d8ac7</guid>
            <category><![CDATA[esp32]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[dev]]></category>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[platformio]]></category>
            <dc:creator><![CDATA[YUNJU]]></dc:creator>
            <pubDate>Fri, 24 Feb 2023 04:12:18 GMT</pubDate>
            <atom:updated>2023-02-24T04:36:15.452Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>開發上採用 VSCode + PlatformIO 以 C++ 撰寫</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*d4DShmbLFxZp2_4p" /><figcaption>Photo by <a href="https://unsplash.com/@vishnumaiea?utm_source=medium&amp;utm_medium=referral">Vishnu Mohanan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>定義所需資訊</h4><p>為了日後方便擴充 Sensor 放置點，除了定義相關連線資訊外，再而外定義一組設備名稱</p><pre>// WiFi Info<br>const char* WIFI_SSID = &quot;YOUR_WIFI_SSID&quot;;<br>const char* WIFI_PASS = &quot;YOUR_WIFI_PASSWORD&quot;;<br><br>// Device Info<br>const char* DEVICE_NAME = &quot;YOUR_CUSTOM_DEVICE_ID_OR_NAME&quot;;<br>const int DEVICE_WIFI_CONNECT_TIME_OUT = 15;<br><br>// Firebase Info<br>const char FIREBASE_PRIVATE_KEY[] PROGMEM = &quot;YOUR_PROJECT_PRIVATE_KEY&quot;;<br>const char* FIREBASE_PROJECT_ID = &quot;YOUR_PROJECT_ID&quot;;<br>const char* FIREBASE_CLIENT_EMAIL = &quot;YOUR_CLIENT_EMAIL&quot;;<br>const char* FIREBASE_PROJECT_LOCATION = &quot;YOUR_PROJECT_LOCATION&quot;;<br>const char GOOGLE_CA[] PROGMEM = &quot;GOOGLE DOMAIN ROOT CA&quot;;</pre><p>接著撰寫 WiFi 連線 function</p><pre>#include &lt;WiFi.h&gt;<br><br>void connectToWiFi() {<br>  // 設定 WiFi 模式<br>  WiFi.mode(WIFI_STA);<br>  // 設定名稱<br>  WiFi.setHostname(DEVICE_NAME);<br>  // Connect<br>  WiFi.begin(WIFI_SSID, WIFI_PASS);<br><br>  int connectTime = 0;<br>  <br>  // 等待 WiFi 連線中並輸出資訊<br>  Serial.print(&quot;WiFi 正在連線中.&quot;);<br>  while (WiFi.status() != WL_CONNECTED) {<br>    Serial.print(&quot;.&quot;);<br>    // 如果超過 15 秒就重開機<br>    if (connectTime &gt; DEVICE_WIFI_CONNECT_TIME_OUT) {<br>      ESP.restart();<br>    } else {<br>      connectTime++;<br>    }<br>    delay(1000);<br>  }<br><br>  Serial.printf(&quot;\nWiFi連線成功\n&quot;);<br>}</pre><p>定義連線伺服器 function</p><pre>#include &lt;Firebase_ESP_Client.h&gt;<br>#include &lt;addons/TokenHelper.h&gt;<br><br>// Firebase Variable<br>FirebaseData data;<br>FirebaseConfig config;<br>FirebaseAuth auth;<br><br>void connectToServer() {<br>  auth.user.email = &quot;User email&quot;;<br>  auth.user.password = &quot;User Password&quot;;<br>  <br>  config.cert.data = GOOGLE_CA;<br>  config.service_account.data.client_email = FIREBASE_CLIENT_EMAIL;<br>  config.service_account.data.project_id = FIREBASE_PROJECT_ID;<br>  config.service_account.data.private_key = FIREBASE_PRIVATE_KEY;<br>  config.token_status_callback = tokenStatusCallback;<br><br>  data.setCert(GOOGLE_CA);<br>  Firebase.begin(&amp;config, &amp;auth);<br>  Firebase.reconnectWiFi(true);<br>}</pre><p>定義上傳資料 function</p><pre>void uploadData() {<br>  // 設定 HTTP POST 參數<br>  FirebaseJson payload;<br>  payload.set(&quot;deviceId&quot;, DEVICE_NAME);<br>  // 直接從腳位抓直帶入<br>  payload.set(&quot;moisture&quot;, analogRead(A0);<br><br>  if (Firebase.functions.callFunction(&amp;data, <br>                                FIREBASE_ID, <br>                  FIREBASE_PROJECT_LOCATION, <br>                             &quot;FunctionName&quot;, <br>                               payload.raw())) {<br>    // 解析伺服器回傳 json logic<br>    int nextUploadSec = 1800;<br>    // 設定深度睡眠喚醒時間<br>    esp_sleep_enable_timer_wakeup(nextUploadSec * 1000000L);<br>    Serial.printf(&quot;喚醒秒數 %u\n&quot;, nextUploadSec);<br>    delay(100);<br>    // 進入深度睡眠<br>    esp_deep_sleep_start();<br>  }<br>}</pre><p>其他 function</p><pre>bool taskCompleted = false;<br><br>void setup() {<br>  Serial.begin(115200);<br>  connectToWiFi();<br>  connectToServer();<br>}<br><br>void loop() {<br>  if (Firebase.ready() &amp;&amp; !taskCompleted) {<br>    uploadData();<br>    taskCompleted = true;<br>  }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf40434d8ac7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[物聯網開發筆記 (一) 介紹]]></title>
            <link>https://medium.com/@YUNJU/%E7%89%A9%E8%81%AF%E7%B6%B2%E9%96%8B%E7%99%BC%E7%AD%86%E8%A8%98-%E4%B8%80-44089183d4e5?source=rss-ce8079bb57ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/44089183d4e5</guid>
            <category><![CDATA[jetson-nano]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[dev]]></category>
            <category><![CDATA[esp32]]></category>
            <dc:creator><![CDATA[YUNJU]]></dc:creator>
            <pubDate>Fri, 24 Feb 2023 03:31:02 GMT</pubDate>
            <atom:updated>2023-05-22T02:31:47.181Z</atom:updated>
            <content:encoded><![CDATA[<p>希望能夠在 2023 年底前開發完成</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4DrMZCInVMfCFgr4" /><figcaption>Photo by <a href="https://unsplash.com/@jorgedevs?utm_source=medium&amp;utm_medium=referral">Jorge Ramirez</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>也刊登在 <a href="https://www.yunserve.dev/aiot-dev-intro/">物聯網開發筆記 (一) 介紹</a></blockquote><h3>動機及設備</h3><p>家父的開心農場一直以來都是使用定時灑水，每天清晨時間一到計時器便會通電讓馬達自動灑水，這樣的好處是便宜方便，壞處可想而知就是不管三七二十一，潮濕、下雨、淹水等各種情況照樣灑水。</p><p>正好前陣子看了看 Arduino 感覺是蠻有興趣的，那就先拿改良灑水系統來玩玩看，以下為目前採購的裝置，邊開發編採購，日後可能會再增加。</p><ul><li>NVIDIA Jetson nano 4GB Developer Kit * 1 (後稱 Nano)</li><li>ESP32 開發板 * 1</li><li>四路繼電器 * 1</li><li>土壤偵測器 * 1</li><li>太陽能板 * 1</li><li>太陽能儲電 * 1</li></ul><h3>架構</h3><p>架構上目前僅為擬定階段，後續可能跟著實務或現場困難隨時修改。</p><h4><strong>ESP32 開發板</strong></h4><p>ESP32 搭配太陽能系統及土壤偵測器放置在農場裡，以 WiFi 無線方式連接，用途很單純的開機後上傳偵測原始數值到伺服器上。</p><h4><strong>Nano</strong></h4><p>Nano 作為農場中的中控設備，放在電路匯集的工具房裡，以有線網路方式連線，結合繼電器及原先馬達設備。</p><h4><strong>系統層面</strong></h4><ul><li>伺服器端採用 Google Cloud Functions 無伺服器架構，相關設備以 HTTPS 與其溝通。</li><li>終端設備中ESP32採用C++語言開發，開機後上傳偵測值給予伺服器，並取得下次上傳時間後進入深度睡眠，以節省電力消耗；Nano開發上採用 Node.js、Python 並行開發，利用 Node.js 監聽 Server 數值，並透過Python 給 GPIO 指定腳位訊號。</li><li>所有運算需求均在伺服器端實作，故終端上傳的資料均為原始資料，否則改 Code 要驅車幾個小時前往燒錄ESP32。</li></ul><h4><strong>需求層面</strong></h4><ol><li>冬夏不同灑水時段</li><li>手機 APP 可遠端監看、手動操作灑水</li><li>所有終端或伺服器數值，均可在 APP 即時調整</li><li>中控設備是否要有螢幕可直接顯示相關數值 (?</li><li>中控設備是否要有實體按鈕可按下直接灑水 (?</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44089183d4e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java、Objective-C 傳送圖片到遊戲引擎]]></title>
            <link>https://medium.com/@YUNJU/java-objective-c-%E5%82%B3%E9%80%81%E5%9C%96%E7%89%87%E5%88%B0%E9%81%8A%E6%88%B2%E5%BC%95%E6%93%8E-2cdcc903ec73?source=rss-ce8079bb57ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/2cdcc903ec73</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[objective-c]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[unreal]]></category>
            <dc:creator><![CDATA[YUNJU]]></dc:creator>
            <pubDate>Fri, 22 Jul 2022 05:26:04 GMT</pubDate>
            <atom:updated>2023-05-22T02:30:45.801Z</atom:updated>
            <content:encoded><![CDATA[<p>讓 Java、Objective-C 語言能夠將圖片轉為 Unity、Unreal 的教學，主要也是我自己研究了一段時間，相關的文件真的蠻少的。</p><blockquote>也刊登在 <a href="https://www.yunserve.dev/game-engine-with-native-image-convert/">Java、Objective-C 傳送圖片到遊戲引擎</a></blockquote><h4>前言</h4><p>我的工作是串接 iOS、Android 的原生功能 e.g. , IAP、Permission、AlertDialog ，來讓公司的遊戲專案可以不用去考慮平台的原生功能，專心的處理遊戲及商業邏輯。</p><h4>功能需求</h4><p>這一次的功能需求起因是遊戲專案需要讓玩家可以選擇頭像，但原先使用的 Unity 套件沒有繼續更新支援新版 Android 日漸嚴格的隱私權政策，所以就把這個 case 轉來我們團隊了 !</p><h4>作法簡介</h4><p>我的作法是將圖片先轉為 Byte Array 再轉為 base64 字串傳到引擎內再去處理。</p><p>處理順序</p><ol><li>Convert to byte array</li><li>Encode to base64</li><li>Send message to engine</li><li>Engine base64 decode</li><li>Convert to engine texture</li></ol><h4>引擎坑</h4><blockquote>Unity 支援 base 64 帶有 \n</blockquote><blockquote>Unreal 不支援 base64 帶有 \n</blockquote><h4>Objective-C</h4><pre>// 選擇照片的 Callback<br>-(void)onSelectPhotoSuccess:(UIImage*)choseImage<br>{<br>    // 壓縮值(%)<br>    CGFloat quality = 0.8;<br>    // Convert image to NSData<br>    NSData* data = UIImageJPEGRepresentation(choseImage, quality);<br>    [self sendPhotoDataToEngine: data];<br>}<br><br>// 傳送處理過的 data 給遊戲引擎<br>-(void)sendPhotoDataToEngine:(NSData*)photoData<br>{<br>    if (photoData != nil)<br>    {<br>        // no \n<br>        NSString* base64Str = [photoData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];<br>        // default<br>        NSString* base64StrWithLine = [photoData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];<br>        // Use your way to Engine<br>    }<br>}</pre><h4>Java</h4><pre>// 選擇照片的 Callback<br>private void onSelectPhotoSuccess(Bitmap bitmap)<br>{<br>    float quality = 80;<br>    <br>    ByteArrayOutputStream out = new ByteArrayOutputStream();<br>    bitmap.compress(Bitmap.CompressFormat.PNG, quality, out);<br>    sendPhotoDataToEngine(out.toByteArray());<br>}<br><br>// 傳送處理過的 data 給遊戲引擎<br>private void sendPhotoDataToEngine(byte[] data)<br>{<br>    String resultString = &quot;&quot;;<br>    <br>    // Unity support Default<br>    resultString = Base64.encodeToString(data, Base64.DEFAULT);    <br>    // Unreal doesn&#39;t support DEFAULT<br>    resultString = Base64.encodeToString(data, Base64.NO_WARP);<br>    // Use your way to Engine<br>}</pre><h4>Unity</h4><pre>/// &lt;summary&gt;<br>/// 處理傳來的 base64 <br>/// &lt;/summary&gt;<br>/// &lt;param name=&quot;base64Str&quot;&gt;圖片資訊&lt;/param&gt;<br>private void ConvertBase64ToBytes(string base64Str)<br>{<br>    byte[] bytes = System.Convert.FromBase64String(base64Str);<br>    ConvertBytesToTexture(bytes);<br>}<br>/// &lt;summary&gt;<br>/// 轉換為 Texture<br>/// &lt;/summary&gt;<br>/// &lt;param name=&quot;photoByteArray&quot;&gt;圖片byte array&lt;/param&gt;<br>private void ConvertBytesToTexture(Byte[] photoByteArray)<br>{<br>    if (photoByteArray != null)<br>    {<br>        // 如果有需要，也可以把長寬從 Java、iOS 傳過來<br>        var photoTexture = new Texture2D(width, height);<br>        photoTexture.LoadImage(photoByteArray);<br>    }<br>}</pre><h4>Unreal</h4><pre>// 略過相關的 C、Jni 類型轉換<br>void Sample::ConvertBase64ToTexture2D(FString base64Str)<br>{<br>    TArray&lt;uint8&gt; sourceData;<br>    FBase64::Decode(base64Str, sourceData);<br>    UTexture2D* outTexture = FImageUtils::ImportBufferAsTexture2D(sourceData);<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2cdcc903ec73" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Unity] Photon Bolt 開發筆記 03 — 入門]]></title>
            <link>https://medium.com/@YUNJU/unity-photon-bolt-%E9%96%8B%E7%99%BC%E7%AD%86%E8%A8%98-03-%E5%85%A5%E9%96%80-6af54767c083?source=rss-ce8079bb57ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/6af54767c083</guid>
            <category><![CDATA[bolt]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[photon]]></category>
            <category><![CDATA[network]]></category>
            <category><![CDATA[photon-bolt]]></category>
            <dc:creator><![CDATA[YUNJU]]></dc:creator>
            <pubDate>Fri, 10 May 2019 17:21:09 GMT</pubDate>
            <atom:updated>2019-05-10T17:21:09.166Z</atom:updated>
            <content:encoded><![CDATA[<h3>[Unity] Photon Bolt 開發筆記 03 — 入門</h3><blockquote>Bolt 與 UNet 不同的地方在於需要自行手動撰寫的網路代碼不多，在 Bolt 中所有的序列化以及數值、動畫複製等等都將自動完成。</blockquote><p>詳細的 Bolt 介紹可以觀看 Photon 官方的 Medium。</p><p><a href="https://medium.com/photon-taiwan/photon-bolt-%E5%85%A5%E9%96%80%E4%BB%8B%E7%B4%B9-62c326a260eb">Photon Bolt 入門介紹</a></p><h3>Bolt Asset</h3><p>Bolt 的資產分為以下四大類：</p><p>States 狀態：</p><pre>State 是整個 Bolt 在 Unity 中的核心部分，它允許你自定義你想同步的數據</pre><pre>例如：角色名稱(String)、角色血量(Float)、、物件座標旋轉與縮放(Transform)、動畫參數等數據</pre><p>Objects 物件：</p><pre>Objects 物件類似於 C# 中的 Class、Struct，可以定義自己的資料結構，再於 State 狀態中創建一個陣列用於儲存該 Objects。</pre><p>Commands 指令：</p><pre>有些遊戲是完全伺服器權威的，也就是所有操作必須由伺服器運算，玩家看到的只是結果，所以 Commands 指令可以用於封裝用戶的輸入功能，並傳輸到伺服器上再藉由伺服器去控制該玩家擁有控制權的角色。</pre><pre>而玩家看到的結果僅是 State 狀態同步回去的結果。</pre><p>Events 事件：</p><pre>事件只是一些簡單的訊息，通過事件的應用可以讓物件與物件之間的依賴性降到最低，讓彼此相互分離。</pre><p>這四個資產的製作皆不用撰寫任何程式碼，Bolt 本身就提供了很方便的 Editor 讓使用者可以很直覺的創建，它位於工作列上的 Bolt &gt; Assets。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/1*jbG-zIEZXd0bYP3A9oTpBA.png" /><figcaption>Photon Bolt Assets</figcaption></figure><p>它預設會自帶一些範本，若不需要可以按住 Ctrl 後按下紅色 X 。</p><p>在這個 Editor 中空白區域按下右鍵，可以出現選單來新增資產：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/1*gzJOjttGNMei4foY8JBqPw.png" /><figcaption>Create Bolt Assets</figcaption></figure><p>這裡先新增一個 State ，Bolt 在每次新增完資產後，都會跳出相對應的設置 Editor。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*HvH4JiQsx-T-QYksi6dhPw.png" /><figcaption>Bolt Assets Editor</figcaption></figure><p>我將 State 取名為 <strong>PlayerState</strong>，用來同步玩家所需資訊，命名完成後點選後方的 New Property 新增屬性，並取名為 Transform，後方的類型也選擇 Transform。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*TRX7H_JdyHyvlStnBFOGyA.png" /><figcaption>Create state and add property</figcaption></figure><p>完成後，請選擇工具列中的 Bolt &gt; Compile Assembly。</p><blockquote>這個步驟很重要 Bolt 只要跟製作資產有關的都需要經過 Compile。</blockquote><h3>讓 Bolt 認識 Entity Prefab</h3><p>接著完成了 Bolt 玩家狀態的定義後，來將該定義實際運用在 Unity 的角色身上，這邊我以 Cube 當作我們的玩家並取名為 Player 做成 Prefab。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D__7ZJORkJHcFQChLJekSA.png" /><figcaption>Make player prefab</figcaption></figure><p>接著我們要讓 Bolt 知道我們有一個 Prefab 要與 State 做一個關聯綁定，利用Add Component 增加一個元件 Bolt Entity 。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*Z9O3rN5bJ2lauGWadr-YhA.png" /><figcaption>Add Bolt Entity Component</figcaption></figure><p>一開始出現一些錯誤是正常的，前兩個錯誤是因為 Bolt 系統完全不認識這個 Prefab 所以缺少 id 與一些資訊，這邊只要利用上面說過的方式再 Compile 一次就解決了。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*Dj9P6bLMTy8v4FdjHsAsrQ.png" /><figcaption>Bolt Entity error message</figcaption></figure><p>接下來剩下的錯誤就只是因為未選取要配對的 State 狀態，只要選擇我們剛才創建的 IPlayerState 即可。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*tTCGVReDkOiltWlYiyGbeA.png" /><figcaption>Entity state error message</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*xwR1Cz2NrkkVMKJHZhx5cQ.png" /><figcaption>Select state</figcaption></figure><p>這樣 Bolt 系統就認識了該 Prefab 物件，該 Prefab 就能正式的在 Bolt 的 API 進行呼叫使用。</p><h3>生成玩家物件的程式</h3><p>在接續之前，我們先簡單利用 Plane 創建一個地板，改動一下攝影機從約 45 度角照射下去。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*rue9uGkxIDRPJmYzIGbX7g.png" /><figcaption>Create environment</figcaption></figure><p>將這個場景儲存起來，我將其命名為 Game，接著再新增一個場景命名為 Menu，並將兩個場景都加入到 Build Settings 中。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*QD6lik8Ky5YCH6DB926SqQ.png" /><figcaption>Unity build settings</figcaption></figure><blockquote>增減場景也必須通過 Bolt Compile</blockquote><p>接下來創建一個 C# 腳本，我將其取名為 Menu，首先這個腳本要替換掉預設的繼承類 MonoBehaviour，更改為 Bolt.GlobalEventListener 。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9b9ee1ba929d9dd7525c424d63a7746d/href">https://medium.com/media/9b9ee1ba929d9dd7525c424d63a7746d/href</a></iframe><p>這個腳本也同時是一個全域的事件監聽器，添加 OnGUI 製作兩個簡單的按鈕，並對應到 Bolt 的<strong>啟動伺服器</strong>與<strong>啟動客戶端</strong> API。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d7fe6b9aaed8f769b0daa26e92f8c3c/href">https://medium.com/media/0d7fe6b9aaed8f769b0daa26e92f8c3c/href</a></iframe><p>這時候將 Menu 放到場景上隨機的物件上執行，會得到下面的畫面：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u4HYH0RMBOHm6zfFLyEutQ.png" /><figcaption>GUI</figcaption></figure><p>這時候的按下 Server 與 Client 雖然都會與伺服器連線，但並不會執行什麼接下來的動作，回到 Menu 我們來繼續完善程式。</p><pre>public override void BoltStartDone(string scene) {}</pre><p>上面繼承的 BoltStartDone方法會再 Bolt 執行完 BoltLauncher.StartServer 或 BoltLauncher.StartClient 後自動呼叫該回呼(Callback)方法，所以我們在執行完成後，讓伺服器去執行創建房間與切換場景的功能：</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef653e584330a910b14ebd9a6e7d2a6c/href">https://medium.com/media/ef653e584330a910b14ebd9a6e7d2a6c/href</a></iframe><p>接著在覆寫一個方法為 SessionListUpdated ，該方法會在房間列表更新時通知所有連線的程式，這邊練習以列表中第一個房間為主要加入對象。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1177dacb9758148b9331f05426d577b/href">https://medium.com/media/d1177dacb9758148b9331f05426d577b/href</a></iframe><p>這樣子再次測試後，不管是 Server 還是 Client 都可以加入房間並一同加入 Game 場景。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1013/1*OPejb1ca2SOkI2iIYYOlHw.png" /><figcaption>Change to game scene</figcaption></figure><p>接著新增一個 C# 腳本，先取名為 NetworkCallbacks 這個腳本將用來在連線成功時自動創建玩家物件。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c402a9af5973c3b99760611d7686842e/href">https://medium.com/media/c402a9af5973c3b99760611d7686842e/href</a></iframe><blockquote>[BoltGlobalBehaviour] 這個類別屬性可以讓該腳本無須掛載於任何場景上的物件，他將隨著 Bolt 一同實例化與銷毀。</blockquote><p>這時再執行一次後就可以看到角色產生了。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YNiKSgHPAc8syEEu6m93VA.png" /><figcaption>Player object spawn in the server.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6af54767c083" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Unity] Photon Bolt 開發筆記 02— Installer]]></title>
            <link>https://medium.com/@YUNJU/unity-photon-bolt-%E9%96%8B%E7%99%BC%E7%AD%86%E8%A8%98-02-installer-ae0525138104?source=rss-ce8079bb57ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae0525138104</guid>
            <category><![CDATA[installer]]></category>
            <category><![CDATA[photon]]></category>
            <category><![CDATA[network]]></category>
            <category><![CDATA[bolt]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[YUNJU]]></dc:creator>
            <pubDate>Tue, 07 May 2019 17:11:48 GMT</pubDate>
            <atom:updated>2019-05-07T17:11:48.849Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Unity Asset Store</strong></h3><p>從資源商店中搜尋 Photon Bolt，先下載在匯入至專案內。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*j9JqVpBu8s053P8SstuzPg.png" /></figure><h3>Bolt Wizard</h3><p>匯入完成後，會跳出下列的視窗：</p><blockquote>若沒有跳出可以到狀態列 Bolt &gt; Wizard 中呼叫出來。</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*vsxpovBzOBNQQNVPT36rKw.png" /></figure><p>這個步驟直接按 Next。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*aszyGmLSfdYqMjgfWgVafg.png" /></figure><p>這邊要填入 APP ID ，可以按右上角的 <strong>Visit Dashboard</strong> 登入 Photon 去創建一個。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*seWoiVvFq6xDGq-jZ7qP1g.png" /></figure><p>這邊可以直接下一步，也可以選擇匯入 Samples 檔。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*KijsqaP2JqyPl9f_iWN1TA.png" /></figure><p>這樣就設置完成囉，可以按 <strong>Done</strong>。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae0525138104" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Unity] Photon Bolt 開發筆記 01 — 前言]]></title>
            <link>https://medium.com/@YUNJU/unity-photon-bolt-01-ac9a1d50f2e4?source=rss-ce8079bb57ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac9a1d50f2e4</guid>
            <category><![CDATA[network]]></category>
            <category><![CDATA[unet]]></category>
            <category><![CDATA[bolt]]></category>
            <category><![CDATA[photon]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[YUNJU]]></dc:creator>
            <pubDate>Tue, 07 May 2019 16:27:43 GMT</pubDate>
            <atom:updated>2019-05-07T16:27:43.170Z</atom:updated>
            <content:encoded><![CDATA[<h3>[Unity] Photon Bolt 開發筆記 01 — 前言</h3><h3>UNet</h3><p>Unity 自帶的連線解決方案 UNet 已經要淘汰掉了，目前確定在2018.3版以後已經移除 API，而 Match Server 還能使用到 2018.4 正式版出來後起算三年，Unity 正在著手開發新的連線製作 API，大概會在 2019 不知道哪一個版本號出現，若還想使用舊的 API 可以在 Package Manager 中下載。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*ECXwkJy58Fb1VFpOtCbeOA.png" /></figure><p>這裡是相關 <a href="https://blogs.unity3d.com/2018/08/02/evolving-multiplayer-games-beyond-unet/?_ga=2.65580846.1665630523.1557194745-322847509.1553443880">部落格公告</a> 與 <a href="https://support.unity3d.com/hc/en-us/articles/360001252086-UNet-Deprecation-FAQ?_ga=2.65580846.1665630523.1557194745-322847509.1553443880">Q&amp;A</a></p><h3>Photon Bolt</h3><p>前陣子因為製作連線的需求，重新複習了一下 UNet ，真的是個蠻難用的東西，而 Unity 有跟 Google Cloud Platform(GCP)合作，看到的相關資料是之後會提供開發工具可以更簡便的開發 Unity 整合 GCP 的專案，不過距離那份資料也已經有段時間還是沒看到相關工具? 再來就是 Unity 蠻多人使用的連線解決方案 Photon，剛好接下來的專案是款多人的 VR Action Game，所以就來研究一下 Photon Bolt 拉。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac9a1d50f2e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>