-
Notifications
You must be signed in to change notification settings - Fork 11
Sample FruitsMerge #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| using System; | ||
| using System.Threading; | ||
| using VContainer; | ||
| using VContainer.Unity; | ||
|
|
||
| namespace ControllersTree.Samples.FruitsMerge | ||
| { | ||
| /// <summary> | ||
| /// Bootstrap manages the application startup and shutdown. | ||
| /// It utilizes dependency injection with IObjectResolver and BootstrapController to initialize and control the application flow. | ||
| /// The Start() method launches the bootstrap process, handling exceptions and cancellation, | ||
| /// while Dispose() ensures proper cleanup by cancelling ongoing operations and releasing associated resources. | ||
| /// </summary> | ||
| public class Bootstrap : IStartable, IDisposable | ||
| { | ||
| private readonly BootstrapController _bootstrapController; | ||
|
|
||
| private CancellationTokenSource _cancellationTokenSource = new(); | ||
|
|
||
| public Bootstrap(BootstrapController bootstrapController) | ||
| { | ||
| _bootstrapController = bootstrapController; | ||
| } | ||
|
|
||
| public void Start() | ||
| { | ||
| try | ||
| { | ||
| _bootstrapController.LaunchTree(_cancellationTokenSource.Token); | ||
| } | ||
| catch (OperationCanceledException) | ||
| { | ||
| } | ||
| catch (Exception exception) | ||
| { | ||
| UnityEngine.Debug.LogError($"Can't start bootstrap controller {exception}"); | ||
| } | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| _cancellationTokenSource?.Cancel(); | ||
| _cancellationTokenSource?.Dispose(); | ||
|
|
||
| _cancellationTokenSource = null; | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| using Cysharp.Threading.Tasks; | ||
| using Playtika.Controllers; | ||
|
|
||
| namespace ControllersTree.Samples.FruitsMerge | ||
| { | ||
| /// <summary> | ||
| /// BootstrapController extends RootController to manage the initialization flow of the application. | ||
| /// It asynchronously starts a game loop by repeatedly executing GameLoopController instances until cancellation is requested. | ||
| /// </summary> | ||
| public class BootstrapController : RootController | ||
| { | ||
| public BootstrapController(IControllerFactory controllerFactory) | ||
| : base(controllerFactory) | ||
| { | ||
| } | ||
|
|
||
| protected override void OnStart() | ||
| { | ||
| FlowAsync().Forget(); | ||
|
|
||
| base.OnStart(); | ||
| } | ||
|
|
||
| private async UniTask FlowAsync() | ||
| { | ||
| while (!CancellationToken.IsCancellationRequested) | ||
| { | ||
| await ExecuteAndWaitResultAsync<GameLoopController>(CancellationToken); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| using Playtika.Controllers; | ||
| using VContainer; | ||
|
|
||
| namespace ControllersTree.Samples.FruitsMerge | ||
| { | ||
| /// <summary> | ||
| /// The ControllerFactory class implements the IControllerFactory interface to facilitate the creation | ||
| /// of controllers using a project-specific Dependency Injection (DI) container. | ||
| /// It utilizes an IObjectResolver instance to resolve and instantiate controllers of type T | ||
| /// that implement theIController interface. | ||
| /// </summary> | ||
| public class ControllerFactory : IControllerFactory | ||
| { | ||
| private readonly IObjectResolver _container; | ||
|
|
||
| public ControllerFactory(IObjectResolver container) | ||
| { | ||
| _container = container; | ||
| } | ||
|
|
||
| public IController Create<T>() where T : class, IController | ||
| { | ||
| var controller = _container.Resolve<T>(); | ||
| return controller; | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| using System.Threading; | ||
| using Cysharp.Threading.Tasks; | ||
| using UnityEngine; | ||
|
|
||
| namespace ControllersTree.Samples.FruitsMerge | ||
| { | ||
| /// <summary> | ||
| /// AnimationExtensions is a static class providing extension methods for Unity's Animation class. | ||
| /// </summary> | ||
| public static class AnimationExtensions | ||
| { | ||
| public static async UniTask PlayAsync( | ||
| this Animation animationComponent, | ||
| string animationName, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| animationComponent.Play(animationName); | ||
|
|
||
| while (animationComponent.isPlaying) | ||
| { | ||
| await UniTask.Yield(); | ||
| if (cancellationToken.IsCancellationRequested) | ||
| { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider throwing an operation cancelled exception simply passing CT into yield |
||
| return; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| using UnityEngine; | ||
|
|
||
| namespace ControllersTree.Samples.FruitsMerge | ||
| { | ||
| /// <summary> | ||
| /// TransformExtensions is a static class providing extension methods for Unity's Transform class. | ||
| /// </summary> | ||
| public static class TransformExtensions | ||
| { | ||
| public static void Clear(this Transform transform) | ||
| { | ||
| foreach (Transform child in transform) | ||
| { | ||
| Object.Destroy(child.gameObject); | ||
| } | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to pass a cancellation token as a parameter