Ахуеть, я сделал генерацию уровней на основе идеи Димки
This commit is contained in:
1 parent
b7e9a26462
commit
acd9cc1a32
52 files changed
+6333
-540
No files matched your search
@@ -40,7 +40,7 @@ namespace Code.App.AppStates
|
||||
Context.LoadingManager
|
||||
.RegisterLoading(LoadingWork.LoadScene)
|
||||
.RegisterLoading(LoadingWork.LoadUI)
|
||||
// .RegisterLoading(LoadingWork.LoadModelResource)
|
||||
.RegisterLoading(LoadingWork.LoadModelResource)
|
||||
.RegisterLoading(LoadingWork.LoadAudio);
|
||||
|
||||
//_playerHealth = Context.PlayerFactory.CreatePlayerHealth();
|
||||
@@ -89,7 +89,7 @@ namespace Code.App.AppStates
|
||||
|
||||
Context.LoadingManager.OnLoadingEnded -= AfterSceneLoaded;
|
||||
Context.LoadingManager.OnLoadingEnded += AfterPlayerLoaded;
|
||||
|
||||
|
||||
await UniTask.WhenAll(
|
||||
WaitForPlayerArmsToInitialize(),
|
||||
WaitForPlayerCharacterLoad()
|
||||
|
||||
@@ -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
|
||||
@@ -1,3 +1,5 @@
|
||||
|
||||
using Code.Gameplay.Orders.Order;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -5,9 +7,10 @@ namespace Code.Generator
|
||||
{
|
||||
public interface IRoomGeneratorFactory
|
||||
{
|
||||
UniTask PreloadRooms();
|
||||
GameObject GetCachedPrefab(int index);
|
||||
UniTask<Room> CreateRoomByIndex(int index);
|
||||
void ReleaseRoom(Room room);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
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;
|
||||
@@ -14,6 +16,7 @@ namespace Code.Generator
|
||||
public Transform EnterMarker => enterMarker;
|
||||
[SerializeField] private Transform exitMarker;
|
||||
public Transform ExitMarker => exitMarker;
|
||||
[SerializeField] private Door door;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -22,7 +25,9 @@ namespace Code.Generator
|
||||
Debug.LogError($"Але маркеры не найдены у комнаты {gameObject.name}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Initialize() => door.TranslationMode(false);
|
||||
|
||||
//PIZDEC
|
||||
}
|
||||
}
|
||||
@@ -6,35 +6,49 @@ using UnityEngine;
|
||||
|
||||
namespace Code.Generator
|
||||
{
|
||||
public class RoomGenerator : MonoBehaviour
|
||||
public class RoomGenerator
|
||||
{
|
||||
private IOrderService _orderService;
|
||||
|
||||
[SerializeField] private GeneratorConfig generatorConfig;
|
||||
|
||||
private RoomGeneratorFactory _factory;
|
||||
[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<int> _roomIndexesStack;
|
||||
private List<Room> _spawnedRooms;
|
||||
|
||||
private int _nextRoomStackIndex;
|
||||
|
||||
[Inject]
|
||||
private async void Construct(IOrderService orderService)
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
_orderService = orderService;
|
||||
_orderService.OrderGive();
|
||||
|
||||
_factory = new RoomGeneratorFactory(generatorConfig);
|
||||
// _orderService.OrderGive();
|
||||
|
||||
_spawnedRooms = new List<Room>();
|
||||
_roomIndexesStack = new List<int>();
|
||||
_roomIndexesStack = new();
|
||||
|
||||
Debug.LogWarning($"КОТЛЫ ГЕНЕРАЛЬСКИЕ{_orderService.DeliveryTimer}");
|
||||
|
||||
await _factory.PreloadRooms();
|
||||
// CreateRoomsStack();
|
||||
|
||||
CreateRoomsStack();
|
||||
await SpawnInitialRoomsAsync();
|
||||
// SpawnInitialRoomsAsync();
|
||||
_orderService.OnOrderGiven += CreateRoomsStack;
|
||||
RoomTrigger.PlayerEnteredRoom += OnPlayerEntered;
|
||||
|
||||
CreateSaveRoom();
|
||||
SpawnNextRoomAsync();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
@@ -46,117 +60,72 @@ namespace Code.Generator
|
||||
{
|
||||
RoomTrigger.PlayerEnteredRoom -= OnPlayerEntered;
|
||||
}
|
||||
|
||||
public async void OnPlayerEntered()
|
||||
{
|
||||
await SpawnNextRoomAsync();
|
||||
|
||||
if (_spawnedRooms.Count > 2)
|
||||
public void OnPlayerEntered()
|
||||
{
|
||||
SpawnNextRoomAsync();
|
||||
|
||||
if (_spawnedRooms.Count > 3)
|
||||
{
|
||||
Room roomToRemove = _spawnedRooms[0];
|
||||
_spawnedRooms.RemoveAt(0);
|
||||
|
||||
_factory.ReleaseRoom(roomToRemove);
|
||||
Destroy(roomToRemove.gameObject);
|
||||
// _factory.ReleaseRoom(roomToRemove);
|
||||
Object.Destroy(roomToRemove.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateRoomsStack()
|
||||
|
||||
private void CreateRoomsStack(float timer)
|
||||
{
|
||||
var currentSaveRoom = _roomIndexesStack[^1];
|
||||
_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)
|
||||
_roomIndexesStack.Add(currentSaveRoom);
|
||||
|
||||
var remainingTime = timer;
|
||||
|
||||
while (remainingTime > 0)
|
||||
{
|
||||
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;
|
||||
var prefab = _factory.GetRandomCachedPrefabOfType(RoomType.Basic, out int roomIndex);
|
||||
|
||||
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;
|
||||
}
|
||||
_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;
|
||||
|
||||
await SpawnNextRoomAsync();
|
||||
SpawnNextRoomAsync();
|
||||
|
||||
await SpawnNextRoomAsync();
|
||||
SpawnNextRoomAsync();
|
||||
}
|
||||
|
||||
private async UniTask SpawnNextRoomAsync()
|
||||
|
||||
private void SpawnNextRoomAsync()
|
||||
{
|
||||
if (_nextRoomStackIndex >= _roomIndexesStack.Count)
|
||||
return;
|
||||
|
||||
int index = _roomIndexesStack[_nextRoomStackIndex];
|
||||
Room room = await _factory.CreateRoomByIndex(index);
|
||||
RoomIndex index = _roomIndexesStack[_nextRoomStackIndex];
|
||||
Room room = _factory.CreateRoomByIndex(index.Index, index.RoomType);
|
||||
|
||||
if (_spawnedRooms.Count == 0)
|
||||
{
|
||||
@@ -172,70 +141,168 @@ namespace Code.Generator
|
||||
_spawnedRooms.Add(room);
|
||||
_nextRoomStackIndex++;
|
||||
}
|
||||
|
||||
private int FindRoomIndexByType(RoomType neededType)
|
||||
{
|
||||
int totalRooms = generatorConfig.roomAssetReferences.Length;
|
||||
for (int i = 0; i < totalRooms; i++)
|
||||
{
|
||||
var prefab = _factory.GetCachedPrefab(i);
|
||||
if (prefab == null)
|
||||
continue;
|
||||
|
||||
Room room = prefab.GetComponent<Room>();
|
||||
if (room == null)
|
||||
continue;
|
||||
|
||||
if (room.RoomType == neededType)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void AddPickupRoom()
|
||||
{
|
||||
int pickupIndex = FindRoomIndexByType(RoomType.PickUp);
|
||||
if (pickupIndex == -1)
|
||||
{
|
||||
Debug.Log("PickUp комнат не найдено але");
|
||||
return;
|
||||
}
|
||||
|
||||
var prefab = _factory.GetCachedPrefab(pickupIndex);
|
||||
if (prefab == null)
|
||||
return;
|
||||
var prefab = _factory.GetRandomCachedPrefabOfType(RoomType.PickUp, out int pickupIndex);
|
||||
|
||||
Room pickupRoom = prefab.GetComponent<Room>();
|
||||
if (pickupRoom == null)
|
||||
return;
|
||||
|
||||
if (_roomIndexesStack.Count == 0)
|
||||
{
|
||||
Debug.LogWarning("Стек пуст, нет позиции после первой");
|
||||
return;
|
||||
}
|
||||
|
||||
int insertPos = Random.Range(1, _roomIndexesStack.Count + 1);
|
||||
|
||||
_roomIndexesStack.Insert(insertPos, pickupIndex);
|
||||
|
||||
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;
|
||||
|
||||
Transform enter = current.EnterMarker;
|
||||
Transform exit = previous.ExitMarker;
|
||||
Vector3 segmentOriginPosition = previous.ExitMarker.transform.position;
|
||||
|
||||
Quaternion rotationDiff = Quaternion.FromToRotation(enter.forward, exit.forward);
|
||||
current.transform.rotation = rotationDiff * current.transform.rotation;
|
||||
Transform randomDoorOrigin = current.EnterMarker;
|
||||
Vector3 randomDoorOriginPosition = randomDoorOrigin.localPosition * current.transform.localScale.x;
|
||||
Quaternion randomDoorOriginRotation = randomDoorOrigin.localRotation;
|
||||
|
||||
Vector3 offset = enter.localPosition;
|
||||
current.transform.position = exit.position - offset;
|
||||
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}");
|
||||
// }
|
||||
@@ -1,57 +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 readonly GameObject[] _cashedRooms;
|
||||
private bool _isInitialized;
|
||||
private Dictionary<RoomType, List<GameObject>> _cashedRooms = new();
|
||||
|
||||
public RoomGeneratorFactory(GeneratorConfig generatorConfig)
|
||||
{
|
||||
_roomAssetReferences = generatorConfig.roomAssetReferences;
|
||||
_cashedRooms = new GameObject[_roomAssetReferences.Length];
|
||||
// _cashedRooms = new GameObject[_roomAssetReferences.Length];
|
||||
_cashedRooms.Add(RoomType.Basic, new());
|
||||
_cashedRooms.Add(RoomType.Save, new ());
|
||||
_cashedRooms.Add(RoomType.PickUp, new ());
|
||||
}
|
||||
|
||||
public async UniTask PreloadRooms()
|
||||
{
|
||||
if (_isInitialized)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < _roomAssetReferences.Length; i++)
|
||||
{
|
||||
var reference = _roomAssetReferences[i];
|
||||
var prefab = await reference.LoadAssetAsync<GameObject>().ToUniTask();
|
||||
_cashedRooms[i] = prefab;
|
||||
}
|
||||
|
||||
_isInitialized = true;
|
||||
Debug.Log($"Комнат в памяти есть: {_cashedRooms.Length}");
|
||||
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}");
|
||||
}
|
||||
|
||||
public GameObject GetCachedPrefab(int index)
|
||||
private void OnRoomLoaded(GameObject room)
|
||||
{
|
||||
if (index < 0 || index >= _cashedRooms.Length)
|
||||
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[index];
|
||||
return _cashedRooms[roomType][index];
|
||||
}
|
||||
public GameObject GetRandomCachedPrefabOfType(RoomType roomType, out int index)
|
||||
{
|
||||
index = Random.Range(0, _cashedRooms[roomType].Count);
|
||||
return _cashedRooms[roomType][index];
|
||||
}
|
||||
|
||||
public async UniTask<Room> CreateRoomByIndex(int index)
|
||||
public Room CreateRoomByIndex(int index, RoomType roomType)
|
||||
{
|
||||
var room = UnityEngine.Object.Instantiate(_cashedRooms[roomType][index]);
|
||||
return room.GetComponent<Room>();
|
||||
}
|
||||
public void ReleaseRooms()
|
||||
{
|
||||
if (!_isInitialized)
|
||||
await PreloadRooms();
|
||||
|
||||
return (await Addressables.InstantiateAsync(_roomAssetReferences[index]).ToUniTask()).GetComponent<Room>();
|
||||
}
|
||||
|
||||
public void ReleaseRoom(Room room)
|
||||
{
|
||||
Addressables.Release(room);
|
||||
_roomsHandle.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,17 @@ namespace Code.Generator
|
||||
{
|
||||
public class RoomTrigger : MonoBehaviour
|
||||
{
|
||||
[Inject] private OrderService _orderService;
|
||||
[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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user