URL: http://atnd.org/events/34621
5シーンあるうちの最後ですね。ちなみにアドベントカレンダーも13日目なので折り返し地点っすよ。
最後だが、とりわけ難しいってわけではないHierarchyでした。
「ui」GameObjectのInspectorを拝見します。
ShakeVariantsGUI.csなんてのがアタッチされてます。
シェイクはわかるが、Variantsは?英語がわからないので
【名詞】【可算名詞】 1変形,別形. 2a(つづり・発音の)異形. b(原典の)異文,異本.
研究社 新英和中辞典から引用
シェイクの変形?わからないので。To see is to believeなので見てみる。
7つボタンがあって、規則性のない変な動きをしてた。
動作が数秒で、動作する瞬間に停止するショートカット「command+shift+P」で撮ってみても残像がない限り静止画では何してるかわからない画像になりますね。
「Shake Eulers」のスクリーンショットにしました。
・ShakeVariantsGUI.cs
using UnityEngine; using System.Collections; public class ShakeVariantsGUI : BaseDemoGUI { public Transform cube; protected override void OnGUI () { // make some buttons to showcase different shake types if (GUILayout.Button ("Shake Position")) { stopRunningTween (); _tween = Go.to (cube, 0.5f, new TweenConfig ().shake (new Vector3 (1, 1, 1), ShakeType.Position)); } if (GUILayout.Button ("Shake Scale")) { stopRunningTween (); _tween = Go.to (cube, 0.5f, new TweenConfig ().shake (new Vector3 (2, 2, 2), ShakeType.Scale)); } if (GUILayout.Button ("Shake Eulers")) { stopRunningTween (); _tween = Go.to (cube, 0.5f, new TweenConfig ().shake (new Vector3 (150, 150, 150), ShakeType.Eulers)); } if (GUILayout.Button ("Shake Position & Scale")) { stopRunningTween (); _tween = Go.to (cube, 0.5f, new TweenConfig ().shake (new Vector3 (1, 1, 1), ShakeType.Position | ShakeType.Scale)); } // we add the eulers separately here so that we can get enough magnitude with the shake if (GUILayout.Button ("Shake Position & Eulers")) { stopRunningTween (); _tween = Go.to (cube, 0.5f, new TweenConfig ().shake (new Vector3 (1, 1, 1), ShakeType.Position).shake (new Vector3 (150, 150, 150), ShakeType.Eulers)); } if (GUILayout.Button ("Shake Position, Scale & Eulers")) { stopRunningTween (); _tween = Go.to (cube, 0.5f, new TweenConfig ().shake (new Vector3 (1, 1, 1), ShakeType.Position | ShakeType.Scale).shake (new Vector3 (150, 150, 150), ShakeType.Eulers)); } // the frameMod parameter basically acts as a way to slow down the shake by skipping frames in the animation // to make it a bit less jumpy if (GUILayout.Button ("Shake Position with Frame Mod")) { stopRunningTween (); _tween = Go.to (cube, 0.5f, new TweenConfig ().shake (new Vector3 (1, 1, 1), ShakeType.Position, 2)); } } private void stopRunningTween () { // shake tweens should always be completed before stopping to ensure the item ends up in // the same location it started if (_tween != null) { _tween.complete (); _tween.destroy (); _tween = null; } } }
ShakeVariantsGUIは、BaseDemoGUIクラスをいつもどおり継承してますね。
しかし、「OnGUI ()」をオーバーライドしてますねw
ぶっちゃけ使ってるのは、MonoBehaviorであることと、_tween変数があることが揃っていればいいので、
最初のあたりの行をこのようにしても別にOK
//public class ShakeVariantsGUI : BaseDemoGUI public class ShakeVariantsGUI : MonoBehaviour { public Transform cube; protected AbstractTween _tween; // protected override void OnGUI () void OnGUI () {
特筆するのはこれで初期化を、まずしてること。
stopRunningTween ();
Shake Positionでやってるのは、こんなかんじだが、
_tween = Go.to (cube, 0.5f, new TweenConfig ().shake (new Vector3 (1, 1, 1), ShakeType.Position));
Go.toの第1引数はGameObjectで第2引数は、durationで第3引数はコンフィグ
このコンフィグが重要で、
shakeの引数に、振れ幅とタイプを入れている。
ShakeType.Positionが座標移動、ShakeType.Scaleは大きさ・・な具合ですね。
ShakeTypeは「|(パイプライン)」で、ブレンドして組み合わせるっぽいです。
ShakeType.Position | ShakeType.Scale
その場合は、Vector3の値が共通になってしまうので、
_tween = Go.to (cube, 0.5f, new TweenConfig ().shake (new Vector3 (1, 1, 1), ShakeType.Position | ShakeType.Scale).shake (new Vector3 (150, 150, 150), ShakeType.Eulers));
このようにshakeの返り値にさらに.shakeでメソッドチェーンしてるのですね。
今までネタがないから、GoKitについてを続けましたが、今回で最後です。
明日はNGUIのAtlas書き出しハックかな?