private void SetStates(SwitchEnum star1, SwitchEnum star2, SwitchEnum star3) { float delay = 0; float delta = 0.5f; IGameAction animations = null; if (this.Owner != null && this.Owner.Scene != null) { animations = this.Owner.Scene.CreateEmptyGameAction(); } if (this.star1Component != null) { this.star1Component.State = star1; if (star1 == SwitchEnum.ON) { delay += delta; animations.ContinueWith(this.CreateStarAnimation(this.star1Component.Owner, delay)); } } if (this.star2Component != null) { this.star2Component.State = star2; if (star2 == SwitchEnum.ON) { delay += delta; animations.ContinueWith(this.CreateStarAnimation(this.star2Component.Owner, delay)); } } if (this.star3Component != null) { this.star3Component.State = star3; if (star3 == SwitchEnum.ON) { delay += delta; animations.ContinueWith(this.CreateStarAnimation(this.star3Component.Owner, delay)); } } if (animations != null) { animations.Run(); } }
public void MoveTo(Entity destinationEntity) { var scene = this.Owner.Scene; var cameraPoint = FindCameraPosition(this.Owner); List <Transform3D> path = calculatePath(this.Owner, cameraPoint, destinationEntity); var limitCameraBehavior = Owner.FindComponent <LimitCameraBehavior>(); limitCameraBehavior.IsActive = false; IGameAction action = null; if (path.Count() > 1) { // rotation action IGameAction rotationAction = null; for (int i = 0; i < path.Count; i++) { if (i == 0) { rotationAction = scene.CreateGameAction( new RotateToShortest3DGameAction( Owner, path[i].Rotation, TimeSpan.FromSeconds(TranslationDuration / path.Count), EaseFunction.None, false, true)); } else { rotationAction = rotationAction.ContinueWith( scene.CreateGameAction( new RotateToShortest3DGameAction( Owner, path[i].Rotation, TimeSpan.FromSeconds(TranslationDuration / path.Count), (i == path.Count - 1) ? EaseFunction.SineOutEase : EaseFunction.None, false, true))); } } // init movement rotation var transform = this.Owner.FindComponent <Transform3D>(); path.Insert(0, transform); CatmullRomSpline catmullRomSpline = new CatmullRomSpline(path.ToArray()); action = scene.CreateParallelGameActions( new FloatAnimationGameAction( this.Owner, 0, 1, TimeSpan.FromSeconds(TranslationDuration), EaseFunction.SineInOutEase, (lerp) => { transform.Position = catmullRomSpline.GetPosition(lerp); }), rotationAction ) .WaitAll(); } else { action = scene.CreateParallelGameActions( new MoveTo3DGameAction( this.Owner, path.Last().Position, TimeSpan.FromSeconds(TranslationDuration), EaseFunction.SineInOutEase), new RotateToShortest3DGameAction( this.Owner, path.Last().Rotation, TimeSpan.FromSeconds(TranslationDuration), EaseFunction.SineOutEase, false, true)) .WaitAll(); } if (action != null) { action.Run(); action.Completed += (obj) => { limitCameraBehavior.OriginalRotation = path.Last().Rotation; limitCameraBehavior.IsActive = true; var destinationLimitCameraBehavior = destinationEntity.FindComponent <LimitCameraBehavior>(); limitCameraBehavior.MaxPitch = destinationLimitCameraBehavior?.MaxPitch ?? LimitCameraBehavior.DefaultMaxPitch; limitCameraBehavior.MaxYaw = destinationLimitCameraBehavior?.MaxYaw ?? LimitCameraBehavior.DefaultMaxYaw; // Invoke subscribed AnimationCompleted?.Invoke(this, new EventArgs()); }; } }