その他の書式関係
このページは映像エフェクトプラグイン作成入門の一部です。
/icons/-.icon
effectDescription.DrawDescription長すぎ問題
前回の最後に書いたコードを見てみましょう。
code:cs
public DrawDescription Update(EffectDescription effectDescription)
{
var opacity = 0.5;
var zoom = 1.2;
var rotationZ = 95;
return effectDescription.DrawDescription with
{
Opacity = opacity,
Zoom = effectDescription.DrawDescription.Zoom * (float)zoom,
Rotation = new(
effectDescription.DrawDescription.Rotation.X,
effectDescription.DrawDescription.Rotation.Y,
effectDescription.DrawDescription.Rotation.Z + rotationZ)
};
}
effectDescription.DrawDescriptionが多くて読みにくいですよね。
このコードは短く書くことができます。
code:cs
public DrawDescription Update(EffectDescription effectDescription)
{
var opacity = 0.5;
var zoom = 1.2;
var rotationZ = 95;
var drawDesc = effectDescription.DrawDescription;
return drawDesc with
{
Opacity = opacity,
Zoom = drawDesc.Zoom * (float)zoom,
Rotation = new(
drawDesc.Rotation.X,
drawDesc.Rotation.Y,
drawDesc.Rotation.Z + rotationZ)
};
}
このようにvar drawDesc = effectDescription.DrawDescription;とすれば以降のコードでdrawDescと書けます。
大きな数字の定数
次にSimpleEffectクラスの次の部分を見てください。
code:cs
Display(GroupName = "描画位置", Name = "X座標", Description = "横方向の描画位置")
AnimationSlider("F1", "px", -100, 100)
public Animation X { get; } = new Animation(0, -9999, 9999);
ここではXの下限、上限をそれぞれ-9999, 9999としています。
このような極端に大きい(小さい)数はYMM4Constants.VeryLargeValue, YMM4Constants.VerySmallValueという定数が用意されています。
値は以下の通りです。
table:YMM4Constants
YMM4Constants.VerySmallValue -100000
YMM4Constants.VeryLargeValue 100000
実際に使うときは以下のように書きます。
using YukkuriMovieMaker.Commonsを追加しておいてください。
code:cs
// using YukkuriMovieMaker.Commonsを追加しておく
Display(GroupName = "描画位置", Name = "X座標", Description = "横方向の描画位置")
AnimationSlider("F1", "px", -100, 100)
public Animation X { get; } = new Animation(0, YMM4Constants.VerySmallValue, YMM4Constants.VeryLargeValue);
// これと同じ意味になる↓
// public Animation X { get; } = new Animation(0, -100000, 100000);
好みや場合によるので数字を直接使ってもYMM4Constantsを使ってもOKです。
/icons/-.icon
次はこちら:まとめ(シンプルなエフェクトの作成)