<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Unity on AYU MAX</title>
    <link>https://ayumax.net/tags/unity/</link>
    <description>Recent content in Unity on AYU MAX</description>
    <image>
      <title>AYU MAX</title>
      <url>https://ayumax.net/profile.jpg</url>
      <link>https://ayumax.net/profile.jpg</link>
    </image>
    <generator>Hugo -- 0.147.1</generator>
    <language>en</language>
    <lastBuildDate>Mon, 12 Nov 2018 22:22:34 +0000</lastBuildDate>
    <atom:link href="https://ayumax.net/tags/unity/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Attended Center CLR Try! Development #2</title>
      <link>https://ayumax.net/entry/2018/11/12/222234/</link>
      <pubDate>Mon, 12 Nov 2018 22:22:34 +0000</pubDate>
      <guid>https://ayumax.net/entry/2018/11/12/222234/</guid>
      <description>&lt;h1 id=&#34;attended-center-clr-try-development-2&#34;&gt;Attended Center CLR Try! Development #2&lt;/h1&gt;
&lt;p&gt;I recently attended &amp;ldquo;Center CLR Try! Development #2&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;The venue was different from #1, right in front of Kanayama Station, making it easily accessible.
However, the target building was under construction, making the entrance hard to find, and I wandered around for a few minutes&amp;hellip; (Being directionally challenged, I initially went to the wrong building).&lt;/p&gt;
&lt;p&gt;There were three participants that day (Mr. Matsui, Mr. Matsuoka, and myself). Being alongside two amazing individuals made me a little, no, quite nervous. But thanks to the small group size, I was able to talk about various things, making it a meaningful day.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<h1 id="attended-center-clr-try-development-2">Attended Center CLR Try! Development #2</h1>
<p>I recently attended &ldquo;Center CLR Try! Development #2&rdquo;.</p>
<p>The venue was different from #1, right in front of Kanayama Station, making it easily accessible.
However, the target building was under construction, making the entrance hard to find, and I wandered around for a few minutes&hellip; (Being directionally challenged, I initially went to the wrong building).</p>
<p>There were three participants that day (Mr. Matsui, Mr. Matsuoka, and myself). Being alongside two amazing individuals made me a little, no, quite nervous. But thanks to the small group size, I was able to talk about various things, making it a meaningful day.</p>
<h1 id="what-i-did">What I Did</h1>
<p>I had originally planned to spend the day working on an app I was developing in Unity, so that&rsquo;s what I did.</p>
<p>I&rsquo;m creating a prize lottery app to be used at my department&rsquo;s year-end party.</p>
<p>I&rsquo;ve been using Unreal Engine as my game development tool for a long time, but I had no experience with Unity, so I decided to give Unity a try starting this month.
(* Although I use Unreal Engine a lot, I&rsquo;ve never actually made a game.)</p>
<p>By the way, the deadline I set for myself is the end of November, so the duration is one month.</p>
<h1 id="a-bit-more-detail">A Bit More Detail</h1>
<p>Using Unity&rsquo;s UI features (equivalent to UMG in Unreal), I was creating the participant registration screen for the year-end party and implementing a feature to register photos taken with a smartphone camera.</p>
<p>I was worried I might have to use OS-dependent APIs for camera shooting, but it was surprisingly easy to achieve using only Unity&rsquo;s features!</p>
<p>(I&rsquo;m requesting camera usage permission in the app beforehand.)</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cs" data-lang="cs"><span style="display:flex;"><span><span style="color:#75715e">// Get the camera attached to the execution device (the first one if there are multiple)</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">var</span> cameraDevice = WebCamTexture.devices[<span style="color:#ae81ff">0</span>];
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// Create a texture to project the camera feed onto</span>
</span></span><span style="display:flex;"><span>cameraTexture = <span style="color:#66d9ef">new</span> WebCamTexture(cameraDevice.name, <span style="color:#ae81ff">1280</span>, <span style="color:#ae81ff">720</span>);
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// Start shooting</span>
</span></span><span style="display:flex;"><span>cameraTexture.Play();
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// Display the camera feed on the UI (targetImage is a reference to a RawImage on the UI)</span>
</span></span><span style="display:flex;"><span>targetImage.texture = cameraTexture;
</span></span></code></pre></div><p>Running the code above displays the camera feed in real-time on the RawImage in the UI.
I assume it&rsquo;s transferring the camera feed to the RawImage&rsquo;s texture every frame.</p>
<p>This time, I wanted to save a still image, so I executed the following code when a UI button was pressed to save the image data.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cs" data-lang="cs"><span style="display:flex;"><span><span style="color:#75715e">// Get the pixel buffer of the camera image at that moment</span>
</span></span><span style="display:flex;"><span>Color32[] color32 = cameraTexture.GetPixels32();
</span></span><span style="display:flex;"><span><span style="color:#75715e">// Create a texture to display the camera image</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">var</span> cameraImage = <span style="color:#66d9ef">new</span> Texture2D(cameraTexture.width, cameraTexture.height);
</span></span><span style="display:flex;"><span><span style="color:#75715e">// Copy the pixel buffer to the texture</span>
</span></span><span style="display:flex;"><span>cameraImage.SetPixels32(color32);
</span></span><span style="display:flex;"><span>cameraImage.Apply();
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// Stop the camera shooting</span>
</span></span><span style="display:flex;"><span>cameraTexture.Stop();
</span></span></code></pre></div><p>Now, <code>cameraImage</code> contains the image captured by the camera as a texture. By inserting this into the UI&rsquo;s RawImage, I achieved the desired functionality.</p>
<p>That&rsquo;s what I did today. In the future, I plan to shrink and crop this captured image for thumbnails and serialize it so it can be used on the next launch.</p>
<h1 id="summary">Summary</h1>
<ul>
<li>Managed to capture smartphone camera images in Unity.</li>
<li>Small-group events are very meaningful as you get to talk with amazing people.</li>
<li>Might take the first step towards being able to read IL soon.</li>
</ul>
]]></content:encoded>
    </item>
  </channel>
</rss>
