This commit is contained in:
xrust1k committed 2025-11-28 10:43:47 +03:00
commit 13aca5a86f
90 files changed
+9595 -88

No files matched your search

@@ -8,6 +8,7 @@ using Code.Gameplay.Camera;
using Code.Gameplay.Enemies;
using Code.Gameplay.Orders.Order;
using Code.Gameplay.Player;
using Code.Generator;
using Code.Input;
using Code.Scenes;
using Code.StaticData;
@@ -102,6 +103,8 @@ namespace Code.App
containerBuilder.AddSingleton(staticDataService.OrderServiceConfig, typeof(OrderServiceConfig));
containerBuilder.AddSingleton(staticDataService.OrderBoxConfig, typeof(OrderBoxConfig));
containerBuilder.AddSingleton(staticDataService.GeneratorConfig, typeof(GeneratorConfig));
}
private AppStateMachine _appStateMachine;
@@ -1,8 +1,10 @@
using Code.App.Loading;
using Code.Gameplay.Orders.Order;
using Code.Gameplay.Player;
using Code.Generator;
using Code.Scenes;
using Code.Scenes.SceneEnvironments;
using Cysharp.Threading.Tasks;
using Reflex.Core;
using UnityEngine;
using IPlayerScore = Code.Gameplay.Player.IPlayerScore;
@@ -18,6 +20,8 @@ namespace Code.App.SceneInstallers
containerBuilder.AddScoped(typeof(GameplaySceneEnvironment), typeof(CurrentSceneEnvironment));
containerBuilder.AddScoped(typeof(PlayerScore), typeof(IPlayerScore));
containerBuilder.AddScoped(typeof(OrderService), typeof(IOrderService));
containerBuilder.AddScoped(typeof(RoomGeneratorFactory), typeof(IRoomGeneratorFactory));
containerBuilder.AddScoped(typeof(RoomGenerator));
containerBuilder.OnContainerBuilt += Initialize;
}
@@ -32,6 +36,17 @@ namespace Code.App.SceneInstallers
loadingManager
.UnregisterLoading(LoadingWork.LoadScene);
LoadRooms(container,loadingManager);
}
private async UniTaskVoid LoadRooms(Container container, ILoadingManager loadingManager)
{
await container.Resolve<IRoomGeneratorFactory>().PreloadRooms(container.Resolve<IOrderService>());
container.Resolve<RoomGenerator>().Initialize();
loadingManager.UnregisterLoading(LoadingWork.LoadModelResource);
}
}
}
@@ -3,6 +3,7 @@ using Code.Audio;
using Code.Gameplay.Camera;
using Code.Gameplay.Enemies;
using Code.Gameplay.Player;
using Code.Generator;
using Code.Input;
using Code.Scenes;
using Code.UI;
@@ -22,6 +23,6 @@ namespace Code.App.StateMachine
[Inject] public IPlayerProvider PlayerProvider { get; private set; }
[Inject] public IAudioFactory AudioFactory { get; private set; }
[Inject] public IAudioService AudioService { get; private set; }
[Inject] public IEnemyFactory EnemyFactory { get; private set; }
[Inject] public IEnemyFactory EnemyFactory { get; private set; }
}
}
@@ -0,0 +1,23 @@
using UnityEngine;
namespace Code.Gameplay.Door
{
public class Door : MonoBehaviour
{
[SerializeField] private Transform hingeJointAnchor;
[SerializeField] private HingeJoint hingeJoint;
[SerializeField] private Rigidbody rigidbody;
public void TranslationMode(bool on)
{
if (on)
{
rigidbody.isKinematic = true;
return;
}
rigidbody.isKinematic = false;
hingeJoint.autoConfigureConnectedAnchor = false;
hingeJoint.connectedAnchor = hingeJointAnchor.position;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bc9fc6ce2cc24b68b2b330e4fd029b80
timeCreated: 1764304430
@@ -33,7 +33,7 @@ namespace Code.Gameplay.Orders.Order
}
public void OnTriggerEnter(Collider other)
{
if (!_pickupMode) return;
if (!_pickupMode || !other.CompareTag("Player")) return;
_orderService.OrderRecieved();
Destroy(gameObject);
@@ -14,18 +14,20 @@ namespace Code.Gameplay.Orders.Order
hatch.DORotate(new Vector3(-130f, 0, 0), 0.2f);
order.rigidbody.isKinematic = false;
order.rigidbody.AddForce(-transform.forward * 10f, ForceMode.Impulse);
order.rigidbody.AddForce(-transform.forward * 1f, ForceMode.Impulse);
order.SwitchMode();
}
// DEBUG TODO ДИМКА УДАЛИ И ПРОПИШИ В СВОЕЙ ЛОГИКЕ
public void OnTriggerEnter(Collider other)
{
if(_activated) return;
_activated = true;
ThrowOrder();
order.SwitchMode();
}
// public void OnTriggerEnter(Collider other)
// {
// if(_activated) return;
// _activated = true;
//
// ThrowOrder();
// order.SwitchMode();
// }
// DEBUG
}
}
@@ -0,0 +1,17 @@
using UnityEngine;
namespace Code.Gameplay.Orders.Order
{
public class RoomDispenserTrigger : MonoBehaviour
{
[SerializeField] private OrderDispenser orderDispenser;
private bool _playerEntered;
private void OnTriggerEnter(Collider other)
{
if (_playerEntered || !other.CompareTag("Player")) return;
orderDispenser.ThrowOrder();
_playerEntered = true;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 630780fe69aa45eda7d4bcf966516c7d
timeCreated: 1764313014
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b32d6ce440f44fd3abadaa489a44890c
timeCreated: 1762797763
@@ -0,0 +1,11 @@
using UnityEngine;
using UnityEngine.AddressableAssets;
namespace Code.Generator
{
[CreateAssetMenu(menuName = "Config/GeneratorConfig", fileName = "GeneratorConfig")]
public class GeneratorConfig : ScriptableObject
{
public AssetReference[] roomAssetReferences;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1a7c77305de54155b5b94b607531ee3c
timeCreated: 1762453750
@@ -0,0 +1,16 @@
using Code.Gameplay.Orders.Order;
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace Code.Generator
{
public interface IRoomGeneratorFactory
{
UniTask PreloadRooms(IOrderService orderService);
GameObject GetCachedPrefab(int index, RoomType roomType);
Room CreateRoomByIndex(int index, RoomType roomType);
void ReleaseRooms();
GameObject GetRandomCachedPrefabOfType(RoomType roomType, out int index);
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f3fca4115e714519b869eb72d856e89f
timeCreated: 1762453657
@@ -0,0 +1,33 @@
using System;
using Code.Gameplay.Door;
using Code.UI;
using UnityEngine;
namespace Code.Generator
{
[RequireComponent(typeof(Transform))]
public class Room : MonoBehaviour
{
[SerializeField] private RoomType roomType;
public RoomType RoomType => roomType;
[SerializeField] private float roomTimer;
public float RoomTimer => roomTimer;
[SerializeField] private Transform enterMarker;
public Transform EnterMarker => enterMarker;
[SerializeField] private Transform exitMarker;
public Transform ExitMarker => exitMarker;
[SerializeField] private Door door;
private void Awake()
{
if (EnterMarker == null || ExitMarker == null)
{
Debug.LogError($"Але маркеры не найдены у комнаты {gameObject.name}");
}
}
public void Initialize() => door.TranslationMode(false);
//PIZDEC
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5ba1a19c534f4401aa287d4b68ce470c
timeCreated: 1762014278
@@ -0,0 +1,308 @@
using System.Collections.Generic;
using Code.Gameplay.Orders.Order;
using Cysharp.Threading.Tasks;
using Reflex.Attributes;
using UnityEngine;
namespace Code.Generator
{
public class RoomGenerator
{
[Inject] private IOrderService _orderService;
[Inject] private GeneratorConfig generatorConfig;
[Inject] private IRoomGeneratorFactory _factory;
private List<RoomIndex> _roomIndexesStack;
private struct RoomIndex
{
public RoomType RoomType;
public int Index;
public RoomIndex(RoomType roomType, int index)
{
RoomType = roomType;
Index = index;
}
}
private List<Room> _spawnedRooms;
private int _nextRoomStackIndex;
public void Initialize()
{
// _orderService.OrderGive();
_spawnedRooms = new List<Room>();
_roomIndexesStack = new();
Debug.LogWarning($"КОТЛЫ ГЕНЕРАЛЬСКИЕ{_orderService.DeliveryTimer}");
// CreateRoomsStack();
// SpawnInitialRoomsAsync();
_orderService.OnOrderGiven += CreateRoomsStack;
RoomTrigger.PlayerEnteredRoom += OnPlayerEntered;
CreateSaveRoom();
SpawnNextRoomAsync();
}
private void OnEnable()
{
RoomTrigger.PlayerEnteredRoom += OnPlayerEntered;
}
private void OnDisable()
{
RoomTrigger.PlayerEnteredRoom -= OnPlayerEntered;
}
public void OnPlayerEntered()
{
SpawnNextRoomAsync();
if (_spawnedRooms.Count > 3)
{
Room roomToRemove = _spawnedRooms[0];
_spawnedRooms.RemoveAt(0);
// _factory.ReleaseRoom(roomToRemove);
Object.Destroy(roomToRemove.gameObject);
}
}
private void CreateRoomsStack(float timer)
{
var currentSaveRoom = _roomIndexesStack[^1];
_roomIndexesStack.Clear();
_roomIndexesStack.Add(currentSaveRoom);
var remainingTime = timer;
while (remainingTime > 0)
{
var prefab = _factory.GetRandomCachedPrefabOfType(RoomType.Basic, out int roomIndex);
Room room = prefab.GetComponent<Room>();
_roomIndexesStack.Add(new(RoomType.Basic, roomIndex));
remainingTime -= room.RoomTimer;
Debug.Log($"комната {room.name} время {room.RoomTimer} осталось: {remainingTime}");
}
AddPickupRoom();
CreateSaveRoom();
Debug.Log($"стек комнат: {_roomIndexesStack.Count}");
}
private void CreateSaveRoom()
{
var prefab = _factory.GetRandomCachedPrefabOfType(RoomType.Save, out int roomIndex);
Room saveRoom = prefab.GetComponent<Room>();
_roomIndexesStack.Add(new(RoomType.Save, roomIndex));
Debug.Log($"Первая комната: {saveRoom.name}");
}
private async UniTask SpawnInitialRoomsAsync()
{
_nextRoomStackIndex = 0;
SpawnNextRoomAsync();
SpawnNextRoomAsync();
}
private void SpawnNextRoomAsync()
{
if (_nextRoomStackIndex >= _roomIndexesStack.Count)
return;
RoomIndex index = _roomIndexesStack[_nextRoomStackIndex];
Room room = _factory.CreateRoomByIndex(index.Index, index.RoomType);
if (_spawnedRooms.Count == 0)
{
room.transform.position = Vector3.zero;
room.transform.rotation = Quaternion.identity;
}
else
{
Room previousRoom = _spawnedRooms[_spawnedRooms.Count - 1];
PlaceRoom(room, previousRoom);
}
_spawnedRooms.Add(room);
_nextRoomStackIndex++;
}
private void AddPickupRoom()
{
var prefab = _factory.GetRandomCachedPrefabOfType(RoomType.PickUp, out int pickupIndex);
Room pickupRoom = prefab.GetComponent<Room>();
if (_roomIndexesStack.Count == 0)
{
Debug.LogWarning("Стек пуст, нет позиции после первой");
return;
}
int insertPos = Random.Range(1, _roomIndexesStack.Count + 1);
_roomIndexesStack.Insert(insertPos, new(RoomType.PickUp, pickupIndex));
Debug.Log($"PickUp комната '{pickupRoom.name}' позиция {insertPos}");
}
private void PlaceRoom(Room current, Room previous)
{
if (current.EnterMarker == null || previous.ExitMarker == null)
return;
Vector3 segmentOriginPosition = previous.ExitMarker.transform.position;
Transform randomDoorOrigin = current.EnterMarker;
Vector3 randomDoorOriginPosition = randomDoorOrigin.localPosition * current.transform.localScale.x;
Quaternion randomDoorOriginRotation = randomDoorOrigin.localRotation;
float segmentOriginYRotation;
float entityRotation = previous.ExitMarker.transform.rotation.eulerAngles.y;
if (entityRotation > 305f) entityRotation -= 360f;
else if (entityRotation < -45f) entityRotation += 360f;
if (entityRotation > 135f)
segmentOriginYRotation = entityRotation - randomDoorOriginRotation.eulerAngles.y + 180f;
else
segmentOriginYRotation = entityRotation - randomDoorOriginRotation.eulerAngles.y - 180f;
if (segmentOriginYRotation < -45f) segmentOriginYRotation += 360f;
else if (segmentOriginYRotation > 305f) segmentOriginYRotation -= 360f;
else if (segmentOriginYRotation < -305f) segmentOriginYRotation += 720f;
if (segmentOriginYRotation is > -45f and < 45f)
{
segmentOriginPosition.x -= randomDoorOriginPosition.x;
segmentOriginPosition.z -= randomDoorOriginPosition.z;
}
else if (segmentOriginYRotation is >= 45f and < 135f)
{
segmentOriginPosition.x -= randomDoorOriginPosition.z;
segmentOriginPosition.z += randomDoorOriginPosition.x;
}
else if (segmentOriginYRotation is >= 135f and < 225f)
{
segmentOriginPosition.x += randomDoorOriginPosition.x;
segmentOriginPosition.z += randomDoorOriginPosition.z;
}
else if (segmentOriginYRotation is >= 225f and < 305f)
{
segmentOriginPosition.x += randomDoorOriginPosition.z;
segmentOriginPosition.z -= randomDoorOriginPosition.x;
}
segmentOriginPosition.y -= randomDoorOriginPosition.y;
current.transform.position = segmentOriginPosition;
current.transform.rotation = Quaternion.Euler(0, segmentOriginYRotation, 0);
// locationSegment.isNeedSomeDoors = true;
// locationSegment.AddBadDoorId(locationSegment.LocationSegment.GetDoorOrigins.IndexOf(randomDoorOrigin));
current.Initialize();
float frameOnTheBallRotation = segmentOriginYRotation + randomDoorOriginRotation.eulerAngles.y;
if (frameOnTheBallRotation > 305f) frameOnTheBallRotation -= 360f;
else if (frameOnTheBallRotation < -45f) frameOnTheBallRotation += 360f;
// heOnTheBall.AddSlaveLocationSegment(locationSegment.Id);
// heOnTheBall.ReplaceSlaveSegmentDoorOriginYRotation(frameOnTheBallRotation);
// heOnTheBall.isGotOnTheBall = false;
}
}
}
// private void CreateRoomsStackDimka()
// {
// _roomIndexesStack.Clear();
// var remainingTime = _orderService.DeliveryTimer;
// float ladderTimer = 0f;
// int totalRooms = generatorConfig.roomAssetReferences.Length;
// List<int> availableIndexes = new List<int>();
// for (int i = 0; i < totalRooms; i++)
// availableIndexes.Add(i);
//
// int saveIndex = FindRoomIndexByType(RoomType.Save);
// if (saveIndex != -1)
// {
// var prefab = _factory.GetCachedPrefab(saveIndex);
// if (prefab != null)
// {
// Room saveRoom = prefab.GetComponent<Room>();
// if (saveRoom != null)
// {
// _roomIndexesStack.Add(saveIndex);
// availableIndexes.Remove(saveIndex);
//
// Debug.Log($"Первая комната: {saveRoom.name}");
// }
// }
// }
//
// while (remainingTime > 0 && availableIndexes.Count > 0)
// {
// int randomIndex = Random.Range(0, availableIndexes.Count);
// int chosenOne = availableIndexes[randomIndex];
//
// var prefab = _factory.GetCachedPrefab(chosenOne);
// if (prefab == null)
// continue;
//
// Room room = prefab.GetComponent<Room>();
// if (room == null)
// continue;
//
// switch (room.RoomType)
// {
// case RoomType.Save or RoomType.PickUp:
// availableIndexes.RemoveAt(randomIndex);
// continue;
//
// case RoomType.Basic:
// float currentRoomTime = room.RoomTimer;
// if (remainingTime >= currentRoomTime && ladderTimer < 30f)
// {
// _roomIndexesStack.Add(chosenOne);
// remainingTime -= currentRoomTime;
// ladderTimer += currentRoomTime;
// Debug.Log($"комната {room.name} время {currentRoomTime} осталось: {remainingTime}");
// }
//
// availableIndexes.RemoveAt(randomIndex);
// break;
//
// case RoomType.Ladder:
// if (ladderTimer >= 30f)
// {
// _roomIndexesStack.Add(chosenOne);
// ladderTimer = 0f;
//
// availableIndexes.RemoveAt(randomIndex);
// Debug.Log($"Лестница ура {room.name}");
// }
//
// break;
//
// default:
// Debug.Log($"тип комнаты {room.RoomType}");
// availableIndexes.RemoveAt(randomIndex);
// break;
// }
// }
//
// AddPickupRoom();
// Debug.Log($"стек комнат: {_roomIndexesStack.Count}");
// }
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 353230beca35458dafc91c6409c25ab3
timeCreated: 1762014615
@@ -0,0 +1,72 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Code.Configs;
using Code.Gameplay.Orders.Order;
using Cysharp.Threading.Tasks;
using Reflex.Extensions;
using Reflex.Injectors;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.SceneManagement;
using Object = System.Object;
using Random = UnityEngine.Random;
namespace Code.Generator
{
public class RoomGeneratorFactory : IRoomGeneratorFactory
{
private AsyncOperationHandle<IList<GameObject>> _roomsHandle;
private readonly AssetReference[] _roomAssetReferences;
private Dictionary<RoomType, List<GameObject>> _cashedRooms = new();
public RoomGeneratorFactory(GeneratorConfig generatorConfig)
{
_roomAssetReferences = generatorConfig.roomAssetReferences;
// _cashedRooms = new GameObject[_roomAssetReferences.Length];
_cashedRooms.Add(RoomType.Basic, new());
_cashedRooms.Add(RoomType.Save, new ());
_cashedRooms.Add(RoomType.PickUp, new ());
}
public async UniTask PreloadRooms(IOrderService orderService)
{
_roomsHandle =
Addressables.LoadAssetsAsync<GameObject>(_roomAssetReferences, OnRoomLoaded, Addressables.MergeMode.Union);
await _roomsHandle.ToUniTask();
// _cashedRooms = rooms.ToArray(); var rooms =
// Debug.Log($"Комнат в памяти есть: {_cashedRooms.Length}");
}
private void OnRoomLoaded(GameObject room)
{
var temp = room.GetComponent<Room>();
_cashedRooms[temp.RoomType].Add(room);
}
public GameObject GetCachedPrefab(int index, RoomType roomType)
{
if (index < 0 || index >= _cashedRooms[roomType].Count)
return null;
return _cashedRooms[roomType][index];
}
public GameObject GetRandomCachedPrefabOfType(RoomType roomType, out int index)
{
index = Random.Range(0, _cashedRooms[roomType].Count);
return _cashedRooms[roomType][index];
}
public Room CreateRoomByIndex(int index, RoomType roomType)
{
var room = UnityEngine.Object.Instantiate(_cashedRooms[roomType][index]);
return room.GetComponent<Room>();
}
public void ReleaseRooms()
{
_roomsHandle.Release();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d6e5b72284354ba79ec5b89cf06f1203
timeCreated: 1762454256
@@ -0,0 +1,33 @@
using System;
using Code.Gameplay.Orders.Order;
using Reflex.Attributes;
using UnityEngine;
namespace Code.Generator
{
public class RoomTrigger : MonoBehaviour
{
[Inject] private IOrderService _orderService;
public static event Action PlayerEnteredRoom;
private bool _playerEntered;
// [Inject]
// private void Construct(IOrderService orderService)
// {
// _orderService = orderService;
// }
private void OnTriggerEnter(Collider other)
{
if (_playerEntered) return;
if (!other.CompareTag("Player")) return;
_playerEntered = true;
_orderService.RoomPassed();
PlayerEnteredRoom?.Invoke();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4207b7568dc3482393ac1860a31909b4
timeCreated: 1764087485
@@ -0,0 +1,10 @@
namespace Code.Generator
{
public enum RoomType
{
Basic,
Ladder,
Save,
PickUp
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 304fa5ed27cc4bc3aabcfeb272206d89
timeCreated: 1762945420
@@ -4,6 +4,7 @@ using System.Threading.Tasks;
using Code.Audio;
using Code.Configs;
using Code.Gameplay.Camera;
using Code.Generator;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.AddressableAssets;
@@ -31,6 +32,7 @@ namespace Code.StaticData
Dictionary<CameraMode, CameraSettingsConfig> CameraSettingsConfigs { get; }
Dictionary<AudioSourceType, AudioSourceSettingsConfig> AudioSourceSettingsConfigs { get; }
AudioTestClipsConfig AudioTestClipsConfig { get; }
GeneratorConfig GeneratorConfig { get; }
void Load();
Task<T> InstantiateAsset<T>(AssetReference assetReference) where T : Behaviour;
}
@@ -5,6 +5,7 @@ using Code.Audio;
using Code.Configs;
using Code.Constants;
using Code.Gameplay.Camera;
using Code.Generator;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.AddressableAssets;
@@ -35,6 +36,8 @@ namespace Code.StaticData
public OrderServiceConfig OrderServiceConfig { get; private set; }
public OrderBoxConfig OrderBoxConfig { get; private set; }
public GeneratorConfig GeneratorConfig { get; private set; }
public Dictionary<CameraMode, CameraSettingsConfig> CameraSettingsConfigs { get; private set; } = new();
@@ -49,6 +52,7 @@ namespace Code.StaticData
PlayerConfig = Resources.Load<PlayerConfig>(string.Format(StringPaths.ConfigSingle, "App", "PlayerConfig"));
OrderServiceConfig = Resources.Load<OrderServiceConfig>(string.Format(StringPaths.ConfigSingle, "Gameplay", "OrderServiceConfig"));
OrderBoxConfig = Resources.Load<OrderBoxConfig>(string.Format(StringPaths.ConfigSingle, "Gameplay", "OrderBoxConfig"));
GeneratorConfig = Resources.Load<GeneratorConfig>(string.Format(StringPaths.ConfigSingle, "App", "GeneratorConfig"));
CameraConfig = Resources.Load<CameraConfig>(string.Format(StringPaths.ConfigSingle, "Camera", "CameraConfig"));
CameraSettingsConfigs = Resources