{"id":231,"date":"2010-11-14T05:32:06","date_gmt":"2010-11-14T05:32:06","guid":{"rendered":"http:\/\/pixelplacement.com\/?p=231"},"modified":"2017-01-12T04:49:39","modified_gmt":"2017-01-12T04:49:39","slug":"itween-for-unity","status":"publish","type":"post","link":"https:\/\/www.pixelplacement.com\/site\/2010\/11\/14\/itween-for-unity\/","title":{"rendered":"iTween for Unity"},"content":{"rendered":"<p>iTween is an animation library I created which focuses on the premise of \u201cminimum input for maximum output\u201d to make your life easier when it comes to shaking, spinning, moving, fading, coloring, controlling audio, fading cameras, and just about everything else you can think of in Unity.<!--more--><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1475\" src=\"https:\/\/www.pixelplacement.com\/site\/wp-content\/uploads\/2010\/11\/itween11.jpg\" alt=\"\" width=\"800\" height=\"415\" srcset=\"https:\/\/www.pixelplacement.com\/site\/wp-content\/uploads\/2010\/11\/itween11.jpg 800w, https:\/\/www.pixelplacement.com\/site\/wp-content\/uploads\/2010\/11\/itween11-300x156.jpg 300w, https:\/\/www.pixelplacement.com\/site\/wp-content\/uploads\/2010\/11\/itween11-768x398.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>At it&#8217;s core, iTween is an interpolation system that takes one value and animates it to another over a given amount of time. Where iTween shines is in its action-specific syntax that frees you from a production or coding mind-set and places you in more of an action-movie director position. At the end of the day iTween allows you to command, point, and lovingly coerce, while speeding up nearly every facet of your development process without sacrificing production value.<\/p>\n<h4>But I can already do these things by&#8230;<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1477\" src=\"https:\/\/www.pixelplacement.com\/site\/wp-content\/uploads\/2010\/11\/itween31.jpg\" alt=\"\" width=\"800\" height=\"415\" srcset=\"https:\/\/www.pixelplacement.com\/site\/wp-content\/uploads\/2010\/11\/itween31.jpg 800w, https:\/\/www.pixelplacement.com\/site\/wp-content\/uploads\/2010\/11\/itween31-300x156.jpg 300w, https:\/\/www.pixelplacement.com\/site\/wp-content\/uploads\/2010\/11\/itween31-768x398.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>Now, before we dig into the \u201chow-to&#8217;s\u201d of iTween let&#8217;s answer the \u201cwhy\u201d behind it&#8217;s existence. As the saying goes, \u201cthere&#8217;s more than one way to skin a cat\u201d and getting things to come alive in Unity is no exception to that rule. You can animate in external 3D applications or with Unity&#8217;s built in animation timeline; You can utilize JavaScript, C# or Boo and tackle things through pure, monotonous code; You can realize that you sit somewhere in the middle of these talent spectrums and ponder if you can afford the cost of someone who knows what you don&#8217;t. Now don&#8217;t get me wrong, before I show you proof of it&#8217;s abilities, I want to make it known that iTween is NO slouch when it comes to creating powerful results; simplicity does not equal simple in this case. In fact it&#8217;s been battle-tested by big and small game studios, follows the solid foundations of tweening libraries in the Adobe Flash world, and my son thinks it&#8217;s cooler than sliced bread. The bottom line is iTween is efficient, fast, simple and fits into nearly every project for use in simply adding pizazz all the way up to powering fundamental game mechanics and systems.<\/p>\n<h4>Ok, I&#8217;m still here. Where do I start?<\/h4>\n<p>iTween is available for download from <a href=\"http:\/\/itween.pixelplacement.com\" target=\"_blank\">http:\/\/itween.pixelplacement.com<\/a>. iTween is a single C# file that can be used with ANY of the programming languages that Unity supports, as well as all versions of Unity. If you plan on using JavaScript or Boo you will need to create a \u201cPlugins\u201d folder (if you don&#8217;t already have one) in your \u201cAssets\u201d folder for iTween to live in. If you plan on using C# you can place it anywhere you want within your \u201cAssets\u201d folder. That&#8217;s it for installation; I told you \u201cminimum input for maximum output\u201d.<\/p>\n<h4>Hello World!<\/h4>\n<p>Before we get into actually using iTween there&#8217;s a few basic things I want to point out:<\/p>\n<ul class=\"list\">\n<li>Nearly all of iTween&#8217;s methods have 2 \u201cflavors\u201d: a \u201csimple\u201d version and a \u201ccustomizable\u201d version.<\/li>\n<li>The \u201ccustomizable\u201d versions of iTween methods use Hashtables for their property setting.<\/li>\n<li>Nearly every iTween method needs a reference to a GameObject.<\/li>\n<li>iTween can be used in Update functions for repeated calls but there are specific methods included, which are geared towards this and offer significant performance benefits.<\/li>\n<\/ul>\n<p>iTween can do tons of things but let&#8217;s start with something simple; moving from one position to another. The tool for this challenge is iTween&#8217;s MoveTo() method. Lets animate a GameObject from it&#8217;s current position to (2,0,0) over 2 seconds using the \u201csimple\u201d version of MoveTo():<\/p>\n<pre>iTween.MoveTo(gameObject, Vector3(2,0,0), 3);<\/pre>\n<p>Simple, and easy, but what if we wanted some more control over this animation? We would need to use the \u201ccustomizable\u201d version of MoveTo() and provide it&#8217;s properties with a Hashtable:<\/p>\n<pre>iTween.MoveTo(gameObject, {\u201cx\u201d:2, \u201ctime\u201d:3, \u201cloopType\u201d:\u201dpingPong\u201d, \u201cdelay\u201d:1));<\/pre>\n<p>This call to MoveTo() will still animate the GameObject&#8217;s position on the \u201cx\u201d axis to a value of 2 over a span of 3 seconds but it will also delay this animation for 1 second and ping-pong the motion back and forth.<\/p>\n<p>To unlock the real power of iTween you will want to dig into the \u201ccustomizable\u201d versions of each method and all of their parameters (for a complete list please consult the documentation page at <a href=\"http:\/\/itween.pixelplacement.com\/documentation.php\" target=\"_blank\">http:\/\/itween.pixelplacement.com\/documentation.php<\/a>).<\/p>\n<h4>Hashtables are ugly.<\/h4>\n<p>There&#8217;s a plethora of parameters for you to tweak and play with. In fact, MoveTo() is capable of taking a series of points in space that can be used as a smooth path to follow with the \u201cpath\u201d parameter. The only problem is that with great power comes REAL ugly, but its an ugly you can live with.<\/p>\n<p>Where \u201cugly\u201d really rears its head is with using iTween from C#:<\/p>\n<pre>Hashtable parameters = new Hashtable();\r\nparameters.Add(\"x\",2);\r\nparameters.Add(\"time\",3);\r\nparameters.Add(\"looptype\",iTween.LoopType.pingPong);\r\nparameters.Add(\"delay\",1);\r\niTween.MoveTo(gameObject, parameters);\r\n<\/pre>\n<p>If you are keeping count that&#8217;s 6 times the amount of work it took the JavaScript example from earlier to do the exact same thing. That&#8217;s hardly in keeping with \u201cminimum input for maximum output\u201d! But never fear, iTween has a solution to make C# just as concise as the JavaScript version; say \u201chello\u201d to Hash(). With iTween&#8217;s Hash() method we can shorten that C# script down to:<\/p>\n<pre>iTween.MoveTo(gameObject, iTween.Hash(\u201cx\u201d,2,\u201ctime\u201d,3,\u201cloopType\u201d,\u201dpingPong\u201d,\u201cdelay\u201d,1));<\/pre>\n<p>Much better! Notice Hash() takes alternating values of a parameter followed by a value.<\/p>\n<h4>All this for the enormous price of free.<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1478\" src=\"https:\/\/www.pixelplacement.com\/site\/wp-content\/uploads\/2010\/11\/itween21.jpg\" alt=\"\" width=\"800\" height=\"415\" srcset=\"https:\/\/www.pixelplacement.com\/site\/wp-content\/uploads\/2010\/11\/itween21.jpg 800w, https:\/\/www.pixelplacement.com\/site\/wp-content\/uploads\/2010\/11\/itween21-300x156.jpg 300w, https:\/\/www.pixelplacement.com\/site\/wp-content\/uploads\/2010\/11\/itween21-768x398.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>iTween is backed by a regularly updated support site that contains numerous examples, full documentation and information for receiving support and reporting bugs. The only cost to you for iTween is the grand total of absolutely nothing. That&#8217;s right, I worked tirelessly on iTween for roughly 5 months while taking care of my pregnant wife, working my day job as the Interactive Creative Director at Bully! Entertainment (<a href=\"http:\/\/bullyentertainment.com\" target=\"_blank\">http:\/\/bullyentertainment.com<\/a>), spending time with my 9-year-old son, playing with our 2 dogs, shunning our 2 cats, completing many home improvement projects and completely avoiding sleep. My goal behind this endeavor was to help the community, get my name circulated and to learn C#. I&#8217;m where I am in my career as a result of many nameless individuals who have answered questions and offered help over the past 15 years and I want to pay this forward in the hopes of helping others.<\/p>\n<p>iTween isn&#8217;t the solution for every problem you&#8217;ll face but I hope it works well for everything you need it for. My hope is that my hard work will help many, including myself, put out creative and quality projects with \u201cminimum input for maximum output\u201d. Good luck with everything you attempt.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>iTween is an animation library I created which focuses on the premise of \u201cminimum input for maximum output\u201d to make your life easier when it comes to shaking, spinning, moving, fading, coloring, controlling audio, fading cameras, and just about everything else you can think of in Unity.<\/p>\n","protected":false},"author":1,"featured_media":1474,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[14,15,21,36,42,46,75,76,77,82,85],"_links":{"self":[{"href":"https:\/\/www.pixelplacement.com\/site\/wp-json\/wp\/v2\/posts\/231"}],"collection":[{"href":"https:\/\/www.pixelplacement.com\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pixelplacement.com\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pixelplacement.com\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pixelplacement.com\/site\/wp-json\/wp\/v2\/comments?post=231"}],"version-history":[{"count":3,"href":"https:\/\/www.pixelplacement.com\/site\/wp-json\/wp\/v2\/posts\/231\/revisions"}],"predecessor-version":[{"id":1582,"href":"https:\/\/www.pixelplacement.com\/site\/wp-json\/wp\/v2\/posts\/231\/revisions\/1582"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pixelplacement.com\/site\/wp-json\/wp\/v2\/media\/1474"}],"wp:attachment":[{"href":"https:\/\/www.pixelplacement.com\/site\/wp-json\/wp\/v2\/media?parent=231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pixelplacement.com\/site\/wp-json\/wp\/v2\/categories?post=231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pixelplacement.com\/site\/wp-json\/wp\/v2\/tags?post=231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}