init: add project

This commit is contained in:
Bragin Stepan
2026-02-18 23:02:28 +05:00
commit 4f01e66894
620 changed files with 52253 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 563a0a782ca553a499418c1443dac602
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9d1c3e39f1e449709c306eff4c557118
timeCreated: 1771180642

View File

@@ -0,0 +1,10 @@
using UnityEngine;
namespace Assets._Project.Develop.Runtime.Utilities.AssetsManagement
{
public class ResourcesAssetsLoader
{
public T Load<T>(string resourcePath) where T : Object
=> Resources.Load<T>(resourcePath);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c8bedbcabb66ab14aa69461716de6da4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5bddbfc76b347744eb8e51200dd00249
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,35 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
namespace Assets._Project.Develop.Runtime.Utilities.ConfigsManagement
{
public class ConfigsProviderService
{
private readonly Dictionary<Type, object> _configs = new();
private readonly IConfigsLoader[] _loaders;
public ConfigsProviderService(params IConfigsLoader[] loaders)
{
_loaders = loaders;
}
public IEnumerator LoadAsync()
{
_configs.Clear();
foreach (IConfigsLoader loader in _loaders)
yield return loader.LoadAsync(loadedConfigs => _configs.AddRange(loadedConfigs));
}
public T GetConfig<T>() where T : class
{
if (_configs.ContainsKey(typeof(T)) == false)
throw new InvalidOperationException($"Not found config by {typeof(T)}");
return (T)_configs[typeof(T)];
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 91110ad324dd6984a996ba9e842f00d1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace Assets._Project.Develop.Runtime.Utilities.ConfigsManagement
{
public interface IConfigsLoader
{
IEnumerator LoadAsync(Action<Dictionary<Type, object>> onConfigsLoaded);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3fdc549c53a2ce342b7735b0d0a1fd1b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,35 @@
using Assets._Project.Develop.Runtime.Utilities.AssetsManagement;
using System;
using System.Collections;
using System.Collections.Generic;
using Assets._Project.Develop.Runtime.Utilities.SceneManagement;
using UnityEngine;
namespace Assets._Project.Develop.Runtime.Utilities.ConfigsManagement
{
public class ResourcesConfigsLoader : IConfigsLoader
{
private readonly ResourcesAssetsLoader _resources;
private readonly Dictionary<Type, string> _configsResourcesPaths = new (PathToResources.ScriptableObject);
public ResourcesConfigsLoader(ResourcesAssetsLoader resources)
{
_resources = resources;
}
public IEnumerator LoadAsync(Action<Dictionary<Type, object>> onConfigsLoaded)
{
Dictionary<Type, object> loadedConfigs = new();
foreach (KeyValuePair<Type, string> configResourcesPath in _configsResourcesPaths)
{
ScriptableObject config = _resources.Load<ScriptableObject>(configResourcesPath.Value);
loadedConfigs.Add(configResourcesPath.Key, config);
yield return null;
}
onConfigsLoaded?.Invoke(loadedConfigs);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8a5f12d91469c594f9809cd92473593c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 17ff9c1885cc9e74f804cd44ecc95d5d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
using System.Collections;
using UnityEngine;
namespace Assets._Project.Develop.Runtime.Utilities.CoroutinesManagement
{
public class CoroutinesPerformer : MonoBehaviour, ICoroutinesPerformer
{
private void Awake()
{
DontDestroyOnLoad(this);
}
public Coroutine StartPerform(IEnumerator coroutineFunction)
=> StartCoroutine(coroutineFunction);
public void StopPerform(Coroutine coroutine)
=> StopCoroutine(coroutine);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 58469a3d4641ff54d80eef10f5c35e5f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
using System.Collections;
using UnityEngine;
namespace Assets._Project.Develop.Runtime.Utilities.CoroutinesManagement
{
public interface ICoroutinesPerformer
{
Coroutine StartPerform(IEnumerator coroutineFunction);
void StopPerform(Coroutine coroutine);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 94c0861811075594e91dd0115f09cfcf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 78c960bcc3c741f49e39144058ff0ce6
timeCreated: 1770821970

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7fcee5516f2549bfbbf7d525c6e60d84
timeCreated: 1770822079

View File

@@ -0,0 +1,10 @@
using System.Collections.Generic;
using _Project.Develop.Runtime.Logic.Meta.Features.Wallet;
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement
{
public class PlayerData : ISaveData
{
public Dictionary<CurrencyTypes, int> WalletData;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6fdb888a39a0dc548b3149ae88dcf261
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using _Project.Develop.Runtime.Configs.Meta;
using _Project.Develop.Runtime.Logic.Meta.Features.Wallet;
using Assets._Project.Develop.Runtime.Utilities.ConfigsManagement;
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement.DataProviders
{
public class PlayerDataProvider : DataProvider<PlayerData>
{
private readonly ConfigsProviderService _configsProviderService;
public PlayerDataProvider(
ISaveLoadService saveLoadService,
ConfigsProviderService configsProviderService) : base(saveLoadService)
{
_configsProviderService = configsProviderService;
}
protected override PlayerData GetOriginData()
{
return new PlayerData()
{
WalletData = InitWalletData(),
};
}
private Dictionary<CurrencyTypes, int> InitWalletData()
{
Dictionary<CurrencyTypes, int> data = new();
StartWalletConfigSO config = _configsProviderService.GetConfig<StartWalletConfigSO>();
foreach (CurrencyTypes type in Enum.GetValues(typeof(CurrencyTypes)))
data[type] = config.GetValueFor(type);
return data;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c8a9ea5d989647a4081ab2b6b076f1e8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,29 @@
using System.Collections;
using Assets._Project.Develop.Runtime.Utilities.DataManagement;
using Assets._Project.Develop.Runtime.Utilities.DataManagement.DataProviders;
using UnityEngine;
namespace _Project.Develop.Runtime.Utilities.DataManagement
{
public static class DataUtils
{
public static IEnumerator LoadProviderAsync<T>(DataProvider<T> data) where T : ISaveData
{
bool isDataSaveExists = false;
yield return data.ExistsAsync(result => isDataSaveExists = result);
if (isDataSaveExists)
{
yield return data.LoadAsync();
Debug.Log($"Data {typeof(T).Name} loaded");
}
else
{
data.Reset();
yield return data.SaveAsync();
Debug.Log($"Data {typeof(T).Name} created");
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1596051f07de4e36aab6dd2f1f0c8cd4
timeCreated: 1770825076

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b95729626d4a4da8b10a288862b4b647
timeCreated: 1770822430

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0dfabea6753040bb886e08bc12f31679
timeCreated: 1770822024

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bb5d55999e8cd9947b831a8be3baf413
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,77 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement.DataProviders
{
public abstract class DataProvider<TData> where TData : ISaveData
{
private readonly ISaveLoadService _saveLoadService;
private readonly List<IDataWriter<TData>> _writers = new();
private readonly List<IDataReader<TData>> _readers = new();
private TData _data;
protected DataProvider(ISaveLoadService saveLoadService)
{
_saveLoadService = saveLoadService;
}
public void RegisterWriter(IDataWriter<TData> writer)
{
if (_writers.Contains(writer))
throw new ArgumentException(nameof(writer));
_writers.Add(writer);
}
public void RegisterReader(IDataReader<TData> reader)
{
if (_readers.Contains(reader))
throw new ArgumentException(nameof(reader));
_readers.Add(reader);
}
public IEnumerator LoadAsync()
{
yield return _saveLoadService.Load<TData>(loadedData => _data = loadedData);
SendDataToReaders();
}
public IEnumerator SaveAsync()
{
UpdateDataFromWriters();
yield return _saveLoadService.Save(_data);
}
public IEnumerator ExistsAsync(Action<bool> onExistsResult)
{
yield return _saveLoadService.Exists<TData>(result => onExistsResult?.Invoke(result));
}
public void Reset()
{
_data = GetOriginData();
SendDataToReaders();
}
protected abstract TData GetOriginData();
private void SendDataToReaders()
{
foreach (IDataReader<TData> reader in _readers)
reader.ReadFrom(_data);
}
private void UpdateDataFromWriters()
{
foreach (IDataWriter<TData> writer in _writers)
writer.WriteTo(_data);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c6bf35dfa43cf024896bd6a93d0ef7d4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement.DataProviders
{
public interface IDataReader<TData> where TData : ISaveData
{
void ReadFrom(TData data);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5635fd8b8a4db3247a083a80b115ff1c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement.DataProviders
{
public interface IDataWriter<TData> where TData : ISaveData
{
void WriteTo(TData data);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0c199eaeb90195b46b7ef35e77d2fc98
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ee31fbd4ba77de44ab91963e139c0c0e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections;
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement.DataRepository
{
public interface IDataRepository
{
IEnumerator Read(string key, Action<string> onRead);
IEnumerator Write(string key, string serializedData);
IEnumerator Remove(string key);
IEnumerator Exists(string key, Action<bool> onExistsResult);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 44db3bd62a6844b438133918ce7520bd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,53 @@
using System;
using System.Collections;
using System.IO;
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement.DataRepository
{
public class LocalFileDataRepository : IDataRepository
{
private readonly string _folderPath;
private readonly string _saveFileExtension;
public LocalFileDataRepository(string folderPath, string saveFileExtension)
{
_folderPath = folderPath;
_saveFileExtension = saveFileExtension;
}
public IEnumerator Exists(string key, Action<bool> onExistsResult)
{
bool exists = File.Exists(FullPathFor(key));
onExistsResult?.Invoke(exists);
yield break;
}
public IEnumerator Read(string key, Action<string> onRead)
{
string text = File.ReadAllText(FullPathFor(key));
onRead?.Invoke(text);
yield break;
}
public IEnumerator Remove(string key)
{
File.Delete(FullPathFor(key));
yield break;
}
public IEnumerator Write(string key, string serializedData)
{
File.WriteAllText(FullPathFor(key), serializedData);
yield break;
}
private string FullPathFor(string key)
=> Path.Combine(_folderPath, key) + "." + _saveFileExtension;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1237330c119d323409a240bc05147dbb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections;
using UnityEngine;
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement.DataRepository
{
public class PlayerPrefsDataRepository : IDataRepository
{
public IEnumerator Exists(string key, Action<bool> onExistsResult)
{
bool exists = PlayerPrefs.HasKey(key);
onExistsResult?.Invoke(exists);
yield break;
}
public IEnumerator Read(string key, Action<string> onRead)
{
string text = PlayerPrefs.GetString(key);
onRead?.Invoke(text);
yield break;
}
public IEnumerator Remove(string key)
{
PlayerPrefs.DeleteKey(key);
yield break;
}
public IEnumerator Write(string key, string serializedData)
{
PlayerPrefs.SetString(key, serializedData);
yield break;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: adaa5e6dabd0ddc478a6c91a3f53645f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,6 @@
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement
{
public interface ISaveData
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 94f8ecdf9df3d1549ae149d55a4d6654
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections;
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement
{
public interface ISaveLoadService
{
IEnumerator Load<TData>(Action<TData> onLoad) where TData : ISaveData;
IEnumerator Save<TData>(TData data) where TData : ISaveData;
IEnumerator Remove<TData>() where TData : ISaveData;
IEnumerator Exists<TData>(Action<bool> onExistsResult) where TData : ISaveData;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 307c92b53612c4c41845657f42d815d1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6904ab4492a5aa242941e836a86fc46f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement.KeysStorage
{
public interface IDataKeysStorage
{
string GetKeyFor<TData>() where TData : ISaveData;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 10eac07c628f6fc47b2a2965442dedd6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using Assets._Project.Develop.Runtime.Utilities.SceneManagement;
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement.KeysStorage
{
public class MapDataKeysStorage : IDataKeysStorage
{
private readonly Dictionary<Type, string> Keys = new (MapDataKeys.Dictionary);
public string GetKeyFor<TData>() where TData : ISaveData => Keys[typeof(TData)];
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0ee6312a9f3693d4bbb60ffd58b21db7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2a7a36b7945f6484c9df1a4567fb9d67
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement.Serializers
{
public interface IDataSerializer
{
string Serialize<TData>(TData data);
TData Deserialize<TData>(string serializedData);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 68c37667edb0fba42ba8ea048933f424
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,24 @@
using Newtonsoft.Json;
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement.Serializers
{
public class JsonSerializer : IDataSerializer
{
public TData Deserialize<TData>(string serializedData)
{
return JsonConvert.DeserializeObject<TData>(serializedData, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto,
});
}
public string Serialize<TData>(TData data)
{
return JsonConvert.SerializeObject(data, new JsonSerializerSettings
{
Formatting = Formatting.Indented,
TypeNameHandling = TypeNameHandling.Auto,
});
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c2f381e1811dfe344a6c25d6d1205239
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,29 @@
using Assets._Project.Develop.Runtime.Utilities.DataManagement.DataRepository;
using Assets._Project.Develop.Runtime.Utilities.DataManagement.KeysStorage;
using Assets._Project.Develop.Runtime.Utilities.DataManagement.Serializers;
using UnityEngine;
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement
{
public class SaveLoadFactory
{
public SaveLoadService CreateDefaultSaveLoad()
{
IDataRepository dataRepository;
if(RuntimePlatform.WebGLPlayer == Application.platform)
{
dataRepository = new PlayerPrefsDataRepository();
}
else
{
string saveFolderPath =
$"{(Application.isEditor ? Application.dataPath : Application.persistentDataPath)}/Saves";
dataRepository = new LocalFileDataRepository(saveFolderPath, "json");
}
return new SaveLoadService(new JsonSerializer(), new MapDataKeysStorage(), dataRepository);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3890ea90607b48308fbb899dec13672b
timeCreated: 1770823825

View File

@@ -0,0 +1,59 @@
using System;
using System.Collections;
using Assets._Project.Develop.Runtime.Utilities.DataManagement.DataRepository;
using Assets._Project.Develop.Runtime.Utilities.DataManagement.KeysStorage;
using Assets._Project.Develop.Runtime.Utilities.DataManagement.Serializers;
namespace Assets._Project.Develop.Runtime.Utilities.DataManagement
{
public class SaveLoadService : ISaveLoadService
{
private readonly IDataSerializer _serializer;
private readonly IDataKeysStorage _keysStorage;
private readonly IDataRepository _repository;
public SaveLoadService(
IDataSerializer serializer,
IDataKeysStorage keysStorage,
IDataRepository repository)
{
_serializer = serializer;
_keysStorage = keysStorage;
_repository = repository;
}
public IEnumerator Exists<TData>(Action<bool> onExistsResult) where TData : ISaveData
{
string key = _keysStorage.GetKeyFor<TData>();
yield return _repository.Exists(key, result => onExistsResult?.Invoke(result));
}
public IEnumerator Load<TData>(Action<TData> onLoad) where TData : ISaveData
{
string key = _keysStorage.GetKeyFor<TData>();
string serializedData = "";
yield return _repository.Read(key, result => serializedData = result);
TData data = _serializer.Deserialize<TData>(serializedData);
onLoad?.Invoke(data);
}
public IEnumerator Remove<TData>() where TData : ISaveData
{
string key = _keysStorage.GetKeyFor<TData>();
yield return _repository.Remove(key);
}
public IEnumerator Save<TData>(TData data) where TData : ISaveData
{
string serializedData = _serializer.Serialize(data);
string key = _keysStorage.GetKeyFor<TData>();
yield return _repository.Write(key, serializedData);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6e65636005d26054dba538573f23a2b4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f03531ec1be8466f8e4dc6bff6bacff6
timeCreated: 1770396920

View File

@@ -0,0 +1,77 @@
using System;
using UnityEngine;
namespace _Project.Develop.Runtime.Utilities.InputManagement
{
public class DesktopPlayerInputService : IPlayerInputService
{
public event Action OnJump;
public event Action OnInteract;
public event Action OnPrevious;
public event Action OnNext;
private const string HorizontalAxisKey = "Horizontal";
private const string VerticalAxisKey = "Vertical";
private const KeyCode JumpKey = KeyCode.Space;
private const KeyCode InteractKey = KeyCode.F;
private const KeyCode PreviousKey = KeyCode.Q;
private const KeyCode NextKey = KeyCode.E;
public bool IsEnabled { get; set; } = true;
public Vector2 Move
{
get
{
if (IsEnabled == false)
return Vector2.zero;
return new Vector2(Input.GetAxisRaw(HorizontalAxisKey), Input.GetAxisRaw(VerticalAxisKey));
}
}
public void Enable() => IsEnabled = true;
public void Disable() => IsEnabled = false;
public void Update(float deltaTime)
{
if (IsEnabled == false)
return;
if (Input.GetKeyDown(JumpKey))
OnJump?.Invoke();
if (Input.GetKeyDown(InteractKey))
OnInteract?.Invoke();
if (Input.GetKeyDown(PreviousKey))
OnPrevious?.Invoke();
if (Input.GetKeyDown(NextKey))
OnNext?.Invoke();
}
public string GetKeyboardInput()
{
if (IsEnabled == false)
return null;
for (int i = 0; i <= 9; i++)
if (Input.GetKeyDown(KeyCode.Alpha0 + i))
return i.ToString();
for (int i = 0; i < 26; i++)
{
if (Input.GetKeyDown(KeyCode.A + i))
{
char letter = (char)('A' + i);
return letter.ToString();
}
}
return null;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6e89482289184f2b93a4ddf77af98da7
timeCreated: 1770397340

View File

@@ -0,0 +1,13 @@
namespace _Project.Develop.Runtime.Utilities.InputManagement
{
public interface IInput
{
bool IsEnabled { get; set; }
void Enable();
void Disable();
void Update(float deltaTime);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1d448be7d0ba4d988578d646da708c41
timeCreated: 1770397262

View File

@@ -0,0 +1,20 @@
using System;
using UnityEngine;
namespace _Project.Develop.Runtime.Utilities.InputManagement
{
public interface IPlayerInputService : IInput
{
event Action OnJump;
event Action OnInteract;
event Action OnPrevious;
event Action OnNext;
Vector2 Move { get; }
string GetKeyboardInput();
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: de8df9e58e214573bb1d44996dc62484
timeCreated: 1770396950

View File

@@ -0,0 +1,7 @@
namespace _Project.Develop.Runtime.Utilities.InputManagement
{
public interface IUIInputService : IInput
{
// всякие клики
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f60f1acd260a4846943950a6e6682a9b
timeCreated: 1770397255

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 30234528ef773b341a3efe6ca10f9f92
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
namespace Assets._Project.Develop.Runtime.Utilities.LoadingScreen
{
public interface ILoadingScreen
{
bool IsShown { get; }
void Show();
void Hide();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 94ae254a4c187de408c5edfea987d792
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
using UnityEngine;
namespace Assets._Project.Develop.Runtime.Utilities.LoadingScreen
{
public class StandardLoadingScreen : MonoBehaviour, ILoadingScreen
{
public bool IsShown => gameObject.activeSelf;
private void Awake()
{
Hide();
DontDestroyOnLoad(this);
}
public void Hide() => gameObject.SetActive(false);
public void Show() => gameObject.SetActive(true);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d099fb8b85a67de4292ff35469d7e2ac
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f0d9f732a75e4b3ea599a6bb69623c25
timeCreated: 1770824208

View File

@@ -0,0 +1,8 @@
namespace _Project.Develop.Runtime.Utils.RandomManagement
{
public interface IRandomService
{
int Range(int min, int max);
float Range(float min, float max);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d49b6f25c4f34db68e6fcdec5aa0db62
timeCreated: 1770824214

View File

@@ -0,0 +1,17 @@
using UnityEngine;
namespace _Project.Develop.Runtime.Utils.RandomManagement
{
public class RandomService : IRandomService
{
public int Range(int min, int max)
{
return Random.Range(min, max);
}
public float Range(float min, float max)
{
return Random.Range(min, max);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 92646652978e4facaf700e783c669062
timeCreated: 1770824214

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4e4b870cfc3548eea8b0541b9c5ce7aa
timeCreated: 1770822844

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 38f811842f4c4882aca9f3ce32f0ab0c
timeCreated: 1770231370

View File

@@ -0,0 +1,14 @@
using System;
namespace _Project.Develop.Runtime.Utils.ReactiveManagement.Event
{
public interface IReadOnlyEvent
{
IDisposable Subscribe(Action action);
}
public interface IReadOnlyEvent<T>
{
IDisposable Subscribe(Action<T> action);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 39a931a0bd494206bd9b8b1b4003a87e
timeCreated: 1770231417

View File

@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
namespace _Project.Develop.Runtime.Utils.ReactiveManagement.Event
{
public class ReactiveEvent<T> : IReadOnlyEvent<T>
{
private readonly List<Subscriber<T>> _subscribers = new();
private readonly List<Subscriber<T>> _toAdd = new();
private readonly List<Subscriber<T>> _toRemove = new();
public IDisposable Subscribe(Action<T> action)
{
Subscriber<T> subscriber = new Subscriber<T>(action, Remove);
_toAdd.Add(subscriber);
return subscriber;
}
private void Remove(Subscriber<T> subscriber) => _toRemove.Add(subscriber);
public void Invoke(T arg)
{
if (_toAdd.Count > 0)
{
_subscribers.AddRange(_toAdd);
_toAdd.Clear();
}
if (_toRemove.Count > 0)
{
foreach (Subscriber<T> subscriber in _toRemove)
_subscribers.Remove(subscriber);
_toRemove.Clear();
}
foreach (Subscriber<T> subscriber in _subscribers)
subscriber.Invoke(arg);
}
}
public class ReactiveEvent : IReadOnlyEvent
{
private readonly List<Subscriber> _subscribers = new();
private readonly List<Subscriber> _toAdd = new();
private readonly List<Subscriber> _toRemove = new();
public IDisposable Subscribe(Action action)
{
Subscriber subscriber = new Subscriber(action, Remove);
_toAdd.Add(subscriber);
return subscriber;
}
private void Remove(Subscriber subscriber) => _toRemove.Add(subscriber);
public void Invoke()
{
if (_toAdd.Count > 0)
{
_subscribers.AddRange(_toAdd);
_toAdd.Clear();
}
if (_toRemove.Count > 0)
{
foreach (Subscriber subscriber in _toRemove)
_subscribers.Remove(subscriber);
_toRemove.Clear();
}
foreach (Subscriber subscriber in _subscribers)
subscriber.Invoke();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3e72d59ed75643f287ae8c5fe58ce025
timeCreated: 1770231387

View File

@@ -0,0 +1,52 @@
using System;
namespace _Project.Develop.Runtime.Utils.ReactiveManagement
{
public class Subscriber : IDisposable
{
private Action _action;
private Action<Subscriber> _onDispose;
public Subscriber(Action action, Action<Subscriber> onDispose)
{
_action = action;
_onDispose = onDispose;
}
public void Dispose() => _onDispose?.Invoke(this);
public void Invoke() => _action?.Invoke();
}
public class Subscriber<T> : IDisposable
{
private Action<T> _action;
private Action<Subscriber<T>> _onDispose;
public Subscriber(Action<T> action, Action<Subscriber<T>> onDispose)
{
_action = action;
_onDispose = onDispose;
}
public void Dispose() => _onDispose?.Invoke(this);
public void Invoke(T arg1) => _action?.Invoke(arg1);
}
public class Subscriber<T, K> : IDisposable
{
private Action<T, K> _action;
private Action<Subscriber<T, K>> _onDispose;
public Subscriber(Action<T, K> action, Action<Subscriber<T, K>> onDispose)
{
_action = action;
_onDispose = onDispose;
}
public void Dispose() => _onDispose?.Invoke(this);
public void Invoke(T arg1, K arg2) => _action?.Invoke(arg1, arg2);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c87e6c3df4794e418c2060eee1af2d14
timeCreated: 1769098141

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f7c50257552f4cc693958eeda0f41c3d
timeCreated: 1769097237

View File

@@ -0,0 +1,11 @@
using System;
namespace _Project.Develop.Runtime.Utils.ReactiveManagement
{
public interface IReadOnlyVariable<T>
{
T Value { get; }
IDisposable Subscribe(Action<T, T> action);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: abc67e68747846d3aaf1474b04c77c1b
timeCreated: 1769096939

View File

@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
namespace _Project.Develop.Runtime.Utils.ReactiveManagement
{
public class ReactiveVariable<T> : IReadOnlyVariable<T> where T : IEquatable<T>
{
private readonly List<Subscriber<T, T>> _subscribers = new ();
private readonly List<Subscriber<T, T>> _toAddList = new ();
private readonly List<Subscriber<T, T>> _toRemoveList = new ();
public ReactiveVariable() => _value = default(T);
public ReactiveVariable(T value) => _value = value;
private T _value;
public T Value
{
get => _value;
set
{
T oldValue = _value;
_value = value;
if (_value.Equals(oldValue) == false)
Invoke(oldValue, _value);
}
}
public IDisposable Subscribe(Action<T, T> action)
{
Subscriber<T, T> subscriber = new (action, RemoveSubscriber);
_toAddList.Add(subscriber);
return subscriber;
}
private void RemoveSubscriber(Subscriber<T, T> subscriber) => _toRemoveList.Add(subscriber);
private void Invoke(T oldValue, T newValue)
{
if(_toAddList.Count > 0)
{
_subscribers.AddRange(_toAddList);
_toAddList.Clear();
}
if(_toRemoveList.Count > 0)
{
foreach (Subscriber<T, T> subscriber in _toRemoveList)
_subscribers.Remove(subscriber);
_toRemoveList.Clear();
}
foreach (Subscriber<T, T> subscriber in _subscribers)
subscriber.Invoke(oldValue, newValue);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 97e9e838b860437cabd97a319c2b6598
timeCreated: 1769096939

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 88393e1296488c749a3c128a1f2d732c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,6 @@
namespace Assets._Project.Develop.Runtime.Utilities.SceneManagement
{
public interface IInputSceneArgs
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cbe85b26d7f0422449ab0fb3f0443455
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Assets._Project.Develop.Runtime.Utilities.SceneManagement
{
public class SceneLoaderService
{
public IEnumerator LoadAsync(string sceneName, LoadSceneMode loadSceneMode = LoadSceneMode.Single)
{
AsyncOperation wait = SceneManager.LoadSceneAsync(sceneName, loadSceneMode);
yield return new WaitWhile(() => wait.isDone == false);
}
public IEnumerator UnloadAsync(string sceneName)
{
AsyncOperation wait = SceneManager.UnloadSceneAsync(sceneName);
yield return new WaitWhile(() => wait.isDone == false);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b5b398e252187d742ab651dfb1906f35
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,56 @@
using Assets._Project.Develop.Runtime.Infrastructure;
using Assets._Project.Develop.Runtime.Infrastructure.DI;
using Assets._Project.Develop.Runtime.Utilities.LoadingScreen;
using System;
using System.Collections;
using UnityEngine;
using Object = UnityEngine.Object;
namespace Assets._Project.Develop.Runtime.Utilities.SceneManagement
{
public class SceneSwitcherService
{
private readonly SceneLoaderService _sceneLoaderService;
private readonly ILoadingScreen _loadingScreen;
private readonly DIContainer _projectContainer;
private DIContainer _currentSceneContainer;
public SceneSwitcherService(
SceneLoaderService sceneLoaderService,
ILoadingScreen loadingScreen,
DIContainer projectContainer)
{
_sceneLoaderService = sceneLoaderService;
_loadingScreen = loadingScreen;
_projectContainer = projectContainer;
}
public IEnumerator ProcessSwitchTo(string sceneName, IInputSceneArgs sceneArgs = null)
{
_loadingScreen.Show();
_currentSceneContainer?.Dispose();
yield return _sceneLoaderService.LoadAsync(Scenes.Empty);
yield return _sceneLoaderService.LoadAsync(sceneName);
SceneBootstrap sceneBootstrap = Object.FindObjectOfType<SceneBootstrap>();
if (sceneBootstrap == null)
throw new NullReferenceException(nameof(sceneBootstrap) + " not found");
_currentSceneContainer = new DIContainer(_projectContainer);
sceneBootstrap.ProcessRegistrations(_currentSceneContainer, sceneArgs);
_currentSceneContainer.Initialize();
yield return sceneBootstrap.Initialize();
_loadingScreen.Hide();
sceneBootstrap.Run();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b42893fbf47ad02419f5a38341c5ddc6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: eed778ab855746659da5f168f68746c6
timeCreated: 1770381069

View File

@@ -0,0 +1,11 @@
using System;
namespace _Project.Develop.Runtime.Utilities.StateMachine
{
public interface IStateChanger
{
event Action<State> Changed;
StateMachine ChangeState<TState>() where TState : State;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8b705c6047e545c483833a0fe80a6850
timeCreated: 1770390018

Some files were not shown because too many files have changed in this diff Show More