/// <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"); }
// Update is called once per frame void Update() { if (Input.GetAxis("Horizontal") < 0f) { transform.rotation = Quaternion.Euler(0, 270, 0); // transform.Translate(new Vector3(-0.05f, 0f, 0f)); } if (Input.GetAxis("Horizontal") > 0f) { transform.rotation = Quaternion.Euler(0, 90, 0); // transform.Translate(new Vector3(0.05f, 0f, 0f)); } if (Input.GetAxis("Vertical") > 0f) { transform.rotation = Quaternion.Euler(0, 0, 0); // transform.Translate(new Vector3(0f, 0f, -0.05f)); } if (Input.GetAxis("Vertical") < 0f) { transform.rotation = Quaternion.Euler(0, 180, 0); // transform.Translate(new Vector3(0f, 0f, 0.05f)); } if ((Mathf.Abs(Input.GetAxis("Horizontal")) >= 0.1f || Mathf.Abs(Input.GetAxis("Vertical")) >= 0.1f) && !falling && !climbing) { Vector3 speed = CheckCollisions(Vector3.forward * 0.075f); transform.Translate(speed); TopAnimator.Play(); BottomAnimator.Play(); } else { TopAnimator.Pause(); BottomAnimator.Pause(); } // Falling CheckFallCollisions(); if (falling) { fallSpeed += 0.01f; transform.Translate(Vector3.down * fallSpeed); } else { // We're not falling, so find the height of the ground beneath our feet and set the "climbing" flag //for(float y=0.1f;y<2f;y+=0.1f) if (IsVoxelAtPoint(transform.position + new Vector3(0, 0.1f, 0))) { climbing = true; transform.Translate(Vector3.up * (0.1f)); } else { climbing = false; } fallSpeed = 0f; } }
protected override void OnUpdate() { base.OnUpdate(); timer += Time.DeltaTime; if (timer > 10) { if (anim.IsPlaying("Anim")) { anim.Play("Anim2"); } else { anim.Play("Anim"); } timer = 0f; } }
/// <inheritdoc /> public override void OnSelected() { base.OnSelected(); if (!Configured || AnimatorComponent.IsPlaying("toggle")) { return; } AnimatorComponent.Play("highlight"); }
/// <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; }