Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/ControllersTreeSamples/Samples~/FruitsMerge.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/ControllersTreeSamples/Samples~/FruitsMerge/Core.meta

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)

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

{
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)
{

Choose a reason for hiding this comment

The 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.

8 changes: 8 additions & 0 deletions src/ControllersTreeSamples/Samples~/FruitsMerge/Features.meta

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.

Loading