<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3744480327179109411</id><updated>2024-09-17T15:09:09.021-07:00</updated><category term="UNITY 3D"/><category term="蚊囈青年"/><category term="GameJam作品"/><category term="Python"/><category term="C語言"/><category term="PHP"/><category term="iOS"/><category term="遊戲探討"/><category term="遊戲試做"/><title type='text'>蚊子的程式設計路</title><subtitle type='html'>給我一種程式語言，我就變出一個世界。</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>37</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-907283412760937926</id><published>2015-08-26T08:37:00.000-07:00</published><updated>2015-12-08T09:59:11.936-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="UNITY 3D"/><title type='text'>UNITY3D - 用程式更改animation關鍵影格 change animation clip property value by script</title><content type='html'>&lt;div dir=&quot;ltr&quot;&gt;
有時候我們會需要物件的移動數值是可調整的，但可能因為架構上大量使用mecanim(animator)導致難以改用程式去控制物件移動。&lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
這時候我們可以用程式更改animator所讀取的animation clip，將裡面的關鍵影格資訊改成所需要的數值。&lt;br /&gt;
善加利用state machine加上可變動的animation，mecanim的使用彈性就更高了。&lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
&lt;br /&gt;
所用到的function : &lt;a href=&quot;http://docs.unity3d.com/ScriptReference/AnimatorOverrideController.html&quot; target=&quot;_blank&quot;&gt;AnimatorOverrideController&lt;/a&gt;,&amp;nbsp;&lt;a href=&quot;http://docs.unity3d.com/ScriptReference/AnimationClip.SetCurve.html&quot; target=&quot;_blank&quot;&gt;AnimationClip.SetCurve&lt;/a&gt;,&amp;nbsp;&lt;a href=&quot;http://docs.unity3d.com/ScriptReference/AnimationClip.AddEvent.html&quot; target=&quot;_blank&quot;&gt;AnimationClip.AddEvent&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://docs.unity3d.com/ScriptReference/AnimationClip.SetCurve.html&quot; target=&quot;_blank&quot;&gt;AnimationClip.SetCurve&lt;/a&gt;只會新增或蓋掉原本clip中有設定的property，要刪除某個property則在第四個參數(AnimationCurve)傳入null即可。&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;※注意，&lt;a href=&quot;http://docs.unity3d.com/ScriptReference/AnimationClip.SetCurve.html&quot; target=&quot;_blank&quot;&gt;AnimationClip.SetCurve&lt;/a&gt;只在Editor上有效！&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
Runtime會更改專案中animation clip的寫法&lt;/div&gt;
&lt;pre class=&quot;code prettyprint lang-cs linenums:7&quot;&gt;//Change transform.localPosition.x move 0~100
//Change sprite.color.a 1~0
//Add event call Ready and pass parameter on 1sec
//gameObject structure:  gameObject:transform
//                           |
//                           --- child:SpriteRenderer
void ChangeAnimCurve () {
    Animator _animator = GetComponent();
    AnimatorOverrideController myOverrideController = new AnimatorOverrideController();
    myOverrideController.runtimeAnimatorController = _animator.runtimeAnimatorController;
    AnimationClip clip = myOverrideController[&quot;clipname&quot;];
    clip.SetCurve(&quot;&quot;, typeof(Transform), &quot;localPosition.x&quot;, new AnimationCurve(new Keyframe(0f, 0f), new Keyframe(1f, 100f)));
    clip.SetCurve(&quot;child&quot;, typeof(SpriteRenderer), &quot;m_Color.a&quot;, new AnimationCurve(new Keyframe(0f, 1f), new Keyframe(1f, 0f)));
    AnimationEvent evt = new AnimationEvent ();
    evt.functionName = &quot;Ready&quot;;
    evt.intParameter = 1;
    evt.time = 1f; //make sure there got a keyframe
    clip.AddEvent (evt); //events added with AddEvent will only persist until play mode is exited of player is quit.
    _animator.runtimeAnimatorController = myOverrideController;
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot;&gt;
不更改專案中animation clip的寫法&lt;/div&gt;
&lt;pre class=&quot;code prettyprint lang-cs linenums:7&quot;&gt;//Change transform.localPosition.x move 0~100
//Change sprite.color.a 1~0
//Add event call Ready and pass parameter on 1sec
//gameObject structure:  gameObject:transform
//                           |
//                           --- child:SpriteRenderer
void ChangeAnimCurve () {
    Animator _animator = GetComponent();
    AnimatorOverrideController myOverrideController = new AnimatorOverrideController();
    myOverrideController.runtimeAnimatorController = _animator.runtimeAnimatorController;
    AnimationClip clip = new AnimationClip();
    clip.SetCurve(&quot;&quot;, typeof(Transform), &quot;localPosition.x&quot;, new AnimationCurve(new Keyframe(0f, 0f), new Keyframe(1f, 100f)));
    clip.SetCurve(&quot;child&quot;, typeof(SpriteRenderer), &quot;m_Color.a&quot;, new AnimationCurve(new Keyframe(0f, 1f), new Keyframe(1f, 0f)));
    AnimationEvent evt = new AnimationEvent ();
    evt.functionName = &quot;Ready&quot;;
    evt.intParameter = 1;
    evt.time = 1f; //make sure there got a keyframe
    clip.AddEvent (evt); //events added with AddEvent will only persist until play mode is exited of player is quit.
    myOverrideController[&quot;clipname&quot;] = clip;
    _animator.runtimeAnimatorController = myOverrideController;
}
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/907283412760937926/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2015/08/unity3d-animation-change-animation-clip.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/907283412760937926'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/907283412760937926'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2015/08/unity3d-animation-change-animation-clip.html' title='UNITY3D - 用程式更改animation關鍵影格 change animation clip property value by script'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-7675368291519478215</id><published>2015-06-09T07:17:00.000-07:00</published><updated>2015-06-09T07:17:04.582-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="遊戲探討"/><title type='text'>遊戲探討 — FPS/TPS射擊遊戲準心設計</title><content type='html'>&lt;div dir=&quot;ltr&quot;&gt;
因為眼力不好所以很少玩射擊遊戲，但最近有在進行射擊相關的遊戲開發，就來研究一下射擊遊戲的&quot;眉角&quot;。&lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
射擊遊戲一般都有準心輔助玩家瞄準目標物；跟現實射擊類似，由視角槍口目標物三點成三角形，子彈在一定距離下才會準確命中目標物。&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://upload.wikimedia.org/wikipedia/en/d/d6/Figure_2-_Illustration_of_a_Rifle_Showing_Line_of_Sight_and_Bore_Angle..jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://upload.wikimedia.org/wikipedia/en/d/d6/Figure_2-_Illustration_of_a_Rifle_Showing_Line_of_Sight_and_Bore_Angle..jpg&quot; height=&quot;71&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
(&lt;a href=&quot;http://en.wikipedia.org/wiki/Rifleman&#39;s_rule&quot; target=&quot;_blank&quot;&gt;圖片引用處&lt;/a&gt;)&lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
而遊戲為了體貼玩家，避免摸索這個有效距離，會設計成以準心對到的物體為有效距離再以槍口倒推這個三角形(實做上是以準心射出射線，再以射線終點當目標點，子彈從槍口朝目標點移動)&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqkKplOYyj829PyP_CDLOtQEd4B3JL4oncp1jB-0NgUUkqiZDykrfgcNy23VcAz9yqrk9JJboqwUTtF8YB_VpW4xuGlS3hn1e7RCoo6WjNa4Wl6MGC1rFuNa7dyaioyBtV4ORetVl2i2sI/s1600/near.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;238&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqkKplOYyj829PyP_CDLOtQEd4B3JL4oncp1jB-0NgUUkqiZDykrfgcNy23VcAz9yqrk9JJboqwUTtF8YB_VpW4xuGlS3hn1e7RCoo6WjNa4Wl6MGC1rFuNa7dyaioyBtV4ORetVl2i2sI/s320/near.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
目標點近時&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
(這畫面視角不好畫出準心、目標物、槍口的三角形，直角只是槍口跟目標物的交叉，與下圖做比較可發現三角形的不同)&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEja5T6ucYF2keQ0N0bAx74APImLsAFgSNqqJTWbqbR_Sqtis49tnO3ZBAWB_LiwKdIRauMlYHePrAxOnQHAaf0kEijgrIv_cBUG1XayT-1q3y3KPlcUPpMFCbk5Z-4kDE94j1Fmao4n6_Jy/s1600/far.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEja5T6ucYF2keQ0N0bAx74APImLsAFgSNqqJTWbqbR_Sqtis49tnO3ZBAWB_LiwKdIRauMlYHePrAxOnQHAaf0kEijgrIv_cBUG1XayT-1q3y3KPlcUPpMFCbk5Z-4kDE94j1Fmao4n6_Jy/s320/far.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
目標點遠時&lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
但這有個問題是連射並且目標點改變(物體移動或消失)狀況下，會發現子彈軌跡改變，下兩張圖準心接近但可以很明顯看到軌跡不同。&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjueOWwi8qbSQJzii1bz_fEcyHoRX9Ry4mgcRDIQMvYvqDuNkEpSsxUDShww6lpyJMLg9XZTaZmVG0aQB2yCqVhWtFDKNj6wwdjxYNQ3xviAEnJzIpotd7Vxze9bw30wxgC-rB0Mqt1iPUc/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2015-06-09+%25E4%25B8%258B%25E5%258D%258810.05.50.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;119&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjueOWwi8qbSQJzii1bz_fEcyHoRX9Ry4mgcRDIQMvYvqDuNkEpSsxUDShww6lpyJMLg9XZTaZmVG0aQB2yCqVhWtFDKNj6wwdjxYNQ3xviAEnJzIpotd7Vxze9bw30wxgC-rB0Mqt1iPUc/s320/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2015-06-09+%25E4%25B8%258B%25E5%258D%258810.05.50.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
為了放大這問題把準心移到角落，方塊為子彈圓球為槍口(起始點)，&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
假設目標物較近時子彈軌跡&lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJeHxxIcssfwxcI6Haaek3yVCHhvhULeFIJZnXfbPboxY7dSzubBmpwTchO1lYq7DT84WaeHICTGToXr2yLJaQd4FzbuikDxsEJ66v1fwr54m59lcB-chez-bR8n9ov7owVq4XDwVAQRBR/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2015-06-09+%25E4%25B8%258B%25E5%258D%258810.05.37.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;128&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJeHxxIcssfwxcI6Haaek3yVCHhvhULeFIJZnXfbPboxY7dSzubBmpwTchO1lYq7DT84WaeHICTGToXr2yLJaQd4FzbuikDxsEJ66v1fwr54m59lcB-chez-bR8n9ov7owVq4XDwVAQRBR/s320/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2015-06-09+%25E4%25B8%258B%25E5%258D%258810.05.37.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
目標物消失或目標改為較後方的另一目標物時子彈軌跡&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
改善這問題的方法就是盡量拉近準心跟槍口的距離(縮小三角形面積，讓軌跡變化變小)，連射時加上隨機偏差值(讓玩家忽略軌跡改變)。&lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
也可能有別的改善方法，希望有人能提出來讓大家參考看看。&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/7675368291519478215/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2015/06/fpstps_9.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/7675368291519478215'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/7675368291519478215'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2015/06/fpstps_9.html' title='遊戲探討 — FPS/TPS射擊遊戲準心設計'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqkKplOYyj829PyP_CDLOtQEd4B3JL4oncp1jB-0NgUUkqiZDykrfgcNy23VcAz9yqrk9JJboqwUTtF8YB_VpW4xuGlS3hn1e7RCoo6WjNa4Wl6MGC1rFuNa7dyaioyBtV4ORetVl2i2sI/s72-c/near.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-3017971418286697886</id><published>2014-01-20T09:59:00.001-08:00</published><updated>2014-01-20T09:59:26.607-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="UNITY 3D"/><title type='text'>Unity 3D - Facebook SDK for Unity測試心得</title><content type='html'>Facebook推出SDK for Unity已經有段時間了(不過好像一直在beta版？)...&lt;br /&gt;
&lt;br /&gt;
之前的專案因為Facebook SDK還不見蹤影而使用了prime31的SocialNetwork plugin來開發，現在總算有閒可以來測測這東西了。&lt;br /&gt;
&lt;br /&gt;
在設定上Facebook參考了(我覺得啦...)prime31的設定方法，也就是用個asset檔來記錄設定，但Facebook做得更好的是在Unity介面上只要設定好Facebook App Id就幾乎大功告成了，其他需要輸入到Facebook介面上的資料也很貼心的整理好等著複製，甚至貼心到連Debug Android Key Hash也抓好了！&lt;br /&gt;
&lt;br /&gt;
但發生了件令人費解的事情是Web版可以正常登入Facebook帳號也可以發文章，偏偏Android卻怎樣也無法登入...&lt;br /&gt;
&lt;br /&gt;
查了許久才發現Facebook SDK自動生成的AndroidManifest檔案裡面&lt;span style=&quot;color: orange; font-family: Menlo;&quot;&gt;activity&lt;/span&gt;&lt;span style=&quot;color: orange; font-family: Menlo;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orange; font-family: Menlo;&quot;&gt;android&lt;/span&gt;&lt;span style=&quot;color: orange; font-family: Menlo;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: orange; font-family: Menlo;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: orange; font-family: Menlo;&quot;&gt;=&quot;&lt;/span&gt;&lt;span style=&quot;color: orange; font-family: Menlo;&quot;&gt;com&lt;/span&gt;&lt;span style=&quot;color: orange; font-family: Menlo;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: orange; font-family: Menlo;&quot;&gt;unity3d&lt;/span&gt;&lt;span style=&quot;color: orange; font-family: Menlo;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: orange; font-family: Menlo;&quot;&gt;player&lt;/span&gt;&lt;span style=&quot;color: orange; font-family: Menlo;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;font-family: Menlo;&quot;&gt;&lt;span style=&quot;color: orange;&quot;&gt;UnityPlayerNativeActivity&quot;&lt;/span&gt;&lt;/span&gt;沒有被替換成&lt;span style=&quot;color: orange; font-family: Menlo;&quot;&gt;com&lt;/span&gt;&lt;span style=&quot;color: orange; font-family: Menlo;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: orange; font-family: Menlo;&quot;&gt;facebook&lt;/span&gt;&lt;span style=&quot;color: orange; font-family: Menlo;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: orange; font-family: Menlo;&quot;&gt;unity&lt;/span&gt;&lt;span style=&quot;color: orange; font-family: Menlo;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;font-family: Menlo;&quot;&gt;&lt;span style=&quot;color: orange;&quot;&gt;FBUnityPlayerActivity&lt;/span&gt;&lt;/span&gt;，只要修改好這點就可以正常使用無誤了。</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/3017971418286697886/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2014/01/unity-3d-facebook-sdk-for-unity.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/3017971418286697886'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/3017971418286697886'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2014/01/unity-3d-facebook-sdk-for-unity.html' title='Unity 3D - Facebook SDK for Unity測試心得'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-8026222490924468728</id><published>2014-01-16T01:28:00.002-08:00</published><updated>2014-01-16T22:17:05.637-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="UNITY 3D"/><title type='text'>UNITY3D - Time.timeScale</title><content type='html'>&lt;p dir=&quot;ltr&quot;&gt;&amp;#22312;&amp;#36938;&amp;#25138;&amp;#20013;&amp;#24120;&amp;#26371;&amp;#29992;&amp;#21040;&amp;#36938;&amp;#25138;&amp;#26283;&amp;#20572;&amp;#30340;&amp;#21151;&amp;#33021;&amp;#65292;Unity&amp;#20063;&amp;#25552;&amp;#20379;&amp;#20102;&amp;#30456;&amp;#38364;&amp;#30340;&amp;#21151;&amp;#33021;&amp;#23601;&amp;#26159;&amp;#23559;Time.timeScale&amp;#35373;0&amp;#12290;&lt;br&gt;
&amp;#20294;&amp;#30456;&amp;#20449;&amp;#24456;&amp;#22810;&amp;#20154;&amp;#26371;&amp;#25630;&amp;#19981;&amp;#28165;&amp;#26970;Time.timeScale&amp;#26371;&amp;#24433;&amp;#38911;&amp;#21738;&amp;#20123;&amp;#26481;&amp;#35199;&amp;#65292;&amp;#20197;&amp;#19979;&amp;#23601;&amp;#20358;&amp;#21015;&amp;#19968;&amp;#19979;&amp;#26371;&amp;#34987;Time.timeScale&amp;#24433;&amp;#38911;&amp;#30340;&amp;#37096;&amp;#20998;&amp;#12290;&lt;/p&gt;
&lt;p dir=&quot;ltr&quot;&gt;1.FixedUpdate - &amp;#23448;&amp;#26041;&amp;#25991;&amp;#20214;&amp;#20063;&amp;#32882;&amp;#26126;&amp;#20102;Time.timeScale&amp;#29234;0&amp;#26178;FixedUpdate&amp;#19981;&amp;#26371;&amp;#34987;&amp;#21628;&amp;#21483;&amp;#12290;&lt;br&gt;
2.Rigidbody - Rigidbody&amp;#30340;&amp;#29289;&amp;#29702;&amp;#36939;&amp;#31639;&amp;#36319;FixedUpdate&amp;#26377;&amp;#36899;&amp;#24118;&amp;#38364;&amp;#20418;&amp;#65292;&amp;#33258;&amp;#28982;&amp;#20063;&amp;#23601;&amp;#19981;&amp;#26371;&amp;#21205;&amp;#20316;&amp;#12290;&lt;br&gt;
3.Time.time, Time.deltaTime, Time.fixedDeltaTime&amp;#36889;&amp;#20123;&amp;#36319;timeScale&amp;#24687;&amp;#24687;&amp;#30456;&amp;#38364;&amp;#30340;&amp;#25976;&amp;#20540;&amp;#20063;&amp;#19968;&amp;#27171;&amp;#36867;&amp;#19981;&amp;#20102;&amp;#65292;Time.time&amp;#26371;&amp;#20572;&amp;#27490;&amp;#12289;deltaTime&amp;#26371;&amp;#35722;0&amp;#12290;&lt;br&gt;
4.Animation - &amp;#38750;&amp;#24120;&amp;#20381;&amp;#36084;time&amp;#30340;&amp;#21151;&amp;#33021;&amp;#30070;&amp;#28982;&amp;#20063;&amp;#23601;&amp;#19981;&amp;#26371;&amp;#21205;&amp;#20102;&amp;#12290;&lt;br&gt;
5.WaitForSeconds - &amp;#19968;&amp;#27171;&amp;#26159;&amp;#20381;&amp;#36084;time&amp;#20358;&amp;#20570;&amp;#36939;&amp;#31639;&amp;#34389;&amp;#29702;&amp;#65292;&amp;#37027;&amp;#23601;&amp;#19968;&amp;#27171;&amp;#26371;&amp;#20572;&amp;#27490;&amp;#36939;&amp;#20316;&amp;#12290;&lt;br&gt;
6.WaitForFixedUpdate - FixedUpdate&amp;#37117;&amp;#19981;&amp;#21205;&amp;#20102;&amp;#65292;&amp;#37027;&amp;#33258;&amp;#28982;&amp;#36889;&amp;#20063;&amp;#26371;&amp;#20572;&amp;#27490;&amp;#36939;&amp;#20316;&amp;#20102;&amp;#12290;&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/8026222490924468728/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2014/01/unity3d-timetimescale.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/8026222490924468728'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/8026222490924468728'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2014/01/unity3d-timetimescale.html' title='UNITY3D - Time.timeScale'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-9169415086575509180</id><published>2013-11-14T01:04:00.003-08:00</published><updated>2015-08-26T06:29:29.297-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="UNITY 3D"/><title type='text'>UNITY3D - Unity遊戲開發基礎Q&amp;A</title><content type='html'>因為換工作交接的關係，才讓我意識到一般的程式設計人員要理解Unity有蠻大的障礙，如果有開發過遊戲或許還好一點，但如果只開發過一般應用程式的話就幾乎要重新理解觀念了。&lt;br /&gt;
&lt;br /&gt;
Q1.Unity開發的程式進入點是什麼？&lt;br /&gt;
A1.Unity並沒有所謂的主程式進入點，遊戲以“場景”為一個主體，並且“場景”中有多個“遊戲物件”，每個“遊戲物件”內有一或多個“行為元件”。“行為元件”內才有所謂的起始進入點&lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.Awake.html&quot; style=&quot;color: #145d7b; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;Awake&lt;/a&gt;，但要注意的是除非有經過&lt;a href=&quot;http://docs.unity3d.com/Documentation/Components/class-ScriptExecution.html&quot; target=&quot;_blank&quot;&gt;設定每個“行為元件”的執行順序&lt;/a&gt;，不然在執行時“行為元件”的執行順序是不一定的。&lt;br /&gt;
&lt;br /&gt;
Q2.寫好的Class怎麼使用呢？&lt;br /&gt;
A2.Unity內新增的程式檔案預設都會繼承MonoBehaviour，只要繼承MonoBehaviour就可以將這程式附加到“遊戲物件”上成為“行為元件”。&lt;span style=&quot;color: red;&quot;&gt;只有在場景中的行為元件上的&lt;/span&gt;&lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.Awake.html&quot; style=&quot;color: #145d7b; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;Awake&lt;/a&gt;&lt;span style=&quot;color: red;&quot;&gt;、&lt;/span&gt;&lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.Start.html&quot; style=&quot;color: #145d7b; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;Start&lt;/a&gt;&lt;span style=&quot;color: red;&quot;&gt;...等等MonoBehaviour的函式才會被執行。&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
Q3.MonoBehaviour有哪些函式？在什麼情況下用？&lt;br /&gt;
A3.通常最常用的是&lt;br /&gt;
&lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.Awake.html&quot; style=&quot;color: #145d7b; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;Awake&lt;/a&gt;
、&lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.Start.html&quot; style=&quot;color: #145d7b; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;Start&lt;/a&gt;、&lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.Update.html&quot; style=&quot;color: #145d7b; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;Update&lt;/a&gt;還有碰撞相關的&lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnCollisionEnter.html&quot; style=&quot;color: #145d7b; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;OnCollisionEnter&lt;/a&gt;、&lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnTriggerEnter.html&quot; style=&quot;color: #145d7b; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;OnTriggerEnter&lt;/a&gt;，&lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.Awake.html&quot; style=&quot;color: #145d7b; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;Awake&lt;/a&gt;&amp;nbsp;、&lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.Start.html&quot; style=&quot;color: #145d7b; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;Start&lt;/a&gt;用於初始化(Awake會比Start先執行)，&lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.Update.html&quot; style=&quot;color: #145d7b; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;Update&lt;/a&gt;是每個Frame會執行一次，其他詳細的MonoBehaviour請參閱&lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.html&quot; target=&quot;_blank&quot;&gt;這裡&lt;/a&gt;。&lt;br /&gt;
&lt;br /&gt;
Q4.Frame是什麼意思？&lt;br /&gt;
A4.在遊戲中是指程式執行頻率也就是FPS(是Frames Per Second不是First Person Shooter)，意味著一秒鐘執行多少個Frame。&lt;br /&gt;
&lt;br /&gt;
Q5.有辦法知道每Frame的實際執行耗時嗎？&lt;br /&gt;
A5.Unity有提供&lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/Time-deltaTime.html&quot; target=&quot;_blank&quot;&gt;Time.deltaTime&lt;/a&gt;可以取得每Frame實際耗時。&lt;br /&gt;
&lt;br /&gt;
Q6.設定行為元件的enable？&lt;br /&gt;
A6.&lt;a href=&quot;http://4.bp.blogspot.com/-_RwXpShvnNs/UoRK-hu0WFI/AAAAAAAACKg/dzdbxSLjAOY/s1600/%E8%9E%A2%E5%B9%95%E5%BF%AB%E7%85%A7+2013-11-14+%E4%B8%8A%E5%8D%8811.58.20.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;13&quot; src=&quot;http://4.bp.blogspot.com/-_RwXpShvnNs/UoRK-hu0WFI/AAAAAAAACKg/dzdbxSLjAOY/s320/%E8%9E%A2%E5%B9%95%E5%BF%AB%E7%85%A7+2013-11-14+%E4%B8%8A%E5%8D%8811.58.20.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;在Unity Editor上行為元件的勾選可以控制元件的enable，或者也可以在程式中直接設定enable。enable會影響&lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.Start.html&quot; style=&quot;color: #145d7b; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;Start&lt;/a&gt;、&lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.Update.html&quot; style=&quot;color: #145d7b; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;Update&lt;/a&gt;是否執行，使用時需多加注意。&lt;br /&gt;
&lt;br /&gt;
Q7.遊戲物件的父子物件關係？&lt;br /&gt;
A7.遊戲物件可以跟別的遊戲物件成為父子物件關係，子物件會隨著父物件移動。&lt;br /&gt;
&lt;br /&gt;
Q8.如何執行別的行為元件的函式？&lt;br /&gt;
A8.1)宣告一該行為元件型態變數，并在Unity Editor上將指定的行為元件設定到變數上，或者是在程式裡用&lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/Object.FindObjectOfType.html&quot; target=&quot;_blank&quot;&gt;Object.FindObjectOfType&lt;/a&gt;(在別的遊戲物件上)、&lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/GameObject.GetComponent.html&quot; target=&quot;_blank&quot;&gt;GetComponent&lt;/a&gt;(在本身的遊戲物件上)並執行函式。2)將該函式宣告為static，但並不建議此方法，除非是用在類似整個遊戲狀態管理上。3)使用Unity的SendMessage機制，SendMessage系列有三種，1.&lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/GameObject.SendMessage.html&quot; target=&quot;_blank&quot;&gt;SendMessage(string methodName)&lt;/a&gt;：對本身遊戲物件上的所有行為元件(不含父物件及子物件上的)通知執行跟methodName同名的函式；2.&lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/GameObject.SendMessageUpwards.html&quot; target=&quot;_blank&quot;&gt;SendMessageUpwards(string methodName)&lt;/a&gt;：對本身遊戲物件及父物件上的所有行為元件(不含子物件上的)通知執行跟methodName同名的函式；3.&lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/GameObject.BroadcastMessage.html&quot; target=&quot;_blank&quot;&gt;BroadcastMessage(string methodName)&lt;/a&gt;：對本身遊戲物件及子物件上的所有行為元件(不含父物件上的)通知執行跟methodName同名的函式。&lt;br /&gt;
&lt;br /&gt;
Q9.Prefab機制？&lt;br /&gt;
A9.當“遊戲物件”綁上很多“行為元件”後，要怎麼去重複利用這個“遊戲物件”呢？於是&lt;a href=&quot;http://docs.unity3d.com/Documentation/Manual/Prefabs.html&quot; target=&quot;_blank&quot;&gt;Prefab&lt;/a&gt;機制就出現了，將設定好的“遊戲物件”拖曳到Project View就可以將它變成Prefab。只要將Prefab拖曳到場景中就可以變成已經設定好的“遊戲物件”，這裡要注意的是&lt;span style=&quot;color: red;&quot;&gt;Prefab跟產生出來的“遊戲物件”有父子關係&lt;/span&gt;。只要Prefab上的設定一更動，所有由此Prefab產生的“遊戲物件”都會更動，但如果是“遊戲物件”更動的話是不會影響Prefab及其它“遊戲物件”。
&lt;a href=&quot;http://4.bp.blogspot.com/-MvwGt4ntsVE/UoV_Wqf0s8I/AAAAAAAACK4/xdcmhgSRw3s/s1600/%E8%9E%A2%E5%B9%95%E5%BF%AB%E7%85%A7+2013-11-15+%E4%B8%8A%E5%8D%889.55.56.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;20&quot; src=&quot;http://4.bp.blogspot.com/-MvwGt4ntsVE/UoV_Wqf0s8I/AAAAAAAACK4/xdcmhgSRw3s/s320/%E8%9E%A2%E5%B9%95%E5%BF%AB%E7%85%A7+2013-11-15+%E4%B8%8A%E5%8D%889.55.56.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;跟Prefab有關係的“遊戲物件”上會出現這些控制按鈕，Select可以讓你找到此物件的Prefab；Revert會讓此物件的設定回復得跟Prefab一樣；Apply會將此物件的設定覆蓋回Prefab，連帶的會更動到由此Prefab產生出來的其他“遊戲物件”。最後還要注意的是，更動“遊戲物件”上“行為元件”的設定值將會使這設定值被設立旗標(設定值會變粗體)，表示此設定值跟Prefab脫鉤，&lt;span style=&quot;color: red;&quot;&gt;Prefab更動也不會影響到此設定值&lt;/span&gt;。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
之後有想到什麼再補充上去吧...</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/9169415086575509180/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2013/11/unity3d-unityq.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/9169415086575509180'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/9169415086575509180'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2013/11/unity3d-unityq.html' title='UNITY3D - Unity遊戲開發基礎Q&amp;A'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-_RwXpShvnNs/UoRK-hu0WFI/AAAAAAAACKg/dzdbxSLjAOY/s72-c/%E8%9E%A2%E5%B9%95%E5%BF%AB%E7%85%A7+2013-11-14+%E4%B8%8A%E5%8D%8811.58.20.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-7030576814441346834</id><published>2013-08-06T18:38:00.000-07:00</published><updated>2013-08-06T18:39:32.118-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="GameJam作品"/><title type='text'>福島GameJam 2013作品－神蹟之躍</title><content type='html'>&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;http://fgj.igda.jp/dokuwiki/doku.php?id=team%3Ataipeiiii_c&quot;&gt;http://fgj.igda.jp/dokuwiki/doku.php?id=team%3Ataipeiiii_c&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;這次在福島GameJam做出來的小小作品，因為時間只有30小時，所以隊名叫30hr應援團。&lt;br /&gt;&lt;br /&gt;這次的主題是Jump，於是做了個類跳棋的遊戲。&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;遊戲目的是讓左下方出現的災民移動到右上方的出口&lt;br /&gt;&lt;br /&gt;操作方式是是用滑鼠點擊可以交換同一行或同一列的地形，其中有些地形是無法交換的。&lt;br /&gt;&lt;br /&gt;按Space Bar後再點擊地形可強制把地形更換。&lt;br /&gt;&lt;br /&gt;詳細地形功能及地形變化表請參考網頁。&lt;br /&gt;&lt;br /&gt;另，本作品將會在TGS東京電玩展的Indie Corner展出，請有到TGS的朋友幫忙拍個照讓我做個紀念，謝謝！</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/7030576814441346834/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2013/08/gamejam-2013.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/7030576814441346834'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/7030576814441346834'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2013/08/gamejam-2013.html' title='福島GameJam 2013作品－神蹟之躍'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-6126618636664307631</id><published>2013-02-04T02:16:00.001-08:00</published><updated>2013-08-06T18:34:18.326-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="GameJam作品"/><category scheme="http://www.blogger.com/atom/ns#" term="蚊囈青年"/><title type='text'>Global Game Jam讓你的心跳起來！</title><content type='html'>　　自從去年2012年在Google+上看到有人分享參加MIT Game Jam的心得文章之後，心裡就一直想找機會參加這類活動，但去年12月的Ludum Dare又因為正好公司所作的遊戲正忙著收尾準備上架導致沒辦法參加(雖然事後還是忍不住自己做了個應景的世界末日遊戲&lt;a href=&quot;http://dl.dropbox.com/u/26037476/Wasabi/Wasabi.html&quot; target=&quot;_blank&quot;&gt;http://dl.dropbox.com/u/26037476/Wasabi/Wasabi.html&lt;/a&gt;)。&lt;br /&gt;
&lt;br /&gt;
　　於是看到Global Game Jam的活動資訊時，不管三七二十一就填好報名資料送交了。一些同事知道我報名參加後問我說為什麼我要參加這種沒有名次沒有獎品的活動(還要爆肝...)，當下我是無言以對，但事後想來也許就是因為那股熱血吧？我想要知道自己的實力、想知道這個世界有多廣、想見識更多高手，就如同這次的作品想表達的：就算是行尸走肉，只要找到目標就可以讓你的心臟再次跳動！(肝可以爆，但是請爆在你認為值得的事物上。)&lt;br /&gt;
&lt;br /&gt;
　　這次的主題很棒，就只有聽到心跳聲，但是卻可以讓人作出各種聯想。晚餐過後我們與遲到的成員會合並展開討論，一開始我提出了根據心跳聲的狀況來移動的遊戲，但是為了不浪費我們組的美術就捨棄了，我們從最直觀的方向入手，心跳聲來自心臟，再衍生到文明病，是一款玩家必須消除進入心臟有害物質的遊戲。&lt;span style=&quot;color: #454545; font-family: Arial, Helvetica, Nimbus Sans L, Liberation Sans, FreeSans, sans-serif; font-size: x-small;&quot;&gt;&lt;span style=&quot;-webkit-text-size-adjust: none; line-height: 16.890625px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
　　但還沒定案時，Ingrid讓我們看了一款雙螢幕的flash遊戲(我忘了名字 囧rz)，大家討論後覺得切兩個螢幕可以讓玩家有緊張感可以採用，於是其中一個螢幕就變成心臟了(?)，心臟是提供給人動力的來源，但我們又想要跟常識相反，另一個螢幕就變成殭屍在跑了XD。為了給殭屍跑的理由，原本是讓他對一個女生一見鍾情所以追著她跑，但後來又惡搞成是為了還那個女生錢包XD，再後來為了讓女生穿過障礙物不會顯得突兀所以她變成女鬼了(這是什麼發展XD)，雖然最後我還是幫她寫了簡單的AI但是她已經沒辦法復活成人了XD。&lt;br /&gt;
&lt;br /&gt;
　　在最後一刻我們終於順利把作品完成，實在是非常感謝大家的努力！&lt;br /&gt;
&lt;br /&gt;
感謝&lt;br /&gt;
&lt;br /&gt;
企劃：&lt;span style=&quot;background-color: white; font-family: sans-serif; line-height: 21px;&quot;&gt;Kinan&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 21px;&quot;&gt;美術&lt;/span&gt;&lt;span style=&quot;line-height: 21px;&quot;&gt;：&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: sans-serif; line-height: 21px;&quot;&gt;LightAngel (連續三天搬電腦主機來往住家與會場，超猛！)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 21px;&quot;&gt;主程式：Vincent Sai (感謝自己選擇把肝爆在GGJ)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 21px;&quot;&gt;場景程式：&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: sans-serif; line-height: 21px;&quot;&gt;伍小韻&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 21px;&quot;&gt;程式：&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: sans-serif; line-height: 21px;&quot;&gt;小熊、&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: sans-serif; line-height: 21px;&quot;&gt;劉柏賢&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: sans-serif; font-size: 14px; line-height: 21px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
　　雖然三天下來我真是體力耗盡，回到家也只是拼命的睡，但有一點可以肯定的是，下次我還是會參加！&lt;br /&gt;
&lt;br /&gt;
作品頁面連結：&lt;a href=&quot;http://globalgamejam.org/2013/hopping-dead&quot; target=&quot;_blank&quot;&gt;http://globalgamejam.org/2013/hopping-dead&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/6126618636664307631/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2013/02/global-game-jam.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/6126618636664307631'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/6126618636664307631'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2013/02/global-game-jam.html' title='Global Game Jam讓你的心跳起來！'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-2224641008284565377</id><published>2012-12-13T18:49:00.000-08:00</published><updated>2012-12-14T19:29:12.376-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="蚊囈青年"/><title type='text'>少年Pi的半路叛逃</title><content type='html'>&lt;div dir=&quot;ltr&quot;&gt;
前言：&lt;br /&gt;
這只是我硬把兩個不相干的東西湊在一起，若只是想看《少年Pi的奇幻漂流》電影介紹的可以直接離開了…&lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
《半路叛逃》這本書我買了好段時間，但因為覺得文筆不好所以就沒寫書評。&lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
而在看了《少年Pi的奇幻漂流》電影加上聽了&lt;a href=&quot;https://plus.google.com/104841912068205078599/posts/WhcyBZ9WpFS&quot; target=&quot;_blank&quot;&gt;東江亮先生的一席話&lt;/a&gt;後，心裡有無限的感觸造成這篇文章的出現。&lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
少年Pi在大海中漂流時所面對的危機有：老虎、糧食短缺、茫然無助。&lt;br /&gt;
獨立遊戲開發者在這遊戲紅海中奮戰面對的是：自己、時間、失敗的考驗。&lt;br /&gt;
&lt;br /&gt;
※注：如果有看過少年Pi的人，應該也很清楚劇中的老虎指的是Pi他自己。&lt;br /&gt;
&lt;br /&gt;
孤身一人(或小團隊)在開發遊戲的路上其實也很類似在海中漂流，你永遠不知道這海有多廣？還有多久能上岸？下場會是淹死還是餓死？&lt;br /&gt;
&lt;br /&gt;
而最早面對到的危機就是老虎(自己)，這老虎反映了自身的各種慾望與放縱，很諷刺的是投入獨立開發往往都是因為想要釋放這隻老虎，但多數人往往會因為沒意識到它的危險而葬身虎口。&lt;br /&gt;
&lt;br /&gt;
當能夠面對老虎不再逃避它的時候，就是可以開始嘗試馴服它的時候，但要知道馴服野獸並不是那麼簡單的事情，必須不氣餒的多方嘗試。&lt;br /&gt;
&lt;br /&gt;
※注：我也還只在面對老虎的階段，很佩服半路兄可以順利將老虎馴服並且撐過後面的考驗。&lt;br /&gt;
&lt;br /&gt;
要注意的是在海中漂流，最為重要的是不能失去希望，但也不要做過高的期望(上岸以後會成為富翁等等)，先好好面對你面前的老虎吧。&lt;br /&gt;
&lt;br /&gt;
最後，非常推薦大家去買《半路叛逃》這本書來看，也推薦大家去看《少年Pi的奇幻漂流》這部電影。</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/2224641008284565377/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2012/12/pi.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/2224641008284565377'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/2224641008284565377'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2012/12/pi.html' title='少年Pi的半路叛逃'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-531698080434339419</id><published>2012-12-03T18:09:00.000-08:00</published><updated>2012-12-03T18:09:12.853-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="遊戲試做"/><title type='text'>(遊戲試做) - 消方塊遊戲</title><content type='html'>沒試過做這種類型的遊戲，但身邊有人想做那就來想一下遊戲運作機制是如何。&lt;br /&gt;
&lt;br /&gt;
流程應該是如下&lt;br /&gt;
&lt;br /&gt;
1.產生全場景的隨機方塊&lt;br /&gt;
2.根據玩家所移動的方塊去運算是否消除自身及週遭的方塊&lt;br /&gt;
3.產生新的方塊&lt;br /&gt;
4.運算新的方塊及因消除而移位的方塊是否消除自身及週遭的方塊&lt;br /&gt;
5.重覆2－4&lt;br /&gt;
&lt;br /&gt;
※注：本雛形不含圖形及輸入處理，純粹只是運作機制的試做。&lt;br /&gt;
C#雛形&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
將方塊建成class&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;class&lt;/span&gt; GameBox {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt; posX; //X軸位置&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt; posY; //Y軸位置&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt; boxType; //方塊型別&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;public&lt;/span&gt; GameBox (&lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt; positionX, &lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt; positionY, &lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt; setType) {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;this&lt;/span&gt;.posX = positionX;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;this&lt;/span&gt;.posY = positionY;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;this&lt;/span&gt;.boxType = setType;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;}&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;GameBox[][] gameBoxs = &lt;span class=&quot;s2&quot;&gt;new&lt;/span&gt; GameBox[&lt;span class=&quot;s3&quot;&gt;9&lt;/span&gt;][&lt;span class=&quot;s3&quot;&gt;9&lt;/span&gt;]; //本例以9*9為例&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;ArrayList changedBoxs = &lt;span class=&quot;s2&quot;&gt;new&lt;/span&gt; ArrayList(); //用來記錄有更動過的方塊&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;ArrayList eliminateBoxs = &lt;span class=&quot;s2&quot;&gt;new&lt;/span&gt; ArrayList(); // 記錄待消滅的方塊&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s4&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s4&quot;&gt;//新建9*9方塊矩陣&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;void&lt;/span&gt; BuildPuzzle () {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; for&lt;/span&gt;(&lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt; x = &lt;span class=&quot;s3&quot;&gt;0&lt;/span&gt;; x &amp;lt; &lt;span class=&quot;s3&quot;&gt;9&lt;/span&gt;; x++)&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for&lt;/span&gt;(&lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt; y = &lt;span class=&quot;s3&quot;&gt;0&lt;/span&gt;; y &amp;lt; &lt;span class=&quot;s3&quot;&gt;9&lt;/span&gt;; y++)&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gameBoxs[x][y] = &lt;span class=&quot;s2&quot;&gt;new&lt;/span&gt; GameBox(x, y, &lt;span class=&quot;s1&quot;&gt;Random&lt;/span&gt;.Range(&lt;span class=&quot;s3&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;s3&quot;&gt;7&lt;/span&gt;)); //方塊型別為隨機0-7&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;}&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
//將有更動過的方塊記錄，並且檢查是否能消除，不能消除則歸位。&lt;br /&gt;
//輸入端傳入移動的兩點位置&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;void&lt;/span&gt; ChangeBoxPosition (&lt;span class=&quot;s1&quot;&gt;Vector2&lt;/span&gt; fromPosition, &lt;span class=&quot;s1&quot;&gt;Vector2&lt;/span&gt; toPosition) {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; GameBox tempBox = new GameBox();&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; if&lt;/span&gt;(!changedBoxs.Contains(gameBoxs[fromPosition.x][fromPosition.y]))&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; changedBoxs.Add(gameBoxs[fromPosition.x][fromPosition.y]);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; gameBoxs[fromPosition.x][fromPosition.y].posX = toPosition.X;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; gameBoxs[fromPosition.x][fromPosition.y].posY = toPosition.Y;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;tempBox =&amp;nbsp;gameBoxs[fromPosition.x][fromPosition.y];&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;gameBoxs[fromPosition.x][fromPosition.y] =&amp;nbsp;gameBoxs[toPosition.x][toPosition.y];&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; if&lt;/span&gt;(!changedBoxs.Contains(gameBoxs[toPosition.x][toPosition.y]))&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; changedBoxs.Add(gameBoxs[toPosition.x][toPosition.y]);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; gameBoxs[toPosition.x][toPosition.y].posX =&amp;nbsp;fromPosition.x;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; gameBoxs[toPosition.x][toPosition.y].posY =&amp;nbsp;fromPosition.y;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;gameBoxs[toPosition.x][toPosition.y] = tempBox;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; if(CanEliminateBox())&lt;br /&gt;
&amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;EliminateBox();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; else //無法消除方塊，將方塊位置恢復。&lt;br /&gt;
&amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;tempBox =&amp;nbsp;gameBoxs[fromPosition.x][fromPosition.y];&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gameBoxs[fromPosition.x][fromPosition.y] =&amp;nbsp;gameBoxs[toPosition.x][toPosition.y];&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;gameBoxs[fromPosition.x][fromPosition.y].posX =&amp;nbsp;fromPosition.X;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gameBoxs[fromPosition.x][fromPosition.y].posY =&amp;nbsp;fromPosition.Y;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;gameBoxs[toPosition.x][toPosition.y] = tempBox;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gameBoxs[toPosition.x][toPosition.y].posX =&amp;nbsp;toPosition.x;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gameBoxs[toPosition.x][toPosition.y].posY =&amp;nbsp;toPosition.y;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;}&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
//檢查是否有可消除的方塊，除用於消除方塊外也用於是否還原更動方塊的位置&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;bool&lt;/span&gt; CanEliminateBox () {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; bool&lt;/span&gt; canEliminate = &lt;span class=&quot;s6&quot;&gt;false&lt;/span&gt;;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; foreach&lt;/span&gt;(GameBox box &lt;span class=&quot;s5&quot;&gt;in&lt;/span&gt; changedBoxs)&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int&lt;/span&gt; left = IsSameTypeBoxLeft(box);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int&lt;/span&gt; right = IsSameTypeBoxRight(box);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if&lt;/span&gt;(left + right &amp;gt;&amp;nbsp;&lt;span class=&quot;s3&quot;&gt;2&lt;/span&gt;)&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for&lt;/span&gt;(&lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt; x = box.posX - left; x &amp;lt; box.posX + right; x++)&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if&lt;/span&gt;(!eliminateBoxs.Contains(gameBoxs[x][box.posY]))&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; eliminateBoxs.Add(gameBoxs[x][box.posY]);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; canEliminate = &lt;span class=&quot;s6&quot;&gt;true&lt;/span&gt;;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int&lt;/span&gt; up = IsSameTypeBoxUp(box);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int&lt;/span&gt; down = IsSameTypeBoxDown(box);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if&lt;/span&gt;(up + down &amp;gt; &lt;span class=&quot;s3&quot;&gt;2&lt;/span&gt;)&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for&lt;/span&gt;(&lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt; y = box.posY - up; y &amp;lt; box.posY + down; y++)&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if&lt;/span&gt;(!eliminateBoxs.Contains(gameBoxs[box.posX][y]))&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; eliminateBoxs.Add(gameBoxs[box.posX][y]);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; canEliminate = &lt;span class=&quot;s6&quot;&gt;true&lt;/span&gt;;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; changedBoxs.Clear();&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; return&lt;/span&gt; canEliminate;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;}&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt; IsSameTypeBoxLeft (GameBox startBox) {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; if&lt;/span&gt;(startBox.posX &amp;gt; &lt;span class=&quot;s3&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; gameBoxs[startBox.posX - &lt;span class=&quot;s3&quot;&gt;1&lt;/span&gt;][startBox.posY].boxType == startBox.boxType)&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return&lt;/span&gt; IsSameTypeBoxLeft(gameBoxs[startBox.posX - &lt;span class=&quot;s3&quot;&gt;1&lt;/span&gt;][startBox.posY]) + &lt;span class=&quot;s3&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s7&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; else&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s7&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return&lt;span class=&quot;s7&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;s7&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;}&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt; IsSameTypeBoxRight (GameBox startBox) {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; if&lt;/span&gt;(startBox.posX &amp;lt; &lt;span class=&quot;s3&quot;&gt;8&lt;/span&gt; &amp;amp;&amp;amp; gameBoxs[startBox.posX + &lt;span class=&quot;s3&quot;&gt;1&lt;/span&gt;][startBox.posY].boxType == startBox.boxType)&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return&lt;/span&gt; IsSameTypeBoxRight(gameBoxs[startBox.posX + &lt;span class=&quot;s3&quot;&gt;1&lt;/span&gt;][startBox.posY]) + &lt;span class=&quot;s3&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s7&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; else&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s7&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return&lt;span class=&quot;s7&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;s7&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;}&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt; IsSameTypeBoxUp (GameBox startBox) {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; if&lt;/span&gt;(startBox.posY &amp;gt; &lt;span class=&quot;s3&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; gameBoxs[startBox.posX][startBox.posY - &lt;span class=&quot;s3&quot;&gt;1&lt;/span&gt;].boxType == startBox.boxType)&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return&lt;/span&gt; IsSameTypeBoxUp(gameBoxs[startBox.posX][startBox.posY - &lt;span class=&quot;s3&quot;&gt;1&lt;/span&gt;]) + &lt;span class=&quot;s3&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s7&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; else&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s7&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return&lt;span class=&quot;s7&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;s7&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;}&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt; IsSameTypeBoxDown (GameBox startBox) {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; if&lt;/span&gt;(startBox.posY &amp;lt; &lt;span class=&quot;s3&quot;&gt;8&lt;/span&gt; &amp;amp;&amp;amp; gameBoxs[startBox.posX][startBox.posY + &lt;span class=&quot;s3&quot;&gt;1&lt;/span&gt;].boxType == startBox.boxType)&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return&lt;/span&gt; IsSameTypeBoxDown(gameBoxs[startBox.posX][startBox.posY + &lt;span class=&quot;s3&quot;&gt;1&lt;/span&gt;]) + &lt;span class=&quot;s3&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s7&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; else&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s7&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return&lt;span class=&quot;s7&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;s7&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;}&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
//消除可消除的方塊，並且讓方塊往下掉且在上方產生新方塊，最後再檢查是否有可消除的方塊。&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;void&lt;/span&gt; EliminateBox () {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; foreach&lt;/span&gt;(GameBox eliminate &lt;span class=&quot;s5&quot;&gt;in&lt;/span&gt; eliminateBoxs)&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for&lt;/span&gt;(&lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt; y = eliminate.posY - &lt;span class=&quot;s3&quot;&gt;1&lt;/span&gt;; y &amp;gt;= &lt;span class=&quot;s3&quot;&gt;0&lt;/span&gt;; y--)&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gameBoxs[eliminate.posX][y + &lt;span class=&quot;s3&quot;&gt;1&lt;/span&gt;] = gameBoxs[eliminate.posX][y];&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gameBoxs[eliminate.posX][y + &lt;span class=&quot;s3&quot;&gt;1&lt;/span&gt;].posY += &lt;span class=&quot;s3&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if&lt;/span&gt;(!changedBoxs.Contains(gameBoxs[eliminate.posX][y + &lt;span class=&quot;s3&quot;&gt;1&lt;/span&gt;]))&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; changedBoxs.Add(gameBoxs[eliminate.posX][y + &lt;span class=&quot;s3&quot;&gt;1&lt;/span&gt;]);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gameBoxs[eliminate.posX][&lt;span class=&quot;s3&quot;&gt;0&lt;/span&gt;] = &lt;span class=&quot;s2&quot;&gt;new&lt;/span&gt; GameBox(eliminate.posX, &lt;span class=&quot;s3&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;s1&quot;&gt;Random&lt;/span&gt;.Range(&lt;span class=&quot;s3&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;s3&quot;&gt;7&lt;/span&gt;));&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if&lt;/span&gt;(!changedBoxs.Contains(gameBoxs[eliminate.posX][&lt;span class=&quot;s3&quot;&gt;0&lt;/span&gt;]))&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; changedBoxs.Add(gameBoxs[eliminate.posX][&lt;span class=&quot;s3&quot;&gt;0&lt;/span&gt;]);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;eliminateBoxs.Clear();&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&amp;nbsp; &amp;nbsp; if&lt;/span&gt;(CanEliminateBox())&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; EliminateBox();&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;}&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/531698080434339419/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2012/12/blog-post.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/531698080434339419'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/531698080434339419'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2012/12/blog-post.html' title='(遊戲試做) - 消方塊遊戲'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-5176991327698031917</id><published>2012-11-07T21:55:00.002-08:00</published><updated>2012-12-13T18:50:13.419-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="iOS"/><title type='text'>IOS - IAP的那些鳥事</title><content type='html'>為了搞IAP經歷了許多痛苦和鳥事，深深覺得Apple也不是那麼人性化嘛= =&lt;br /&gt;
&lt;br /&gt;
以下是開發IAP的注意事項&lt;br /&gt;
&lt;br /&gt;
1.記得要加入StoreKit.framework (這不是廢話嗎？)&lt;br /&gt;
&lt;br /&gt;
2.在&lt;a href=&quot;https://itunesconnect.apple.com/&quot; target=&quot;_blank&quot;&gt;iTunes Connect&lt;/a&gt;建立App (就算單純測試也要建立，建立了並不會馬上出現在AppStore)，填寫資料時Bundle ID必須跟你的App Bundle ID一樣，最麻煩的是要提供一堆符合規定Size的圖檔，請善用command + shift + 4截圖吧。&lt;br /&gt;
&lt;br /&gt;
3.建立完App之後一樣在&lt;a href=&quot;https://itunesconnect.apple.com/&quot; target=&quot;_blank&quot;&gt;iTunes Connect&lt;/a&gt;那點進App的詳細設定，右上角有個Manage In App Purchases，在裡面建立IAP的商品。&lt;br /&gt;
&lt;br /&gt;
4.IAP的&lt;b&gt;Product ID&lt;/b&gt;可以隨便設，要注意的是這是唯一性的，就算刪除了也無法再重用一樣的Product ID。&lt;br /&gt;
&lt;br /&gt;
5.設定完之後在App頁面那裡點進View Detail，下方有個IAP設定，進去把剛才建立的IAP都加進去吧。(當App進入等待上傳Binary檔的流程時此設定將無法更改，切記！)&lt;br /&gt;
&lt;br /&gt;
6.Xcode Build的時候記得Code Signing要選對，也就是對應App Bundle ID那個，我連Any IOS SDK的Code Signing也改了。(&lt;span style=&quot;color: red;&quot;&gt;IAP必須用實際測試哦&lt;/span&gt;)&lt;br /&gt;
&lt;br /&gt;
7.接下來，只要code沒寫錯Product ID也沒錯的話，但是在撈IAP產品資訊的時候卻頻頻出現&lt;span style=&quot;background-color: white; font-family: Monaco, &#39;Lucida Console&#39;, monospace; font-size: 13px; line-height: 18.66666603088379px; white-space: nowrap;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;invalidProductIdentifiers&lt;/span&gt;&lt;/span&gt;，你就只能擇日再測了。(沒錯！完全猜不透哪個環節出錯，不斷反覆檢查各個環節都找不出原因，就只能看著這個訊息發呆！但過兩天你甚麼都不用改它就突然可以撈到資料了...)&lt;br /&gt;
&lt;br /&gt;
8.需要注意的還有一點，就在我測試沒問題之後過了幾天我把code移到正式專案時發生了慘劇，它突然又&lt;span style=&quot;background-color: white; color: red; font-family: Monaco, &#39;Lucida Console&#39;, monospace; font-size: 13px; line-height: 18.66666603088379px; white-space: nowrap;&quot;&gt;invalidProductIdentifiers&lt;/span&gt;了！就這樣又瞎忙了兩天發現問題出現在測試IAP用的Bundle ID跟正式專案是一樣的，而這兩個App居然同時存在於機器上，我天真的以為它會因為Bundle ID一樣而被覆蓋，但顯然它沒有......於是死馬當活馬醫將機器上的這兩個App都刪除重Build正式專案，結果資料又撈出來了= =(&lt;span style=&quot;color: red;&quot;&gt;如果等個兩天還是&lt;span style=&quot;background-color: white; font-family: Monaco, &#39;Lucida Console&#39;, monospace; font-size: 13px; line-height: 18.66666603088379px; white-space: nowrap;&quot;&gt;invalidProductIdentifiers&lt;/span&gt;，請檢查看看機器上有沒有跟你專案一樣Bundle ID的App存在吧！&lt;/span&gt;)</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/5176991327698031917/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2012/11/ios-iap.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/5176991327698031917'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/5176991327698031917'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2012/11/ios-iap.html' title='IOS - IAP的那些鳥事'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-2944758581361661831</id><published>2012-10-15T00:30:00.001-07:00</published><updated>2013-11-13T06:29:36.522-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="UNITY 3D"/><title type='text'>UNITY3D - SendMessage多重參數</title><content type='html'>善用Unity3D內建的SendMessage函式可以讓程式更容易拆解、更好重覆利用，在Component Oriented Design上是很好用的工具。&lt;br /&gt;
&lt;br /&gt;
但SendMessage系列有個缺陷是只能接收單一參數，除非自己將多重參數包成struct、class使用，這樣在使用上也變得無法統一不太便利。&lt;br /&gt;
&lt;br /&gt;
如何改善呢？&lt;br /&gt;
&lt;br /&gt;
試了幾種方法後發現用Hashtable較為合適，且C#或JavaScript皆可使用。按Key來得知所接收的變數該塞在哪？不用像用Array時還要確定變數的位子。&lt;br /&gt;
&lt;br /&gt;
C#&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;code prettyprint&quot;&gt;void Start () {
&amp;nbsp; &amp;nbsp;&amp;nbsp;Hashtable&amp;nbsp;args = new Hashtable();
&lt;div&gt;
//想塞什麼型態都可以&lt;br /&gt;
&lt;div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; args.Add(&quot;string&quot;, &quot;i am string&quot;);&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; args.Add(&quot;int&quot;, 123);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; args.Add(&quot;float&quot;, 567.89f);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; args.Add(&quot;Vector3&quot;, new Vector3(1, 2, 3));&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; SendMessage(&quot;TestMessage&quot;, args);&lt;br /&gt;
}&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
void TestMessage (Hashtable args) {

//可以直接使用或新建變數接收，個人覺得新建變數接收使用上較為直覺

//接收時須轉型為正確型態

&amp;nbsp; &amp;nbsp; string stringVar = (args.Contains(&quot;string&quot;)) ? args[&quot;string&quot;].ToString() : &quot;&quot;;

&amp;nbsp; &amp;nbsp; int intVar =&amp;nbsp;(args.Contains(&quot;int&quot;)) ? (int)args[&quot;int&quot;] : 0;

&amp;nbsp; &amp;nbsp; float floatVar =&amp;nbsp;(args.Contains(&quot;float&quot;)) ? (float)args[&quot;float&quot;] : 0.0f;

&amp;nbsp; &amp;nbsp;&amp;nbsp;Vector3 vectorVar =&amp;nbsp;(args.Contains(&quot;Vector3&quot;)) ? (Vecotr3)args[&quot;Vector3&quot;] : Vector.zero;

}

&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝&lt;br /&gt;
&lt;br /&gt;
JavaScript&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;code prettyprint&quot;&gt;function Start () {
&amp;nbsp; &amp;nbsp; var&amp;nbsp;args :&amp;nbsp;Hashtable&amp;nbsp;= new Hashtable();

//想塞什麼型態都可以

&lt;div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; args.Add(&quot;string&quot;, &quot;i am string&quot;);&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; args.Add(&quot;int&quot;, 123);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; args.Add(&quot;float&quot;, 567.89f);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; args.Add(&quot;Vector3&quot;, new Vector3(1, 2, 3));&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; SendMessage(&quot;TestMessage&quot;, args);&lt;br /&gt;
}&lt;br /&gt;
function&amp;nbsp;TestMessage (args : Hashtable) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; string stringVar = (args.Contains(&quot;string&quot;)) ? args[&quot;string&quot;] : &quot;&quot;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; int intVar =&amp;nbsp;(args.Contains(&quot;int&quot;)) ? args[&quot;int&quot;] : 0;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; float floatVar =&amp;nbsp;(args.Contains(&quot;float&quot;)) ? args[&quot;float&quot;] : 0.0f;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;Vector3 vectorVar =&amp;nbsp;(args.Contains(&quot;Vector3&quot;)) ? args[&quot;Vector3&quot;] : Vector.zero;&lt;br /&gt;
}&lt;/div&gt;
&lt;/div&gt;
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/2944758581361661831/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2012/10/unity3d-sendmessage.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/2944758581361661831'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/2944758581361661831'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2012/10/unity3d-sendmessage.html' title='UNITY3D - SendMessage多重參數'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-4361313796939463538</id><published>2012-08-15T00:03:00.001-07:00</published><updated>2012-12-13T18:49:03.988-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="蚊囈青年"/><title type='text'>人生如遊戲，遊戲如人生。</title><content type='html'>遊戲在設計的時候都會設置短期、中期、長期任務還有最終目標，而玩家為了完成這些任務及邁向最終目標會作出各種努力以期完成任務，如升級、學習及提升技能、尋找隊友幫助、強化工具與裝備等等。&lt;br /&gt;
&lt;br /&gt;
當玩家作出的努力得到回報時（完成任務），玩家的心情會是雀躍萬分甚至心裡會想說“如果這輩子再也玩不到這麼棒的任務該怎麼辦”，好吧...這麼棒的任務確實比較難設計，但這就是玩家想要的。&lt;br /&gt;
&lt;br /&gt;
其實把遊戲中的規則玩法套用在生活中時間很棒的事情，現實生活中也需要各種任務跟最終目標的存在。比如說：這個月要減重3公斤，就必須透過少吃、運動、吃藥(不良示範)、抽脂(？)來達成這個任務。&lt;br /&gt;
&lt;br /&gt;
人類是很容易失去動力的生物，當你茫茫然不知道自己能做什麼、該做什麼時就更需要定個短期任務讓自己有個目標前進。除了短期任務外也需要定個中長期任務，如：我想做遊戲，這個任務的子任務可能就是學習寫程式、學習畫2D3D、學習寫遊戲企劃、得到不做遊戲就會死的病（？）等等。&lt;br /&gt;
&lt;br /&gt;
當然...這跟遊戲一樣，最難的是設計一個剛好的任務，不至於太簡單一點成就都沒有，也不能太難要擁有100台名車（好吧，我知道有些人可以），最好就是設置有可能完成但是需要經過一番努力的任務，相信完成的時候心情是難以言喻的。&lt;br /&gt;
&lt;br /&gt;
讓我們大家為了讓自己的人生過得更棒而對自己設定任務吧！</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/4361313796939463538/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2012/08/blog-post.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/4361313796939463538'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/4361313796939463538'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2012/08/blog-post.html' title='人生如遊戲，遊戲如人生。'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-4607790868197946803</id><published>2012-08-14T02:57:00.001-07:00</published><updated>2015-01-30T07:43:19.563-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="UNITY 3D"/><title type='text'>UNITY3D - JavaScript &quot;in&quot; 的妙用</title><content type='html'>&lt;span style=&quot;color: red;&quot;&gt;前言：這裏指的Javascript是指Unity所用的，而非一般所用的Javascript，一般所用的Javascript無法使用in來當Contains使用。&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
C# 的ArrayList有Contains函式可以用來檢查元素是否存在於這個Array裡，但是JavaScript裡的Array就沒有Contains函式可以使用，難道只能用迴圈來檢查了嗎？&lt;br /&gt;
不！JavaScript有提供很棒的&quot;in&quot;關鍵字供我們使用，這關鍵字不但容易讓人理解而且功能強大，如：&lt;br /&gt;
&lt;br /&gt;
var arr : int[] = [1, 2, 3, 4, 5];&lt;br /&gt;
for(var i : int in arr)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Debug.Log(i); //1 2 3 4 5&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
像C#的foreach用法&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
var arr : Array = new Array(1, 2, 3, 4, 5);&lt;br /&gt;
if(3 in arr)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Debug.Log(true);&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Debug.Log(false);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
我們想要的Contains功能&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
var arr : int[] = [1, 2, 3, 4, 5];&lt;br /&gt;
&lt;br /&gt;
if(3 in arr)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Debug.Log(true);&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Debug.Log(false);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
更棒的是BuildInArray也適用這個做法，C#的話似乎就必須用迴圈去找了。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if (foo == &quot;bar&quot; || foo == &quot;foobar&quot; || foo == &quot;foo&quot; )&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;//...&lt;br /&gt;
}&lt;br /&gt;
// can be written as&lt;br /&gt;
if (foo in [&quot;bar&quot;, &quot;foobar&quot;, &quot;foo&quot;])&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;//...&lt;br /&gt;
}&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
超棒的是不用再寫一堆||了，不但易讀易懂更易寫。&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
還有甚麼更好的應用就等大家分享了。&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/4607790868197946803/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2012/08/unity3d-javascript-in.html#comment-form' title='2 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/4607790868197946803'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/4607790868197946803'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2012/08/unity3d-javascript-in.html' title='UNITY3D - JavaScript &quot;in&quot; 的妙用'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-8825284582174867726</id><published>2012-07-23T19:39:00.002-07:00</published><updated>2012-07-23T19:39:24.567-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="UNITY 3D"/><title type='text'>「轉載」Unity3d动画脚本 Animation Scripting(深入了解游戏引擎中的动画处理原理)</title><content type='html'>&lt;br /&gt;
也許這一篇文章的內容有點枯燥，但我要說的是如果你想深入的了解遊戲引擎是如何處理動畫片斷或者素材並&lt;br /&gt;
讓玩家操控的角色動起來栩栩如生，那麼這&lt;span style=&quot;color: red; font-size: x-large;&quot;&gt;真是一篇好文章&lt;/span&gt;(當然我僅僅是翻譯了一下)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
動畫腳本 Animation Scripting&lt;br /&gt;
Unity&#39;s 動畫系統允許你創建一個漂亮的動畫蒙皮角色. 動畫系統支持動畫融合,混合,添加動畫,步調週期時間同步.動畫層.控制動畫回放的所有方面(時間,速度,混合權重) 每個頂點有1.2.4個骨骼影響的mesh，基於物理系統的布娃娃系統，另外還有程序動畫.為了獲得最佳效果推薦您在製作模型和動畫綁定前閱讀一下&lt;a href=&quot;http://docs.unity3d.com/Documentation/Manual/ModelingOptimizedCharacters.html&quot;&gt;Modeling Optimized Characters&lt;/a&gt; 章節.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
製作一個動畫角色主要包括兩個方面; 在世界中移動和由此產生的動畫. 如果你想了解角色移動相關的更多內容, 請參閱&lt;a href=&quot;http://docs.unity3d.com/Documentation/Components/class-CharacterController.html&quot;&gt;Character Controller page&lt;/a&gt;. &amp;nbsp; 實際上角色動畫是由Unity&#39;s 腳本界面完成的 .&lt;br /&gt;
你可以下載&lt;a href=&quot;http://www.unity3d.com/examples/&quot;&gt;example demos&lt;/a&gt; 中預設置好的動畫角色. 當你學完本頁的基礎部分你還可以看一看&lt;a href=&quot;http://docs.unity3d.com/Documentation/Manual/AnimationScripting.html&quot;&gt;animation script interface&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
如果需要你可以點擊并快速轉到以下主題:&lt;br /&gt;
· &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://docs.unity3d.com/Documentation/Manual/AnimationScripting.html#AnimBlend&quot;&gt;Animation Blending&lt;/a&gt; &amp;nbsp; &amp;nbsp;動畫融合&lt;br /&gt;
· &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://docs.unity3d.com/Documentation/Manual/AnimationScripting.html#AnimLayers&quot;&gt;Animation Layers&lt;/a&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;動畫層&lt;br /&gt;
· &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://docs.unity3d.com/Documentation/Manual/AnimationScripting.html#AnimMixing&quot;&gt;Animation Mixing&lt;/a&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; 動畫混合&lt;br /&gt;
· &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://docs.unity3d.com/Documentation/Manual/AnimationScripting.html#Additive&quot;&gt;Additive Animation&lt;/a&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;附加動畫&lt;br /&gt;
· &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://docs.unity3d.com/Documentation/Manual/AnimationScripting.html#Procedural&quot;&gt;Procedural Animation&lt;/a&gt; &amp;nbsp; &amp;nbsp;程序動畫&lt;br /&gt;
· &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://docs.unity3d.com/Documentation/Manual/AnimationScripting.html#Playback&quot;&gt;Animation Playback and Sampling&lt;/a&gt; &amp;nbsp; 動畫重放和取樣&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;Animation Blending 動畫融合&lt;/span&gt;&lt;br /&gt;
在現今的遊戲中&lt;b&gt;Animation Blending是一項保證遊戲動畫順暢過渡的基本的特性&lt;/b&gt;.動畫師創建的動畫例如： walk 循環, run 循環, idle原地空閒動畫或射擊動畫.在遊戲的任何時間點你都有可能從空閒站立轉換到走動，反之亦然. 當然你不希望兩個不同的動作之間突然跳轉, 你需要動畫平滑過渡.&lt;br /&gt;
而這個問題的解決就依賴動畫融合技術. 在Unity中你可以讓同一個角色擁有任意數量的動畫.所有這些動畫融合添加成為一個總的動畫.&lt;br /&gt;
首先我們來為一個角色添加兩個動畫原地空閒站立和走動並平滑的使這兩個動畫過渡. 為了使我們在寫腳本時簡單些, 首先我們設置動畫的&lt;span style=&quot;color: red;&quot;&gt;Wrap Mode&lt;/span&gt;為&lt;span style=&quot;color: red;&quot;&gt;Loop&lt;/span&gt;. 然後&lt;span style=&quot;color: red;&quot;&gt;關閉Play Automatically&lt;/span&gt;來讓我們的腳本來獨占動畫的播放.&lt;br /&gt;
&lt;br /&gt;
我們第一個動畫腳本很簡單; 我們需要一些方法來探查角色移動的有多快, 然後在走和站立之間淡入淡出. 在這個簡單的測試中我們使用pre-setup input axes.&lt;br /&gt;
&lt;br /&gt;
function Update () {&lt;br /&gt;
&amp;nbsp; &amp;nbsp;if (Input.GetAxis(&quot;Vertical&quot;) &amp;gt; 0.2)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;animation.CrossFade (&quot;walk&quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp;else&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; animation.CrossFade (&quot;idle&quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
下面我們來讓這個腳本運行:&lt;br /&gt;
1. &amp;nbsp; &amp;nbsp; &amp;nbsp; 創建一個js腳本Assets-&amp;gt;Create Other-&amp;gt;Javascript.&lt;br /&gt;
2. &amp;nbsp; &amp;nbsp; &amp;nbsp; 把代碼拷貝進去&lt;br /&gt;
3. &amp;nbsp; &amp;nbsp; &amp;nbsp; 把腳本拖拽給角色character (It needs to be the same GameObject as the animation)&lt;br /&gt;
點擊Play 按鈕, 當你按上下鍵時角色會走動，鬆開上下鍵時角色站立不動.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;動畫層Animation Layers&lt;/span&gt;&lt;br /&gt;
層是一個非常有用的概念它可以讓你將動畫片段任意成組並且區分優先順序.&lt;br /&gt;
在Unity&#39;s動畫系統中, 你可以混合任意數量的動畫片段. 你可以手工分配權重或者直接使用&lt;b&gt;animation.CrossFade()&lt;/b&gt;,來自動分配權重.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;混合權重混合權重總是在應用前被規格化normalized&lt;/b&gt;&lt;br /&gt;
比如說我們現在有一個walk cycle 和一個run cycle, 權重都是1 (100%).當unity計算最終動畫時會規格化權重, 這意味著walk佔50% 權重, &amp;nbsp; run cycle佔50% 權重.&lt;br /&gt;
&lt;br /&gt;
這在大多數情況下都是不錯的, 但當兩個動畫片段同時運行而其中一個權重明顯大於另外一個. 那麼你需要手動調整權重值,但如果你使用動畫層來解決這個問題過程會容易得多.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;製作動畫層的範例Layering Example&lt;/b&gt;&lt;br /&gt;
例如現在你有一個射擊動畫, 一個空閒站立，一個走動循環 . 你需要在走和站兩個動作間持續的淡入淡出(在玩家走動速度的基礎上) 但當玩家射擊時我們只想展示射擊動畫. 因而射擊動畫此時的優先度最高.&lt;br /&gt;
&lt;br /&gt;
為了達到這一目的最簡單的方法是在射擊時簡單的保持walk 和idle動畫. 接下來需要確定shoot animation在一個比idle 和walk更高的層. 這意味著shoot animation 將首先收到混合權重. walk 和idle 只有在shoot animation不使用100% 混合權重的情況下接收權重. 所以當CrossFading the shoot animation in, 權重將從0開始很短時間內到達100%. 在開始階段walk 和idle 層將依然可以收到混合權重但當shoot animation 完全切入時, 他們就收不到權重了. &amp;nbsp;這才是我們需要的!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function Start () {&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Set all animations to loop 設置所有動畫為循環&lt;br /&gt;
&amp;nbsp; &amp;nbsp;animation.wrapMode = WrapMode.Loop;&lt;br /&gt;
// except shooting 除了射擊（不循環）&lt;br /&gt;
&amp;nbsp; &amp;nbsp;animation[&quot;shoot&quot;].wrapMode = WrapMode.Once;&lt;br /&gt;
&lt;br /&gt;
//放置idle 和walk 進低一級別的layers &amp;nbsp;(默認layer 總是0)&lt;br /&gt;
// This will do two things這將作兩件事情&lt;br /&gt;
// - 當calling CrossFade時，由於shoot 和idle/walk 在不同的layers 中&lt;br /&gt;
// &amp;nbsp; 它們將不會影響互相之間的重放.&lt;br /&gt;
// - 由於shoot 在高一級的layer, 當faded in 時shoot動畫將替換&lt;br /&gt;
&amp;nbsp; &amp;nbsp;// &amp;nbsp; idle/walk 動畫 .&lt;br /&gt;
&amp;nbsp; &amp;nbsp;animation[&quot;shoot&quot;].layer = 1;&lt;br /&gt;
&lt;br /&gt;
// Stop animations that are already playing停止已經播放的動畫&lt;br /&gt;
//(萬一user 忘記的話，自動disable播放)&lt;br /&gt;
&amp;nbsp; &amp;nbsp;animation.Stop();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function Update () {&lt;br /&gt;
// Based on the key that is pressed,基於按下的鍵&lt;br /&gt;
// play the walk animation or the idle animation播放走，站動畫&lt;br /&gt;
if (Mathf.Abs(Input.GetAxis(&quot;Vertical&quot;)) &amp;gt; 0.1)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; animation.CrossFade(&quot;walk&quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp;else&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; animation.CrossFade(&quot;idle&quot;);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;// Shoot射擊&lt;br /&gt;
&amp;nbsp; &amp;nbsp;if (Input.GetButtonDown (&quot;Fire1&quot;))&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; animation.CrossFade(&quot;shoot&quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
默認情況下animation.Play() 和animation.CrossFade() 將停止或淡出在同一層裡面的動畫. 這是我們在絕大多數情況下需要的.在我們shoot, idle, run 範例中, 播放idle 和run 將不會影響到shoot動畫反之亦然(you can change this behavior(行為) with an optional parameter(任意參數) to animation.CrossFade if you like).&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;動畫混合Animation Mixing&lt;/b&gt;&lt;br /&gt;
動畫混合可以讓你縮減你必須為遊戲製作的動畫片斷數量，方法是製作只對身體某個部分起作用的動畫. 這意味著這些動畫可以和其他動畫合併起來一起使用.&lt;br /&gt;
&lt;br /&gt;
如果你想給一個動畫添加animation mixing transform to an animation by calling AddMixingTransform() on the given AnimationState.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;混合範例Mixing Example&lt;/b&gt;&lt;br /&gt;
例如你可能有一個揮手(hand-waving)動畫. 你可能需要讓一個空閒站立(idle)角色或者一個走動(walking)角色來揮手. 如果沒有動畫混合你可能需要製作兩個揮手hand-waving動畫:一個給idle, 一個給walking. 可是, 如果你將揮手(hand-waving)動畫作為一個mixing transform 添加到shoulder transform,揮手動畫將只控制肩膀. 身體餘下部位不受其影響, 下半身會繼續播放idle 或者walk 動畫. 因而你只需要一個揮手(hand-waving)動畫.&lt;br /&gt;
&lt;br /&gt;
/// Adds a mixing transform using a Transform variable&lt;br /&gt;
var shoulder : Transform;&lt;br /&gt;
animation[&quot;wave_hand&quot;].AddMixingTransform(shoulder);&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Another example using a path.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
function Start () {&lt;br /&gt;
// Adds a mixing transform using a path instead&lt;br /&gt;
var mixTransform : Transform = transform.Find(&quot;root/upper_body/left_shoulder&quot;);&lt;br /&gt;
animation[&quot;wave_h和&quot;].AddMixingTransform(mixTransform);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;附加動畫 Additive Animations&lt;/b&gt;&lt;br /&gt;
附加動畫和動畫混合可以讓你縮減為遊戲製作的動畫片斷的數量,並且對面部動畫(facial animations)來說非常重要.&lt;br /&gt;
讓我們來看看如果創建一個在跑和轉身時身體可以自動傾斜的角色.&lt;br /&gt;
你已經製作好了一個walk 和run循環, 現在你還要製作一個走動左傾( walk-lean-left), 走動右傾(walk-lean-right), 跑左傾(run-lean-left), 跑右傾( run-lean-right)動畫.&lt;br /&gt;
這意味著你需要多做4個動畫片斷! 製作這麼多數量的動畫會累死人的. 而附加動畫(Additive animations) 和混合(Mixing) 可以大大減少這些工作量!&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;附加動畫範例 Additive Animation Example&lt;/b&gt;&lt;br /&gt;
附加動畫允許你在頂層覆蓋其他所有可能播放的動畫的效果( allow you to overlay the effects of animation on top of any others that may be playing). 當你製作一個附加動畫時, Unity將計算動畫片斷裡的第一幀(first frame)和當前幀(current frame)的差異. 然後它將在所有其他播放的動畫之上應用這個差異(Then it will apply this difference on top of all other playing animations).&lt;br /&gt;
&lt;br /&gt;
現在你只需要製作一個左傾( lean-left) 和右傾( lean-right)動畫. Unity將為此傾斜動畫新建一個層並置於walk, idle 或run循環的層級之上.&lt;br /&gt;
下面是代碼Here is the code to make that happen:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
private var leanLeft : AnimationState;&lt;br /&gt;
private var leanRight : AnimationState;&lt;br /&gt;
&lt;br /&gt;
function Start () {&lt;br /&gt;
&amp;nbsp; &amp;nbsp;leanLeft = animation[&quot;leanLeft&quot;];&lt;br /&gt;
&amp;nbsp; &amp;nbsp;leanRight = animation[&quot;leanRight&quot;];&lt;br /&gt;
&lt;br /&gt;
// Put the leaning animation in a separate layer&lt;br /&gt;
// So that other calls to CrossFade won&#39;t affect it.&lt;br /&gt;
&amp;nbsp; &amp;nbsp;leanLeft.layer = 10;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;leanRight.layer = 10;&lt;br /&gt;
&lt;br /&gt;
// Set the lean animation to be additive 混合模式為附加&lt;br /&gt;
leanLeft.blendMode = AnimationBlendMode.Additive;&lt;br /&gt;
leanRight.blendMode = AnimationBlendMode.Additive;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;// Set the lean animation ClampForever&lt;br /&gt;
// With ClampForever animations will not stop&lt;br /&gt;
// automatically when reaching the end of the clip&lt;br /&gt;
&amp;nbsp; &amp;nbsp;leanLeft.wrapMode = WrapMode.ClampForever;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;leanRight.wrapMode = WrapMode.ClampForever;&lt;br /&gt;
&lt;br /&gt;
// Enable the animation 和fade it in completely&lt;br /&gt;
// We don&#39;t use animation.Play here because we manually adjust the time&lt;br /&gt;
&amp;nbsp; &amp;nbsp;// in the Update function.&lt;br /&gt;
// Instead we just enable the animation 和set it to full weight&lt;br /&gt;
&amp;nbsp; &amp;nbsp;leanRight.enabled = true;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;leanLeft.enabled = true;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;leanRight.weight = 1.0;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;leanLeft.weight = 1.0;&lt;br /&gt;
&lt;br /&gt;
// For testing just play &quot;walk&quot; animation 和loop it&lt;br /&gt;
&amp;nbsp; &amp;nbsp;animation[&quot;walk&quot;].wrapMode = WrapMode.Loop;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;animation.Play(&quot;walk&quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Every frame just set the normalized time&lt;br /&gt;
// based on how much lean we want to apply&lt;br /&gt;
function Update () {&lt;br /&gt;
&amp;nbsp; &amp;nbsp;var lean = Input.GetAxis(&quot;Horizo​​ntal&quot;);&lt;br /&gt;
// normalizedTime is 0 at the first frame 和1 at the last frame in the clip&lt;br /&gt;
&amp;nbsp; &amp;nbsp;leanLeft.normalizedTime = -lean;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;leanRight.normalizedTime = lean;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
提示Tip:&lt;br /&gt;
當使用附加動畫時它會判斷你同時也在播放一些其他的使用了附加動畫的非附加動畫(it is critical that you are also playing some other non-additive animation on every transform that is also used in the additive animation ), 否則動畫將添加到最後一幀結果的頂部(animations will add on top of the last frame&#39;s result). 這通常不是你所需要的(This is most certainly not what you want).&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;程序動畫角色Procedurally Animating Characters&lt;/b&gt;&lt;br /&gt;
有時你需要程序化的驅動你的角色骨骼. 例如你可能需要你的角色的頭注視3d空間的某個點. 這個活最好讓腳本來幹. 幸運的是, Unity做這個很容易. 在Unity中所有骨骼來驅動蒙皮網格(skinned mesh)的變換(Transforms). 因而你可以給角色的骨骼寫腳本,就和其他GameObject一樣.&lt;br /&gt;
&lt;br /&gt;
很重要的一點是動畫系統updates the Transforms 是在Update() function調用之後 &amp;nbsp;，LateUpdate() function 調用之前. 因而如果你要調用LookAt() function 你應該do that in LateUpdate() to make sure that you are really overriding the animation.&lt;br /&gt;
布娃娃系統Ragdolls 也是用同樣的方法製作出來的. 你可以簡單的把剛性物體(Rigidbodies), 角色關節(Character Joints) 和膠囊碰撞體(Capsule Colliders)連接給不同的骨骼. 這樣物理系統就可以作用於蒙皮角色(skinned character). (&lt;span style=&quot;color: red;&quot;&gt;什麼是布娃娃系統，當你在射擊類游戲中打死對手時可以注意到當角色快接近地面時，他的四肢開始癱軟在地面上，這個不是動畫師調出來的，而是布娃娃系統自動計算出來的。&lt;/span&gt;)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;動畫重放和取樣Animation Playback 和Sampling&lt;/b&gt;&lt;br /&gt;
這一部分將說明引擎如何在動畫重放時取樣.&lt;br /&gt;
&lt;br /&gt;
動畫片斷製作時總是有一個特定的速率. 舉例來說, 你可能在Max 或Maya at 創建了一個幀速為60 frames 每秒(fps)的動畫. 當導入Unity後, 輸入模塊將讀取幀速, 所以導入的動畫幀速還是60fps.&lt;br /&gt;
&lt;br /&gt;
可是, 遊戲運行時的速率是不斷變化的. 有的電腦幀速快有的電腦幀速慢, 即使是同一台電腦前一秒和後一秒因為視角的不同幀速也不一樣. 基本上當遊戲開始運行時我們無法確定一個精確的幀速. 這意味著即使我們的動畫片斷製作時是60 fps, 它重放時也許用的是另外一個速率, 例如56.72 fps, 或83.14 fps. 它可以變成任何一個速率.&lt;br /&gt;
&lt;br /&gt;
Unity 對這些變化的速率取樣, 不在於其製作時的速率. 幸運的是，3d電腦圖形動畫不是由分散的動畫組成, 確切地說是由連續的曲線構成的. 這些曲線可以讓我們在任何時間點取樣; 而不是適配某一個原始幀的時間點. I這也意味著如果遊戲運行速率高於原始製作速率, 動作事實上看起來會更平滑流暢.&lt;br /&gt;
&lt;br /&gt;
對絕大多數應用場合, &amp;nbsp;Unity對變化幀速的採樣我們無需對其進行干預. 可是, 如果你的某個遊戲邏輯所依賴的動畫變化或道具(transforms or properties)結構十分特殊, 那你必須知道這一點. &amp;nbsp;舉例說, 如果你有一個動畫是把一個物體30幀內從0旋轉到180度, 你想從代碼中得知什麼時候動畫完成一半, 你不能寫一段條件語言來檢查現在旋轉值是不是90度. 因為Unity 依照遊戲的變化速率來對動畫採樣, 它可能在旋轉快到90度時進行採樣, 或者是剛好過90度的時候採樣. 如果你需要通報動畫中一個特殊點到達時,你可以使用&lt;a href=&quot;http://docs.unity3d.com/Documentation/Components/animeditor-AnimationEvents.html&quot;&gt;AnimationEvent&lt;/a&gt; 來替代.&lt;br /&gt;
&lt;br /&gt;
同樣需要注意的是變化的幀速採樣結果, 一個使用WrapMode.Once 模式重放的動畫的採樣不一定是精確的最後一幀( last frame).在遊戲中很有可能是剛好結束前的某一幀, 在下一幀時間可能超過動畫的長度, so it is disabled 和not sampled further. 如果你需要動畫的最後一幀採樣精確，你可以使用WrapMode.ClampForever. 如果是那樣的話動畫將不停的對最後一幀進行採樣直到你自己停止動畫.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/8825284582174867726/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2012/07/unity3d-animation-scripting.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/8825284582174867726'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/8825284582174867726'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2012/07/unity3d-animation-scripting.html' title='「轉載」Unity3d动画脚本 Animation Scripting(深入了解游戏引擎中的动画处理原理)'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-3960782915588404153</id><published>2012-07-03T00:54:00.000-07:00</published><updated>2012-07-03T00:54:12.675-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="UNITY 3D"/><title type='text'>UNITY3D - 多點觸控Button</title><content type='html'>&lt;br /&gt;
Unity3D自帶的GUI元件並不支援多點觸控，但若針對每個要有多點觸控的Button額外寫程式也很煩人，於是寫了這隻程式，使用方法跟GUI.Button一樣，只是改成用CustomGUI.Button。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public class CustomGUI {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static bool Button (Rect position, string text) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;GUI.Button(position, text);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;position.y = Screen.height - position.y - position.height;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if(Input.GetMouseButtonUp(0) &amp;amp;&amp;amp; position.Contains(Input.mousePosition))&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;return true;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;foreach (Touch touch in Input.touches) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (touch.phase != TouchPhase.Ended &amp;amp;&amp;amp; touch.phase != TouchPhase.Canceled)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;if(position.Contains(touch.position))&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;return true;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return false;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static bool Button (Rect position, Texture image) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;GUI.Button(position, image);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;position.y = Screen.height - position.y - position.height;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if(Input.GetMouseButtonUp(0) &amp;amp;&amp;amp; position.Contains(Input.mousePosition))&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;return true;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;foreach (Touch touch in Input.touches) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (touch.phase != TouchPhase.Ended &amp;amp;&amp;amp; touch.phase != TouchPhase.Canceled)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;if(position.Contains(touch.position))&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;return true;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return false;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static bool Button (Rect position, GUIContent content) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;GUI.Button(position, content);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;position.y = Screen.height - position.y - position.height;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if(Input.GetMouseButtonUp(0) &amp;amp;&amp;amp; position.Contains(Input.mousePosition))&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;return true;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;foreach (Touch touch in Input.touches) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (touch.phase != TouchPhase.Ended &amp;amp;&amp;amp; touch.phase != TouchPhase.Canceled)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;if(position.Contains(touch.position))&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;return true;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return false;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static bool Button (Rect position, string text, GUIStyle style) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;GUI.Button(position, text, style);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;position.y = Screen.height - position.y - position.height;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if(Input.GetMouseButtonUp(0) &amp;amp;&amp;amp; position.Contains(Input.mousePosition))&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;return true;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;foreach (Touch touch in Input.touches) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (touch.phase != TouchPhase.Ended &amp;amp;&amp;amp; touch.phase != TouchPhase.Canceled)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;if(position.Contains(touch.position))&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;return true;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return false;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static bool Button (Rect position, Texture image, GUIStyle style) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;GUI.Button(position, image, style);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;position.y = Screen.height - position.y - position.height;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if(Input.GetMouseButtonUp(0) &amp;amp;&amp;amp; position.Contains(Input.mousePosition))&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;return true;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;foreach (Touch touch in Input.touches) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (touch.phase != TouchPhase.Ended &amp;amp;&amp;amp; touch.phase != TouchPhase.Canceled)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;if(position.Contains(touch.position))&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;return true;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return false;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static bool Button (Rect position, GUIContent content, GUIStyle style) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;GUI.Button(position, content, style);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;position.y = Screen.height - position.y - position.height;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if(Input.GetMouseButtonUp(0) &amp;amp;&amp;amp; position.Contains(Input.mousePosition))&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;return true;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;foreach (Touch touch in Input.touches) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (touch.phase != TouchPhase.Ended &amp;amp;&amp;amp; touch.phase != TouchPhase.Canceled)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;if(position.Contains(touch.position))&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;return true;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return false;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
}&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/3960782915588404153/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2012/07/unity3d-button.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/3960782915588404153'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/3960782915588404153'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2012/07/unity3d-button.html' title='UNITY3D - 多點觸控Button'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-380109650835793305</id><published>2012-07-03T00:42:00.003-07:00</published><updated>2012-07-03T00:42:55.714-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="UNITY 3D"/><title type='text'>UNITY3D - 自動調整GUITexture比例</title><content type='html'>&lt;br /&gt;
開發手機、平板電腦遊戲最怕就是各廠商尺寸解析度不同，造成UI被破壞。&lt;br /&gt;
若是本來就在OnGUI做UI處理的可以在該程式中處理比例問題，但如果有使用到大量GUITexture，將以下程式附加在EmptyObject上即可將問題處理。&lt;br /&gt;
&lt;br /&gt;
/*******************************************************/&lt;br /&gt;
C#&lt;br /&gt;
/*******************************************************/&lt;br /&gt;
public Vector2 oriScale = new Vector2(&lt;span style=&quot;background-color: white;&quot;&gt;1024.0f, 768.0f&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
void Start () {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;GUITexture[] guis = FindObjectsOfType(typeof(GUITexture)) as GUITexture[];&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Vector2 size = new Vector2();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;size.x = Screen.width /&amp;nbsp;oriScale.x;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;size.y = Screen.height /&amp;nbsp;oriScale.y;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;foreach(GUITexture gui in guis)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;gui.pixelInset = new Rect(gui.pixelInset.x * size.x, gui.pixelInset.y * size.y, gui.pixelInset.width * size.x, gui.pixelInset.height * size.y);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*******************************************************/&lt;br /&gt;
Javascript&lt;br /&gt;
/*******************************************************/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public var oriScale : Vector2 = Vector2(1024.0f, 768.0f);&lt;br /&gt;
&lt;br /&gt;
function Start () {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;var guis : GUITexture[] = FindObjectsOfType(typeof(GUITexture));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;var size : Vector2;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;size.x = Screen.width / 1024.0f;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;size.y = Screen.height / 768.0f;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;for(var gui : GUITexture in guis)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;gui.pixelInset = Rect(gui.pixelInset.x * size.x, gui.pixelInset.y * size.y, gui.pixelInset.width * size.x, gui.pixelInset.height * size.y);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/380109650835793305/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2012/07/unity3d-guitexture.html#comment-form' title='1 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/380109650835793305'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/380109650835793305'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2012/07/unity3d-guitexture.html' title='UNITY3D - 自動調整GUITexture比例'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-2308573358249082751</id><published>2011-09-22T01:23:00.000-07:00</published><updated>2011-09-22T01:23:46.058-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="UNITY 3D"/><title type='text'>UNITY3D - Javascript繼承</title><content type='html'>善用繼承可以讓遊戲有更多的變化且減少無意義的COPY&amp;amp;PASTE(?)&lt;br /&gt;
&lt;br /&gt;
U3D的JS繼承用法如下&lt;br /&gt;
&lt;br /&gt;
class Parent {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;function Start () {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;print(&quot;parent&#39;s Start&quot;);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;A();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;function A () {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;print(&quot;parent&#39;s A&quot;);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;B();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;function B () {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;print(&quot;parent&#39;s B&quot;);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;C();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;function C () {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;print(&quot;parent&#39;s C&quot;);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class Children extends Parent {&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;function A () {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;print(&quot;Children&#39;s A&quot;);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;B();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;function C () {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;super.C();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;print(&quot;Children&#39;s C&quot;);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
如果在GameObject上附加Children時會發現此GameObject的執行結果為&lt;br /&gt;
parent&#39;s Start&lt;br /&gt;
Children&#39;s A&lt;br /&gt;
parent&#39;s B&lt;br /&gt;
parent&#39;s C&lt;br /&gt;
Children&#39;s C&lt;br /&gt;
&lt;br /&gt;
在寫怪物AI時用繼承的方式會輕鬆很多，底層先寫好每隻怪都會做的動作(移動、攻擊等等)，繼承後就可以按不同需求附加個別處理如(特殊攻擊)。&lt;br /&gt;
</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/2308573358249082751/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2011/09/unity3d-javascript.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/2308573358249082751'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/2308573358249082751'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2011/09/unity3d-javascript.html' title='UNITY3D - Javascript繼承'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-5646168540874251193</id><published>2011-09-15T02:34:00.000-07:00</published><updated>2011-09-15T02:34:30.905-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="UNITY 3D"/><title type='text'>UNITY3D - 圖層觀念</title><content type='html'>U3D裡面有2D物件也有3D物件，因此要注意物件之間是否會造成顯示異常。&lt;br /&gt;
&lt;br /&gt;
2D世界其實跟3D世界不屬於同一個世界...&lt;br /&gt;
可以把2D世界當成是貼在鏡頭前，所以2D物件一定會在介面上擋到3D物件。&lt;br /&gt;
而2D世界中的圖片會依據transform.position.z來當作圖層設定，z軸越大表示圖越上面。&lt;br /&gt;
&lt;br /&gt;
例：&lt;br /&gt;
A圖片z軸為0&lt;br /&gt;
B圖片z軸為1&lt;br /&gt;
C圖片z軸為2&lt;br /&gt;
&lt;br /&gt;
呈現出來就會變成&lt;br /&gt;
┌───────┐&lt;br /&gt;
│ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;┌───────┐&lt;br /&gt;
│ A &amp;nbsp; &amp;nbsp;│　　┌───────┐&lt;br /&gt;
│ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;│ B &amp;nbsp; &amp;nbsp;│　　 　　 &amp;nbsp;&amp;nbsp;│&lt;br /&gt;
└───│　　│　C 　　 &amp;nbsp;&amp;nbsp;│&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;└───│ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;│&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; └───────┘&lt;br /&gt;
&lt;br /&gt;
要注意的是在OnGUI底下畫出來的東西圖層是最高的，所以2D物件也會被OnGUI的東西蓋到喔。</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/5646168540874251193/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2011/09/unity3d.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/5646168540874251193'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/5646168540874251193'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2011/09/unity3d.html' title='UNITY3D - 圖層觀念'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-2253717620239669180</id><published>2011-08-31T23:00:00.000-07:00</published><updated>2011-08-31T23:00:23.461-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="UNITY 3D"/><title type='text'>UNITY3D - 2D圖動畫工具</title><content type='html'>&lt;br /&gt;
遊戲中常常會用到一些2D連續圖來做UI特效，但是UNITY 3D本身不支援GIF格式的檔案，基於這些需求而寫了以下這隻程式。&lt;br /&gt;
目前的功能有：&lt;br /&gt;
1.播放一次&lt;br /&gt;
2.循環播放&lt;br /&gt;
3.淡入&lt;br /&gt;
4.淡出&lt;br /&gt;
5.放大&lt;br /&gt;
6.縮小&lt;br /&gt;
7.上升&lt;br /&gt;
8.下降&lt;br /&gt;
&lt;br /&gt;
變數功能：&lt;br /&gt;
aniplayers&amp;nbsp;：動畫詳細設定&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;size：有幾段動畫要播放&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;aniTexture：放連續圖的位置，需依序放入。&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;playTime：這段動畫的播放時間長度&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;frequency：時間內播放次數(淡入、淡出、放大、縮小、上升、下降無作用)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;playMode：播放模式(播放一次、循環播放、淡入、淡出、放大、縮小、上升、下降)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;waitTime：播放後等待時間(循環播放的作用為多久循環一次)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;offset：偏移量，放大、縮小、上升、下降的依據&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;sync：同步，勾選後會跟下一段動畫同步播放&lt;br /&gt;
destroy：動畫播放完是否銷毀此GameObject&lt;br /&gt;
&lt;br /&gt;
注意事項：&lt;br /&gt;
若勾選destroy時，至少要有一段動畫不能勾選sync&lt;br /&gt;
&lt;br /&gt;
=======================================================================&lt;br /&gt;
&lt;br /&gt;
enum AniPlayMode {PlayOnce,PlayCycle,FadeIn,FadeOut,Magnify,Minify,Up,Down};&lt;br /&gt;
class ANIPLAYER {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;var aniTexture : Texture[];&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;@HideInInspector var startTime : float;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;var playTime : float;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;var frequency : int;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;var playMode : AniPlayMode;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;var waitTime : float;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;var offset : float;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;var sync : boolean;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
var aniplayers : ANIPLAYER[];&lt;br /&gt;
var destroy : boolean;&lt;br /&gt;
&lt;br /&gt;
@script RequireComponent (GUITexture)&lt;br /&gt;
&lt;br /&gt;
function OnEnable () {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;Play();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function Play () {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;for(var aniplayer : ANIPLAYER in aniplayers)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;if(aniplayer.playMode == AniPlayMode.PlayOnce)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;if(aniplayer.sync)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;PlayOnce(aniplayer);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;else&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;yield PlayOnce(aniplayer);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;else if(aniplayer.playMode == AniPlayMode.PlayCycle)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;if(aniplayer.sync)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;PlayCycle(aniplayer);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;else&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;yield PlayCycle(aniplayer);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;else if(aniplayer.playMode == AniPlayMode.FadeIn)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;if(aniplayer.sync)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;FadeIn(aniplayer);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;else&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;yield FadeIn(aniplayer);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;else if(aniplayer.playMode == AniPlayMode.FadeOut)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;if(aniplayer.sync)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;FadeOut(aniplayer);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;else&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;yield FadeOut(aniplayer);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;else if(aniplayer.playMode == AniPlayMode.Magnify)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;if(aniplayer.sync)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;Magnify(aniplayer);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;else&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;yield Magnify(aniplayer);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;else if(aniplayer.playMode == AniPlayMode.Minify)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;if(aniplayer.sync)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;Minify(aniplayer);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;else&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;yield Minify(aniplayer);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;else if(aniplayer.playMode == AniPlayMode.Up)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;if(aniplayer.sync)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;Up(aniplayer);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;else&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;yield Up(aniplayer);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;else if(aniplayer.playMode == AniPlayMode.Down)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;if(aniplayer.sync)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;Down(aniplayer);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;else&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;yield Down(aniplayer);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;if(destroy)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;Destroy(gameObject);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function PlayOnce (aniplayer : ANIPLAYER) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;var index : int;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;aniplayer.startTime = 0.0f;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;while(aniplayer.startTime &amp;lt;= aniplayer.playTime)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;index = (aniplayer.startTime * (aniplayer.aniTexture.Length / aniplayer.playTime) * aniplayer.frequency) % aniplayer.aniTexture.Length;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;guiTexture.texture = aniplayer.aniTexture[index];&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;aniplayer.startTime = aniplayer.startTime + Time.deltaTime;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;yield;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;yield WaitForSeconds(aniplayer.waitTime);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function PlayCycle (aniplayer : ANIPLAYER) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;var index : int;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;aniplayer.startTime = 0.0f;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;while(true)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;while(aniplayer.startTime &amp;lt;= aniplayer.playTime)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;index = (aniplayer.startTime * (aniplayer.aniTexture.Length / aniplayer.playTime) * aniplayer.frequency) % aniplayer.aniTexture.Length;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;guiTexture.texture = aniplayer.aniTexture[index];&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;aniplayer.startTime = aniplayer.startTime + Time.deltaTime;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;yield;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;yield WaitForSeconds(aniplayer.waitTime);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;aniplayer.startTime = 0.0f;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function FadeIn (aniplayer : ANIPLAYER) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;aniplayer.startTime = 0.0f;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;guiTexture.color.a = 0;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;while(aniplayer.startTime &amp;lt;= aniplayer.playTime)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;aniplayer.startTime = aniplayer.startTime + Time.deltaTime;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;guiTexture.color.a = guiTexture.color.a + (Time.deltaTime / aniplayer.playTime);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;yield;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;yield WaitForSeconds(aniplayer.waitTime);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function FadeOut (aniplayer : ANIPLAYER) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;aniplayer.startTime = 0.0f;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;while(aniplayer.startTime &amp;lt;= aniplayer.playTime)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;aniplayer.startTime = aniplayer.startTime + Time.deltaTime;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;guiTexture.color.a = guiTexture.color.a - (Time.deltaTime / aniplayer.playTime);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;yield;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;yield WaitForSeconds(aniplayer.waitTime);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function Magnify (aniplayer : ANIPLAYER) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;var scale : float = guiTexture.pixelInset.width / guiTexture.pixelInset.height;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;aniplayer.startTime = 0.0f;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;while(aniplayer.startTime &amp;lt;= aniplayer.playTime)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;aniplayer.startTime = aniplayer.startTime + Time.deltaTime;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;guiTexture.pixelInset.width = guiTexture.pixelInset.width + Time.deltaTime * aniplayer.offset * scale;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;guiTexture.pixelInset.height = guiTexture.pixelInset.height + Time.deltaTime * aniplayer.offset;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;guiTexture.pixelInset.x = guiTexture.pixelInset.x - Time.deltaTime * aniplayer.offset * scale / 2;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;guiTexture.pixelInset.y = guiTexture.pixelInset.y - Time.deltaTime * aniplayer.offset / 2;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;yield;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;yield WaitForSeconds(aniplayer.waitTime);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function Minify (aniplayer : ANIPLAYER) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;var scale : float = guiTexture.pixelInset.width / guiTexture.pixelInset.height;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;aniplayer.startTime = 0.0f;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;while(aniplayer.startTime &amp;lt;= aniplayer.playTime)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;aniplayer.startTime = aniplayer.startTime + Time.deltaTime;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;guiTexture.pixelInset.width = guiTexture.pixelInset.width - Time.deltaTime * aniplayer.offset * scale;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;guiTexture.pixelInset.height = guiTexture.pixelInset.height - Time.deltaTime * aniplayer.offset;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;guiTexture.pixelInset.x = guiTexture.pixelInset.x + Time.deltaTime * aniplayer.offset * scale / 2;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;guiTexture.pixelInset.y = guiTexture.pixelInset.y + Time.deltaTime * aniplayer.offset / 2;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;yield;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;yield WaitForSeconds(aniplayer.waitTime);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function Up (aniplayer : ANIPLAYER) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;aniplayer.startTime = 0.0f;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;while(aniplayer.startTime &amp;lt;= aniplayer.playTime)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;aniplayer.startTime = aniplayer.startTime + Time.deltaTime;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;guiTexture.pixelInset.y = guiTexture.pixelInset.y + Time.deltaTime * aniplayer.offset;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;yield;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;yield WaitForSeconds(aniplayer.waitTime);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function Down (aniplayer : ANIPLAYER) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;aniplayer.startTime = 0.0f;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;while(aniplayer.startTime &amp;lt;= aniplayer.playTime)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;aniplayer.startTime = aniplayer.startTime + Time.deltaTime;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;guiTexture.pixelInset.y = guiTexture.pixelInset.y - Time.deltaTime * aniplayer.offset;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;yield;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;yield WaitForSeconds(aniplayer.waitTime);&lt;br /&gt;
}</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/2253717620239669180/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2011/08/unity3d-2d.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/2253717620239669180'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/2253717620239669180'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2011/08/unity3d-2d.html' title='UNITY3D - 2D圖動畫工具'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-3430672877139160419</id><published>2011-07-24T23:05:00.000-07:00</published><updated>2011-07-24T23:05:55.408-07:00</updated><title type='text'>蚊語錄</title><content type='html'>記錄自己說過，且還不錯的觀念&lt;br /&gt;
&lt;br /&gt;
經典遊戲之所以經典是因為它的獨特性&lt;br /&gt;
當延續好幾代都差不多或者看起來感覺都一樣，那它就爛掉了</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/3430672877139160419/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2011/07/blog-post_24.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/3430672877139160419'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/3430672877139160419'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2011/07/blog-post_24.html' title='蚊語錄'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-4644080768861264689</id><published>2011-07-20T03:27:00.000-07:00</published><updated>2011-07-20T03:27:35.836-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="UNITY 3D"/><title type='text'>UNITY3D - 圖片淡入淡出</title><content type='html'>圖片淡入淡出其實跟GameObject逐漸透明消失的做法類似&lt;br /&gt;
只要改圖片本身的透明度就好了&lt;br /&gt;
要記得一點是顏色跟透明度的值是(x/256)的float值，不要以為直接塞1~256的值就可以...&lt;br /&gt;
&lt;br /&gt;
圖片淡入&lt;br /&gt;
=========================================================================&lt;br /&gt;
function Start ()&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;guiTexture.color.a = 0; //讓圖片一開始為透明&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function Update ()&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if(guiTexture.color.a &amp;lt; 1)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;guiTexture.color.a = guiTexture.color.a + Time.deltaTime;&amp;nbsp;//讓圖片隨時間變不透明&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=========================================================================&lt;br /&gt;
&lt;br /&gt;
畫面淡出&lt;br /&gt;
=========================================================================&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;function Start ()&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;{&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;guiTexture.color.a = 1; //讓圖片一開始為不透明&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;}&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;function Update ()&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;{&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if(guiTexture.color.a &amp;lt; 1)&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;guiTexture.color.a = guiTexture.color.a - Time.deltaTime;&amp;nbsp;//讓圖片隨時間變透明&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;}&lt;/div&gt;&lt;br /&gt;
=========================================================================</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/4644080768861264689/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2011/07/unity3d_20.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/4644080768861264689'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/4644080768861264689'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2011/07/unity3d_20.html' title='UNITY3D - 圖片淡入淡出'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-156693932724511471</id><published>2011-07-13T03:05:00.000-07:00</published><updated>2011-07-13T03:05:17.208-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="UNITY 3D"/><title type='text'>UNITY3D - 連續貼圖</title><content type='html'>&lt;div&gt;U3D不支援顯示gif檔案，但是我們可以利用程式來將一連串的靜態圖片顯示得跟動態圖片無異。&lt;br /&gt;
首先建立一個empty object然後加入下面component script。&lt;br /&gt;
&lt;br /&gt;
=======================================================================&lt;br /&gt;
var aTexture : Texture[]; //靜態圖片組&lt;br /&gt;
var framePerSecond : int; //每秒播放張數&lt;br /&gt;
var x : int; //x軸位置(以pixel為單位)&lt;br /&gt;
var y : int;&amp;nbsp;//y軸位置(以pixel為單位)&lt;br /&gt;
private var startTime : float;&lt;br /&gt;
function Start () {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; startTime = Time.time; //記錄開始時間，確保圖從第一張開始放。&lt;br /&gt;
}&lt;br /&gt;
function OnGUI () {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; var index : int = ((Time.time - startTime) * framePerSecond) % aTexture.Length;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; GUI.DrawTexture(Rect(x, y,&amp;nbsp;aTexture[index].width,&amp;nbsp;aTexture[index].height),&amp;nbsp;aTexture[index], ScaleMode.StretchToFill, true, 0);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
=======================================================================&lt;br /&gt;
加入component後將靜態圖按順序設給aTexture以及設定framePerSecond與XY軸就可以看到在設好的(x,y)上顯示靜態圖片組成的動畫了。&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/156693932724511471/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2011/07/unity3d.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/156693932724511471'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/156693932724511471'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2011/07/unity3d.html' title='UNITY3D - 連續貼圖'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-2441091629837731147</id><published>2011-07-13T00:10:00.001-07:00</published><updated>2011-07-13T00:10:06.234-07:00</updated><title type='text'>手機測試</title><content type='html'>&lt;div&gt;&lt;p&gt;&amp;#28204;&amp;#35430;&amp;#25163;&amp;#27231;&amp;#29256;blogger&amp;#25928;&amp;#26524;...&amp;#19978;&amp;#35506;&amp;#22826;&amp;#28961;&amp;#32842;&amp;#65292;&amp;#22914;&amp;#26524;&amp;#25928;&amp;#26524;&amp;#19981;&amp;#37679;&amp;#20043;&amp;#24460;&amp;#23601;&amp;#19978;&amp;#35506;&amp;#23531;&amp;#25945;&amp;#23416;&amp;#22909;&amp;#20102;&amp;#12290;&lt;/p&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/2441091629837731147/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2011/07/blog-post.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/2441091629837731147'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/2441091629837731147'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2011/07/blog-post.html' title='手機測試'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-7584264185152130202</id><published>2011-07-03T22:54:00.000-07:00</published><updated>2011-07-03T22:54:39.026-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="UNITY 3D"/><title type='text'>UNITY3D - GameObject逐漸透明消失</title><content type='html'>private var startTime : float;&lt;br /&gt;
private var alpha : float = 255.0f;&lt;br /&gt;
&lt;br /&gt;
function Start () {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;startTime = Time.time;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function Update () {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; if((Time.time - startTime) &amp;gt; 5)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;var render = gameObject.GetComponentInChildren(Renderer);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;alpha = alpha - 10.0f;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;render.material.color.a = alpha / 255.0f;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if(render.material.color.a &amp;lt;= 0)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;Destroy(gameObject);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
用處：用在怪被打死後逐漸消失。&lt;br /&gt;
&lt;br /&gt;
以上程式功能為物件產生出來後經過5秒，然後將render的透明度逐漸遞減，當透明度低於0則清除此物件。&lt;b&gt;注：Material的Shader必須用允許透明的Shader。&lt;/b&gt;</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/7584264185152130202/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2011/07/unity3d-gameobject.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/7584264185152130202'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/7584264185152130202'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2011/07/unity3d-gameobject.html' title='UNITY3D - GameObject逐漸透明消失'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3744480327179109411.post-8079099723047257001</id><published>2011-06-30T20:01:00.000-07:00</published><updated>2013-01-26T06:46:54.024-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="UNITY 3D"/><title type='text'>UNITY3D - 畫面震動效果</title><content type='html'>遊戲設計其實跟電影拍攝的概念很類似，構成電影最基本的元素是導演、攝影師、劇本、演員，而構成遊戲的最基本元素是鏡頭(導演、攝影師)、角色與NPC設定(劇本、演員)。&lt;br /&gt;
&lt;br /&gt;
角色與NPC設定屬於控制與AI的設計，有賴於程設的構思去完善。相信很多人都會忽略鏡頭的重要性，但其實鏡頭就如同導演一般，要負責的東西多又繁雜且細膩。簡單來說...畫面上看到的東西都是鏡頭負責的(好像是廢話)，舉凡玩家視角、遊戲介面、選單、畫面特效(震動、畫面變色)等等都是用鏡頭來呈現。&lt;br /&gt;
&lt;br /&gt;
畫面震動的效果其實說穿了也沒什麼...不就是鏡頭晃一下就好了？以下是javascript code，附加到鏡頭上試試效果吧。&lt;br /&gt;
var shakePower : float = 2.0f; //設定震動的幅度&lt;br /&gt;
var shakeDelay : float = 0.05f; //設定震動的間隔時間&lt;br /&gt;
&lt;br /&gt;
function UpDownShake () //上下震動&lt;br /&gt;
{&lt;br /&gt;
transform.Translate(Vector3.up * shakePower);&lt;br /&gt;
yield WaitForSeconds(shakeDelay);&lt;br /&gt;
transform.Translate(Vector3.up * -shakePower);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function LeftRightShake () //左右震動&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
transform.Translate(Vector3.right * -shakePower);&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
yield WaitForSeconds(shakeDelay);&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
transform.Translate(Vector3.right * shakePower);&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
function ForwardBackShake () //前後震動&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
transform.Translate(Vector3.&lt;span style=&quot;background-color: white; font-family: Helvetica, Arial, sans-serif; font-size: 18px; line-height: 25px;&quot;&gt;forward&lt;/span&gt;&amp;nbsp;* shakePower);&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
yield WaitForSeconds(shakeDelay);&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
transform.Translate(Vector3.&lt;span style=&quot;background-color: white; font-family: Helvetica, Arial, sans-serif; font-size: 18px; line-height: 25px;&quot;&gt;forward&lt;/span&gt;&amp;nbsp;* -shakePower);&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
function XRotateShake () //X軸晃動&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;transform.Rotate(Vector3.right * shakeAngle);&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;yield WaitForSeconds(shakeDelay);&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;transform.Rotate(Vector3.right * -shakeAngle);&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
function YRotateShake () //Y軸晃動&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;transform.Rotate(Vector3.up * shakeAngle);&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;yield WaitForSeconds(shakeDelay);&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;transform.Rotate(Vector3.up * -shakeAngle);&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
function ZRotateShake () //Z軸晃動&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;transform.Rotate(Vector3.foward * shakeAngle);&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;yield WaitForSeconds(shakeDelay);&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;transform.Rotate(Vector3.foward * -shakeAngle);&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
function Update ()&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; if(Input.&lt;/span&gt;GetKeyDown&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;(KeyCode.Keypad1))  {   StartCoroutine(&quot;&lt;/span&gt;UpDownShake&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&quot;);  }&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; if(Input.&lt;/span&gt;GetKeyDown&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;(KeyCode.Keypad&lt;/span&gt;2&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;))  {   StartCoroutine(&quot;&lt;/span&gt;LeftRightShake&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&quot;);  }&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; if(Input.&lt;/span&gt;GetKeyDown&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;(KeyCode.Keypad&lt;/span&gt;3&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;))  {   StartCoroutine(&quot;&lt;/span&gt;ForwardBackShake&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&quot;);  }&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; if(Input.&lt;/span&gt;GetKeyDown&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;(KeyCode.Keypad&lt;/span&gt;4&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;))  {   StartCoroutine(&quot;&lt;/span&gt;XRotateShake&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&quot;);  }&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; if(Input.&lt;/span&gt;GetKeyDown&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;(KeyCode.Keypad&lt;/span&gt;5&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;))  {   StartCoroutine(&quot;&lt;/span&gt;YRotateShake&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&quot;);  }&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; if(Input.&lt;/span&gt;GetKeyDown&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;(KeyCode.Keypad&lt;/span&gt;6&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;))  {   StartCoroutine(&quot;&lt;/span&gt;YRotateShake&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&quot;);  }&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
}&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://playprograms.blogspot.com/feeds/8079099723047257001/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://playprograms.blogspot.com/2011/06/unity3d_30.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/8079099723047257001'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3744480327179109411/posts/default/8079099723047257001'/><link rel='alternate' type='text/html' href='http://playprograms.blogspot.com/2011/06/unity3d_30.html' title='UNITY3D - 畫面震動效果'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16385285145533346954</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>