ラベル Asset (Unity) の投稿を表示しています。 すべての投稿を表示
ラベル Asset (Unity) の投稿を表示しています。 すべての投稿を表示

2016年8月10日水曜日

UnityのMarkLightについて覚書 2

UnityのMarkLightについて覚書 2
MarkLight (AssetStore)
MarkLight Document (英語)

コード内でアニメーションを動的に生成したい時はここ(Creating Animations in Code)に記載があります。
以下、そのまま抜粋

var offsetAnimator = new ViewFieldAnimator();

// set up animation
offsetAnimator.EasingFunction = EasingFunctionType.QuadraticEaseOut;
offsetAnimator.Field = "Offset"; // the field that is to be animated
offsetAnimator.From = new ElementMargin();
offsetAnimator.To = new ElementMargin(x, y, 0, 0); // x and y set during runtime
offsetAnimator.Duration = 0.2f; // duration in seconds
offsetAnimator.TargetView = MyRegion; // the view whose Offset field is to be animated

// start animation
offsetAnimator.StartAnimation();

ただ、このままアニメーションしたいタイミングの箇所に記載しても動作しません。。。
TargetViewのUpdateに以下を記述する必要があります!

ViewFieldAnimator offsetAnimator;
void Update ()
{
    if(offsetAnimator != null && offsetAnimator.IsRunning)
        offsetAnimator.Update ();
}

当然、var offsetAnimator = 〜としていた箇所はメンバ変数を見るよう修正してください!

2016年7月31日日曜日

UnityのMarkLightについて覚書 1

UnityのMarkLightについて覚書
MarkLight (AssetStore)
MarkLight Document (英語)

xmlとcsファイルが対になっている。
Viewデザインに関するファイルをxmlとして管理出来る。
日本語解説サイトはほぼ皆無(´・ω・`)

<Sample (何かしら設定) Example-Scale="1">
  <Label Text="Sample内のテキスト" Width="100%" Height="100%" TextAlignment="Center" />
  <StateAnimation From="Default" To="Example" AnimationCompleted="ExampleAnimationCompleted">
    <Animate Field="Scale" From="1" To="0.8" Duration="250ms" AutoReverse="True" EasingFunction="QuadraticEaseOut" />
  </StateAnimation>
</Sample>

上記XMLであればSample.xml, Sample.csが必要となります。
Sampleタグのオブジェクトが選択された場合やクリックされた場合などに以下コードを実行するとStateAnimation内のアニメーションが実行されます。
SetState ("Example"); // Sample.cs

そして親であるSampleタグ内にExample-Scaleという記述があると思います。
これがExample状態になった時にScaleを1に設定するという指定です。
StateAnimation内でScaleについてアニメーションさせようとしているので先に指定しておかないとアニメーションしませんでした。。。
特に指定しなくてもアニメーションさせられるんじゃないかと思っているのですが、方法は分からず(´・ω・`)
まぁ初期値的な感じで使用しています。

StateAnimationにてAnimationCompletedについて記述しており、こちらは指定したアニメーション完了時に呼び出されるメソッドを指定出来ます。
コード例は以下。
public Action OnExampleAnimationCompleted;
public void ExampleAnimationCompleted()
{
  // 何かしら処理(SetStateしたりクリックイベントを通知したり)
}

なんでメンバ変数用意しなければいけないのか、とかはまだよく分かってません。。。
先の指定もMarkLight側で紐付け作業があると思うのですが、そこまで解読出来てないです。。。
分かり次第、追記致します。

Animateタグ内は見たまんまの設定が可能です。
詳細はドキュメント内のAPIを参照してもらえればと。