{"id":96,"date":"2014-12-02T23:34:35","date_gmt":"2014-12-02T23:34:35","guid":{"rendered":"http:\/\/nbodyphysics.com\/blog\/?p=96"},"modified":"2015-03-06T12:40:34","modified_gmt":"2015-03-06T12:40:34","slug":"the-unity-4-6-ui-some-tidbits","status":"publish","type":"post","link":"https:\/\/nbodyphysics.com\/blog\/the-unity-4-6-ui-some-tidbits\/","title":{"rendered":"The Unity 4.6 UI &#8211; Some Tidbits"},"content":{"rendered":"<p>Unity 4.6 provides a fantastic new UI framework. I will <strong><em>never<\/em><\/strong> use the old OnGui() again! I have been using the new framework for the past several months while Unity 4.6 was in beta. During this time I have collected a few tidbits on working with the framework.<\/p>\n<h2>Getting Started<\/h2>\n<p>The <a href=\"http:\/\/unity3d.com\/learn\/tutorials\/modules\/beginner\/ui\">tutorials<\/a><a title=\"tutorials\" href=\"http:\/\/unity3d.com\/learn\/tutorials\/modules\/beginner\/ui\">\u00a0<\/a>\u00a0are very good and the information in the\u00a0<a href=\"http:\/\/docs.unity3d.com\/460\/Documentation\/Manual\/UISystem.html\">manual<\/a> is getting better all the time. I found the tutorials on Canvas, RectTransform, Button and Event System a bare minimum to get the idea of the whole thing.<\/p>\n<h2>Adapting for Mobile Screen Sizes<\/h2>\n<p>This was one of my first &#8220;care-abouts&#8221;. There are two things that are important to know. The first is the anchor system for the layout of elements \u00a0(see the RectTransform tutorial) but that is only part of the solution. The crucial other element is adding a CanvasScaler to your root canvas.<\/p>\n<p><a href=\"http:\/\/nbodyphysics.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-29-at-12.45.51-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-97\" src=\"http:\/\/nbodyphysics.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-29-at-12.45.51-PM-300x185.png\" alt=\"Screen Shot 2014-11-29 at 12.45.51 PM\" width=\"300\" height=\"185\" srcset=\"https:\/\/nbodyphysics.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-29-at-12.45.51-PM-300x185.png 300w, https:\/\/nbodyphysics.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-29-at-12.45.51-PM-624x384.png 624w, https:\/\/nbodyphysics.com\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-29-at-12.45.51-PM.png 744w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><span style=\"line-height: 1.714285714; font-size: 1rem;\">Once attached to a Canvas this can then be set to give a reference size and you&#8217;re good to go. As the device screen size change your UI element will scale appropriately.<\/span><\/p>\n<h2>UI interactions with Scripts<\/h2>\n<p>In the C# world the Unity elements can be created and modified as you would expect. You will want one or both of the following includes:<\/p>\n<pre>using UnityEngine.UI;\r\nusing UnityEngine.EventSystems;<\/pre>\n<h2>ColorBlock: Changing Button Colors<\/h2>\n<p>The ThreeBody game I am creating makes use of collections of buttons as radio boxes. I set the disabled and highlighted colors to reflect the color I want for unselected and selected. When it is time to enable a button, then the normal color of the button is set to the value in the highlighted color. It would be reasonable to expect that:<\/p>\n<pre>button.colors.normalColor = Color.white; \/\/ DOES NOT WORK!<\/pre>\n<p>would work. It does not. Instead you need to make a temporary copy of the ColorBlock and then modify its elements and copy back the ColorBlock:<\/p>\n<pre><span style=\"font-family: Menlo;\"><span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-style: italic; color: #999988;\">\/\/<\/span><span style=\"font-style: italic; color: #999988;\">\u00a0<\/span><span style=\"font-style: italic; color: #999988;\">flip<\/span><span style=\"font-style: italic; color: #999988;\">\u00a0<\/span><span style=\"font-style: italic; color: #999988;\">to<\/span><span style=\"font-style: italic; color: #999988;\">\u00a0<\/span><span style=\"font-style: italic; color: #999988;\">highlighted<\/span><span style=\"font-style: italic; color: #999988;\">\u00a0<\/span><span style=\"font-style: italic; color: #999988;\">color<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #009695;\">private<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #3363a4;\">void<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #444444;\">EnableButton<\/span><span style=\"color: #444444;\">(<\/span><span style=\"color: #3363a4;\">GameObject<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #444444;\">go<\/span><span style=\"color: #444444;\">)\u00a0{<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #444444;\">Button<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #444444;\">b2<\/span><span style=\"color: #444444;\">\u00a0=\u00a0<\/span><span style=\"color: #444444;\">go<\/span><span style=\"color: #444444;\">.<\/span><span style=\"color: #444444;\">GetComponent<\/span><span style=\"color: #444444;\">&lt;<\/span><span style=\"color: #444444;\">Button<\/span><span style=\"color: #444444;\">&gt;();\u00a0<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #444444;\">ColorBlock<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #444444;\">cb2<\/span><span style=\"color: #444444;\">\u00a0=\u00a0<\/span><span style=\"color: #444444;\">b2<\/span><span style=\"color: #444444;\">.<\/span><span style=\"color: #444444;\">colors<\/span><span style=\"color: #444444;\">;<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #444444;\">cb2<\/span><span style=\"color: #444444;\">.<\/span><span style=\"color: #444444;\">normalColor<\/span><span style=\"color: #444444;\">\u00a0=\u00a0<\/span><span style=\"color: #444444;\">cb2<\/span><span style=\"color: #444444;\">.<\/span><span style=\"color: #444444;\">highlightedColor<\/span><span style=\"color: #444444;\">;<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #444444;\">b2<\/span><span style=\"color: #444444;\">.<\/span><span style=\"color: #444444;\">colors<\/span><span style=\"color: #444444;\">\u00a0=\u00a0<\/span><span style=\"color: #444444;\">cb2<\/span><span style=\"color: #444444;\">;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0}\r\n<\/span>\r\n<\/span><\/pre>\n<h2>Touch Events and Buttons<\/h2>\n<p>Button touch events will still fall through into code that handles touches so it becomes important to screen out those touches that are over top of buttons. A technique that works for both mouse and touch events is:<\/p>\n<pre><span style=\"font-family: Menlo;\"><span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #009695;\">private<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #3363a4;\">bool<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #444444;\">IsTouchOnButton<\/span><span style=\"color: #444444;\">()\u00a0{<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #3363a4;\">GameObject<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #444444;\">go<\/span><span style=\"color: #444444;\">\u00a0=\u00a0<\/span><span style=\"color: #444444;\">EventSystem<\/span><span style=\"color: #444444;\">.<\/span><span style=\"color: #444444;\">current<\/span><span style=\"color: #444444;\">.<\/span><span style=\"color: #444444;\">currentSelectedGameObject<\/span><span style=\"color: #444444;\">;\u00a0<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #009695;\">if<\/span><span style=\"color: #444444;\">\u00a0(<\/span><span style=\"color: #444444;\">go<\/span><span style=\"color: #444444;\">\u00a0!=\u00a0<\/span><span style=\"color: #3363a4;\">null<\/span><span style=\"color: #444444;\">)\u00a0{<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #009695;\">if<\/span><span style=\"color: #444444;\">\u00a0(\u00a0<\/span><span style=\"color: #444444;\">go<\/span><span style=\"color: #444444;\">.<\/span><span style=\"color: #444444;\">GetComponent<\/span><span style=\"color: #444444;\">&lt;<\/span><span style=\"color: #444444;\">Button<\/span><span style=\"color: #444444;\">&gt;()\u00a0!=\u00a0<\/span><span style=\"color: #3363a4;\">null<\/span><span style=\"color: #444444;\">)\u00a0{<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #009695;\">return<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #3363a4;\">true<\/span><span style=\"color: #444444;\">;<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #009695;\">return<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #3363a4;\">false<\/span><span style=\"color: #444444;\">;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/span><\/pre>\n<h2>\u00a0Panel Fading and CanvasGroup<\/h2>\n<p>There is not a lot said about panels in the tutorials or online docs. These appear to be containers for holding a subset of the UI being developed. I found them useful for Settings Menus and High Score panes.\u00a0In order to run a fade effect on these panels, you can add a CanvasGroup (which then has a field &#8220;alpha&#8221; that allows direct control over fading). An example of such a fade coroutine is:<\/p>\n<pre><span style=\"font-family: Menlo;\"><span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0<span style=\"color: #009695;\">public<\/span>\u00a0<span style=\"color: #3363a4;\">GameObject<\/span>\u00a0menuPanel;\u00a0\r\n\u00a0   <\/span><span style=\"color: #009695;\">private<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #009695;\">const<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #3363a4;\">float<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #444444;\">FADE_TIME<\/span><span style=\"color: #444444;\">\u00a0=\u00a0<\/span><span style=\"color: #f57c00;\">0.5f<\/span><span style=\"color: #444444;\">;<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #009695;\">private<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #009695;\">const<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #3363a4;\">float<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #444444;\">FADE_STEPS<\/span><span style=\"color: #444444;\">\u00a0=\u00a0<\/span><span style=\"color: #f57c00;\">10f<\/span><span style=\"color: #444444;\">;<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #009695;\">private<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #009695;\">const<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #3363a4;\">float<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #444444;\">FADE_INCR<\/span><span style=\"color: #444444;\">\u00a0=\u00a0<\/span><span style=\"color: #444444;\">FADE_TIME<\/span><span style=\"color: #444444;\">\/<\/span><span style=\"color: #444444;\">FADE_STEPS<\/span><span style=\"color: #444444;\">;<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #009695;\">private<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #444444;\">IEnumerator<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #444444;\">FadeMenuPanel<\/span><span style=\"color: #444444;\">(<\/span><span style=\"color: #3363a4;\">bool<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #444444;\">visible<\/span><span style=\"color: #444444;\">)\u00a0{<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #444444;\">CanvasGroup<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #444444;\">cg<\/span><span style=\"color: #444444;\">\u00a0=\u00a0<\/span><span style=\"color: #444444;\">menuPanel<\/span><span style=\"color: #444444;\">.<\/span><span style=\"color: #444444;\">GetComponent<\/span><span style=\"color: #444444;\">&lt;<\/span><span style=\"color: #444444;\">CanvasGroup<\/span><span style=\"color: #444444;\">&gt;();<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #009695;\">if<\/span><span style=\"color: #444444;\">\u00a0(!<\/span><span style=\"color: #444444;\">visible<\/span><span style=\"color: #444444;\">)\u00a0{<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #009695;\">for<\/span><span style=\"color: #444444;\">\u00a0(<\/span><span style=\"color: #3363a4;\">float<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #444444;\">i<\/span><span style=\"color: #444444;\">=<\/span><span style=\"color: #444444;\">FADE_STEPS<\/span><span style=\"color: #444444;\">;\u00a0<\/span><span style=\"color: #444444;\">i<\/span><span style=\"color: #444444;\">\u00a0&gt;\u00a0<\/span><span style=\"color: #f57c00;\">0<\/span><span style=\"color: #444444;\">;\u00a0<\/span><span style=\"color: #444444;\">i<\/span><span style=\"color: #444444;\">--)\u00a0{<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #444444;\">cg<\/span><span style=\"color: #444444;\">.<\/span><span style=\"color: #444444;\">alpha<\/span><span style=\"color: #444444;\">\u00a0=\u00a0<\/span><span style=\"color: #444444;\">i<\/span><span style=\"color: #444444;\">\/<\/span><span style=\"color: #444444;\">FADE_STEPS<\/span><span style=\"color: #444444;\">;<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #009695;\">yield<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #009695;\">return<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #009695;\">new<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #3363a4;\">WaitForSeconds<\/span><span style=\"color: #444444;\">(<\/span><span style=\"color: #444444;\">FADE_INCR<\/span><span style=\"color: #444444;\">);<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #444444;\">cg<\/span><span style=\"color: #444444;\">.<\/span><span style=\"color: #444444;\">alpha<\/span><span style=\"color: #444444;\">\u00a0=\u00a0<\/span><span style=\"color: #f57c00;\">0.0f<\/span><span style=\"color: #444444;\">;<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #444444;\">menuPanel<\/span><span style=\"color: #444444;\">.<\/span><span style=\"color: #444444;\">SetActive<\/span><span style=\"color: #444444;\">(<\/span><span style=\"color: #3363a4;\">false<\/span><span style=\"color: #444444;\">);<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\u00a0<\/span><span style=\"color: #009695;\">else<\/span><span style=\"color: #444444;\">\u00a0{<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #444444;\">menuPanel<\/span><span style=\"color: #444444;\">.<\/span><span style=\"color: #444444;\">SetActive<\/span><span style=\"color: #444444;\">(<\/span><span style=\"color: #3363a4;\">true<\/span><span style=\"color: #444444;\">);\u00a0<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #444444;\">cg<\/span><span style=\"color: #444444;\">.<\/span><span style=\"color: #444444;\">alpha<\/span><span style=\"color: #444444;\">\u00a0=\u00a0<\/span><span style=\"color: #f57c00;\">0f<\/span><span style=\"color: #444444;\">;<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #009695;\">for<\/span><span style=\"color: #444444;\">\u00a0(<\/span><span style=\"color: #3363a4;\">float<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #444444;\">i<\/span><span style=\"color: #444444;\">\u00a0=\u00a0<\/span><span style=\"color: #f57c00;\">0f<\/span><span style=\"color: #444444;\">;\u00a0<\/span><span style=\"color: #444444;\">i<\/span><span style=\"color: #444444;\">\u00a0&lt;=\u00a0<\/span><span style=\"color: #444444;\">FADE_STEPS<\/span><span style=\"color: #444444;\">;\u00a0<\/span><span style=\"color: #444444;\">i<\/span><span style=\"color: #444444;\">++)\u00a0{<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #444444;\">cg<\/span><span style=\"color: #444444;\">.<\/span><span style=\"color: #444444;\">alpha<\/span><span style=\"color: #444444;\">\u00a0=\u00a0<\/span><span style=\"color: #444444;\">i<\/span><span style=\"color: #444444;\">\/<\/span><span style=\"color: #444444;\">FADE_STEPS<\/span><span style=\"color: #444444;\">;<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #009695;\">yield<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #009695;\">return<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #009695;\">new<\/span><span style=\"color: #444444;\">\u00a0<\/span><span style=\"color: #3363a4;\">WaitForSeconds<\/span><span style=\"color: #444444;\">(<\/span><span style=\"color: #444444;\">FADE_INCR<\/span><span style=\"color: #444444;\">);<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #444444;\">cg<\/span><span style=\"color: #444444;\">.<\/span><span style=\"color: #444444;\">alpha<\/span><span style=\"color: #444444;\">\u00a0=\u00a0<\/span><span style=\"color: #f57c00;\">1.0f<\/span><span style=\"color: #444444;\">;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span>\r\n<span style=\"color: #444444;\">\u00a0\u00a0\u00a0\u00a0}\r\n\r\n<\/span><\/span><\/pre>\n<p>Note that in my case I\u00a0also change the panel active status. This needs to be done at the end of the fade out or the start of the fade in for the object to stay visible during the fade.<\/p>\n<h2>Off-Topic: Trail Renderers<\/h2>\n<p>This is not part of the new Unity UI theme but as part of getting ThreeBody ready I had to learn a bit about TrailRenders. I use these to leave paths behind the &#8220;stars&#8221; in ThreeBody so the orbital paths can be seen. I always had weird issues with setting materials and colors until I finally found some clear advice on the forums about the material choice. I need to choose a particle material and the trails look best with a mobile\/particle\/vertex-lit shader on that material. To get solid colors I have created a simple 128&#215;128 solid color PNG, imported as a texture.<\/p>\n<p>Another tidbit is how to recycle objects once you have used trail generation. To get rid of the trail I ended up setting the trail length to -1, then counting 5 update cycles before setting the object inactive and putting it back into my object pool. I played around with coroutines for this but they ended up creating more complications &#8211; and a simple synchronous design won out.<\/p>\n<p>Hope some of these save you some time.<\/p>\n<p>[social4i size=&#8221;large&#8221; align=&#8221;float-right&#8221;]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Unity 4.6 provides a fantastic new UI framework. I will never use the old OnGui() again! I have been using the new framework for the past several months while Unity 4.6 was in beta. During this time I have collected a few tidbits on working with the framework. Getting Started The tutorials\u00a0\u00a0are very good and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-96","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3pCRa-1y","_links":{"self":[{"href":"https:\/\/nbodyphysics.com\/blog\/wp-json\/wp\/v2\/posts\/96","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nbodyphysics.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nbodyphysics.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nbodyphysics.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nbodyphysics.com\/blog\/wp-json\/wp\/v2\/comments?post=96"}],"version-history":[{"count":5,"href":"https:\/\/nbodyphysics.com\/blog\/wp-json\/wp\/v2\/posts\/96\/revisions"}],"predecessor-version":[{"id":181,"href":"https:\/\/nbodyphysics.com\/blog\/wp-json\/wp\/v2\/posts\/96\/revisions\/181"}],"wp:attachment":[{"href":"https:\/\/nbodyphysics.com\/blog\/wp-json\/wp\/v2\/media?parent=96"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nbodyphysics.com\/blog\/wp-json\/wp\/v2\/categories?post=96"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nbodyphysics.com\/blog\/wp-json\/wp\/v2\/tags?post=96"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}