/// <inheritdoc /> protected sealed override void OnInitialize() { base.OnInitialize(); int m = Random.Next(5); Sprite sprite = new Sprite(AssetManager.Get <SpriteTexture>(this, "floor"), Color.White) { LayerDepth = 0.1f, }; AddComponent(sprite); Vector2 startPos = Transform.Position; AnimatedVector2 f = new AnimatedVector2(); Curve c = new Curve(); c.Keys.Add(new CurveKey(0, 0)); c.Keys.Add(new CurveKey(1, 200)); c.Keys.Add(new CurveKey(2, 100)); c.Keys.Add(new CurveKey(2.5f, 300)); f.SetCurve(c, c); f.Attach(new Ref <Vector2>(i => Transform.Position = i + startPos)); Animation aC = new Animation(f) { WrapMode = WrapMode.PingPong }; AnimatedVector2 f2 = new AnimatedVector2(); Curve c2 = new Curve(); c2.Keys.Add(new CurveKey(0, 100)); c2.Keys.Add(new CurveKey(1, 400)); c2.Keys.Add(new CurveKey(2, 150)); c2.Keys.Add(new CurveKey(2.5f, 250)); f2.SetCurve(c2, c2); f2.Attach(new Ref <Vector2>(i => Transform.Position = i + startPos)); AnimatedColor col = new AnimatedColor(); col.SetLerp(Color.White, new Color((byte)Random.Next(255), (byte)Random.Next(255), (byte)Random.Next(255), (byte)1.0f), 2.5f); col.Attach(new Ref <Color>(color => { List <Sprite> sprites = GetAllComponents <Sprite>(); for (int i = 0; i < sprites.Count; i++) { sprites[i].Color = color; } })); Animation aC2 = new Animation(f2); aC2.Add(col); aC2.WrapMode = WrapMode.PingPong; anim = new BasicAnimator(); anim.AddAnimation("Anim", aC); anim.AddAnimation("Anim2", aC2); AddComponent(anim); anim.Play("Anim2"); }
/// <summary> /// Configures the UIAnimation component by adding some generic animations: idle, highlight, click. /// </summary> /// <param name="idle">Idle animation state.</param> /// <param name="highlighted">Highlight animation state.</param> /// <param name="clicked">Click animation state.</param> /// <param name="toggled">Toggled animation state.</param> public void Configure(Animation idle, Animation highlighted, Animation clicked, Animation toggled) { Idle = idle; Highlighted = highlighted; Clicked = clicked; AnimatorComponent = new BasicAnimator(); AnimatorComponent.AddAnimation("idle", Idle); AnimatorComponent.AddAnimation("highlight", Highlighted); AnimatorComponent.AddAnimation("click", Clicked); if (toggled != null) { Toggled = toggled; AnimatorComponent.AddAnimation("toggle", Toggled); } Owner.AddComponent(AnimatorComponent); AnimatorComponent.Play("idle"); Configured = true; }