Skip to content

Commit 46121ce

Browse files
committed
add: base scripts for test
1 parent 0a164cf commit 46121ce

60 files changed

Lines changed: 2678 additions & 1785 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Assets/Code/Infrastructure.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using Code.Infrastructure.Factory;
2+
using Code.Infrastructure.Services.PersistenceProgress;
3+
using Code.Infrastructure.Services.SaveLoad;
4+
using Code.Infrastructure.Services.StaticData;
5+
using Services.PersistenceProgress;
6+
using UnityEngine.SceneManagement;
7+
using Zenject;
8+
9+
namespace Code.Infrastructure
10+
{
11+
public class BootstrapInstaller : MonoInstaller, IInitializable
12+
{
13+
private const string SceneName = "Game";
14+
15+
public override void InstallBindings()
16+
{
17+
Container.BindInterfacesTo<BootstrapInstaller>().FromInstance(this).AsSingle();
18+
19+
BindFactory();
20+
BindSaveLoad();
21+
BindProgressData();
22+
BindStaticData();
23+
}
24+
25+
private void BindFactory()
26+
{
27+
Container.BindInterfacesTo<UIFactory>().AsSingle();
28+
}
29+
30+
private void BindSaveLoad()
31+
{
32+
Container.Bind<ISaveLoadService>().To<SaveLoadService>().AsSingle();
33+
}
34+
35+
private void BindProgressData() =>
36+
Container.Bind<IPersistenceProgressService>().To<PersistenceProgressService>().AsSingle();
37+
38+
39+
private void BindStaticData()
40+
{
41+
Container.Bind<IStaticDataService>().To<StaticDataService>().AsSingle();
42+
}
43+
44+
public void Initialize()
45+
{
46+
Container.Resolve<IStaticDataService>().LoadData();
47+
48+
SceneManager.LoadScene(SceneName);
49+
}
50+
}
51+
}

Assets/Code/Infrastructure/BootstrapInstaller.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Code/Infrastructure/Factory.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using UnityEngine;
2+
using UnityEngine.SceneManagement;
3+
using Zenject;
4+
5+
namespace Code.Infrastructure.Factory
6+
{
7+
public abstract class Factory
8+
{
9+
private readonly IInstantiator _instantiator;
10+
11+
protected Factory(IInstantiator instantiator)
12+
{
13+
_instantiator = instantiator;
14+
}
15+
16+
protected GameObject Instantiate(string resourcePath)
17+
{
18+
GameObject gameObject = _instantiator.InstantiatePrefabResource(resourcePath);
19+
return TryMoveToCurrentScene(gameObject);
20+
}
21+
22+
protected GameObject Instantiate(string resourcePath, Transform parent)
23+
{
24+
GameObject gameObject = _instantiator.InstantiatePrefabResource(resourcePath, parent);
25+
return TryMoveToCurrentScene(gameObject);
26+
}
27+
28+
protected GameObject Instantiate(string resourcePath, Vector3 position, Quaternion rotation, Transform parent)
29+
{
30+
GameObject gameObject = _instantiator.InstantiatePrefabResource(resourcePath, position, rotation, parent);
31+
return TryMoveToCurrentScene(gameObject);
32+
}
33+
34+
protected GameObject Instantiate(GameObject prefab)
35+
{
36+
GameObject gameObject = _instantiator.InstantiatePrefab(prefab);
37+
return TryMoveToCurrentScene(gameObject);
38+
}
39+
40+
protected GameObject Instantiate(GameObject prefab, Vector3 position, Quaternion rotation, Transform parent)
41+
{
42+
GameObject gameObject = _instantiator.InstantiatePrefab(prefab, position, rotation, parent);
43+
return TryMoveToCurrentScene(gameObject);
44+
}
45+
46+
protected GameObject Instantiate(GameObject prefab, Transform parent) =>
47+
_instantiator.InstantiatePrefab(prefab, parent);
48+
49+
private GameObject TryMoveToCurrentScene(GameObject gameObject)
50+
{
51+
if(gameObject.transform.parent == null)
52+
SceneManager.MoveGameObjectToScene(gameObject, SceneManager.GetActiveScene());
53+
54+
return gameObject;
55+
}
56+
}
57+
}

Assets/Code/Infrastructure/Factory/Factory.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using UnityEngine;
2+
3+
namespace Code.Infrastructure.Factory
4+
{
5+
public interface IUIFactory
6+
{
7+
Canvas UIRootCanvas { get; }
8+
Canvas GameHudCanvas { get; }
9+
void CreateUIRoot();
10+
void CreateGameHud();
11+
}
12+
}

Assets/Code/Infrastructure/Factory/IUIFactory.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using UnityEngine;
2+
using UnityEngine.SceneManagement;
3+
using Zenject;
4+
5+
namespace Code.Infrastructure.Factory
6+
{
7+
public class UIFactory : Factory, IUIFactory
8+
{
9+
private const string UiRootPath = "UI/UiRoot";
10+
private const string GameHudPath = "UI/GameHud";
11+
12+
public UIFactory(IInstantiator instantiator) : base(instantiator) { }
13+
14+
public Canvas UIRootCanvas { get; private set; }
15+
public Canvas GameHudCanvas { get; private set; }
16+
17+
public void CreateUIRoot()
18+
{
19+
var uiRoot = Instantiate(UiRootPath).transform;
20+
UIRootCanvas = uiRoot.GetComponent<Canvas>();
21+
}
22+
23+
public void CreateGameHud()
24+
{
25+
var gamehud = Instantiate(GameHudPath).transform;
26+
GameHudCanvas = gamehud.GetComponent<Canvas>();
27+
}
28+
}
29+
}

Assets/Code/Infrastructure/Factory/UIFactory.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)