public override async UniTask ExecuteAsync(CancellationToken cancellationToken = default) { var actorId = IdAndAppearance.Name; var manager = Engine.GetAllServices <IActorManager>(c => c.ActorExists(actorId)).FirstOrDefault(); if (manager is null) { LogErrorWithPosition($"Can't find a manager with `{actorId}` actor."); return; } var tasks = new List <UniTask>(); var cameraConfig = Engine.GetConfiguration <CameraConfiguration>(); var actor = manager.GetActor(actorId); var fromPos = new Vector3( FromPosition?.ElementAtOrNull(0)?.HasValue ?? false ? cameraConfig.SceneToWorldSpace(new Vector2(FromPosition[0] / 100f, 0)).x : actor.Visible ? actor.Position.x : cameraConfig.SceneToWorldSpace(new Vector2(Random.value > .5f ? -.1f : 1.1f, 0)).x, FromPosition?.ElementAtOrNull(1)?.HasValue ?? false ? cameraConfig.SceneToWorldSpace(new Vector2(0, FromPosition[1] / 100f)).y : actor.Position.y, FromPosition?.ElementAtOrNull(2) ?? actor.Position.z); var toPos = new Vector3( ToPosition.ElementAtOrNull(0)?.HasValue ?? false ? cameraConfig.SceneToWorldSpace(new Vector2(ToPosition[0] / 100f, 0)).x : actor.Position.x, ToPosition.ElementAtOrNull(1)?.HasValue ?? false ? cameraConfig.SceneToWorldSpace(new Vector2(0, ToPosition[1] / 100f)).y : actor.Position.y, ToPosition.ElementAtOrNull(2) ?? actor.Position.z); var easingType = manager.ActorManagerConfiguration.DefaultEasing; if (Assigned(EasingTypeName) && !System.Enum.TryParse(EasingTypeName, true, out easingType)) { LogWarningWithPosition($"Failed to parse `{EasingTypeName}` easing."); } actor.Position = fromPos; if (!actor.Visible) { if (IdAndAppearance.NamedValue.HasValue) { actor.Appearance = IdAndAppearance.NamedValue; } Visible = true; } else if (IdAndAppearance.NamedValue.HasValue) { tasks.Add(actor.ChangeAppearanceAsync(IdAndAppearance.NamedValue, Duration, easingType, null, cancellationToken)); } if (Assigned(Visible)) { tasks.Add(actor.ChangeVisibilityAsync(Visible, Duration, easingType, cancellationToken)); } tasks.Add(actor.ChangePositionAsync(toPos, Duration, easingType, cancellationToken)); await UniTask.WhenAll(tasks); }
public override async UniTask ExecuteAsync(CancellationToken cancellationToken = default) { if (MakeDefault && !string.IsNullOrEmpty(AssignedPrinterId)) { PrinterManager.DefaultPrinterId = AssignedPrinterId; } if (HideOther) { foreach (var prntr in PrinterManager.GetAllActors()) { if (prntr.Id != (AssignedPrinterId ?? PrinterManager.DefaultPrinterId) && prntr.Visible) { prntr.ChangeVisibilityAsync(false, Duration).Forget(); } } } var printer = default(ITextPrinterActor); var appearance = Assigned(IdAndAppearance) ? IdAndAppearance.NamedValue : null; if (!string.IsNullOrEmpty(appearance)) { if (printer is null) { printer = await GetOrAddPrinterAsync(); } await printer.ChangeAppearanceAsync(appearance, Duration, cancellationToken : cancellationToken); } if (Assigned(ScenePosition)) { if (printer is null) { printer = await GetOrAddPrinterAsync(); } var position = new Vector3( ScenePosition.ElementAtOrNull(0) != null ? ScenePosition[0].Value / 100f : printer.Position.x, ScenePosition.ElementAtOrNull(1) != null ? ScenePosition[1].Value / 100f : printer.Position.y, ScenePosition.ElementAtOrNull(2) ?? printer.Position.z ); await printer.ChangePositionAsync(position, Duration, cancellationToken : cancellationToken); } if (Assigned(Visible) || Configuration.AutoShowOnModify) { if (printer is null) { printer = await GetOrAddPrinterAsync(); } await printer.ChangeVisibilityAsync(Visible, Duration, cancellationToken : cancellationToken); } }
public override async UniTask ExecuteAsync(CancellationToken cancellationToken = default) { var easingType = EasingType.Linear; if (Assigned(EasingTypeName) && !Enum.TryParse(EasingTypeName, true, out easingType)) { LogWarningWithPosition($"Failed to parse `{EasingTypeName}` easing."); } var transitionName = TransitionType.Crossfade; if (Assigned(Transition)) { transitionName = Transition.Value; } var defaultParams = TransitionUtils.GetDefaultParams(transitionName); var transitionParams = Assigned(TransitionParams) ? new Vector4( TransitionParams.ElementAtOrNull(0) ?? defaultParams.x, TransitionParams.ElementAtOrNull(1) ?? defaultParams.y, TransitionParams.ElementAtOrNull(2) ?? defaultParams.z, TransitionParams.ElementAtOrNull(3) ?? defaultParams.w) : defaultParams; if (Assigned(DissolveTexturePath) && !ObjectUtils.IsValid(preloadedDissolveTexture)) { preloadedDissolveTexture = Resources.Load <Texture2D>(DissolveTexturePath); } var transition = new Transition(transitionName, transitionParams, preloadedDissolveTexture); var transitionUI = Engine.GetService <IUIManager>().GetUI <UI.ISceneTransitionUI>(); if (transitionUI != null) { await transitionUI.TransitionAsync(transition, Duration, easingType, cancellationToken); } else { LogErrorWithPosition($"Failed to finish scene transition: `{nameof(UI.ISceneTransitionUI)}` UI is not available."); } }
private float?[] AttemptScenePosition() { if (!Assigned(ScenePosition) && PosedPosition is null) { return(base.AssignedPosition); } if (Assigned(ScenePosition)) { worldPosition[0] = ScenePosition.ElementAtOrNull(0) != null?CameraManager.Configuration.SceneToWorldSpace(new Vector2(ScenePosition[0] / 100f, 0)).x : default(float?); worldPosition[1] = ScenePosition.ElementAtOrNull(1) != null?CameraManager.Configuration.SceneToWorldSpace(new Vector2(0, ScenePosition[1] / 100f)).y : default(float?); worldPosition[2] = ScenePosition.ElementAtOrNull(2); } else { worldPosition = PosedPosition; } return(worldPosition); }
protected virtual async UniTask ApplyAppearanceModificationAsync(TActor actor, EasingType easingType, float duration, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(AssignedAppearance)) { return; } var transitionName = !string.IsNullOrEmpty(AssignedTransition) ? AssignedTransition : TransitionType.Crossfade; var defaultParams = TransitionUtils.GetDefaultParams(transitionName); var transitionParams = Assigned(TransitionParams) ? new Vector4( TransitionParams.ElementAtOrNull(0) ?? defaultParams.x, TransitionParams.ElementAtOrNull(1) ?? defaultParams.y, TransitionParams.ElementAtOrNull(2) ?? defaultParams.z, TransitionParams.ElementAtOrNull(3) ?? defaultParams.w) : defaultParams; if (Assigned(DissolveTexturePath) && !ObjectUtils.IsValid(preloadedDissolveTexture)) { preloadedDissolveTexture = Resources.Load <Texture2D>(DissolveTexturePath); } var transition = new Transition(transitionName, transitionParams, preloadedDissolveTexture); await actor.ChangeAppearanceAsync(AssignedAppearance, duration, easingType, transition, cancellationToken); }