Починка генерации + небольшой прикол дверей

This commit is contained in:
ThomasCharester committed 2025-12-01 00:02:00 +03:00
1 parent aa4a9e69dd
commit fb9510a6b2
66 files changed
+4803 -1241

No files matched your search

@@ -56,6 +56,7 @@ namespace Code.App.AppStates
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug4, RoomPassedDEBUG);
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug5, Tube);
// Context.SceneLoaderService.LoadSceneAsyncAwaitable((int)SceneIds.DevGen);
Context.SceneLoaderService.LoadSceneAsyncAwaitable((int)SceneIds.DevGen);
Context.LoadingManager.OnLoadingEnded += AfterSceneLoaded;
@@ -24,6 +24,8 @@ namespace Code.Gameplay.Camera.CameraStates
CurrentDistance = 0f;
Camera.fieldOfView = Context.CameraSettingsConfigs[CameraMode.FirstPerson].fov;
Cursor.lockState = CursorLockMode.Locked;
}
protected override void HandlePosition(float deltaTime, float zoomInput, Quaternion targetRotation)
@@ -11,6 +11,7 @@ namespace Code.Gameplay.Camera.CameraStates
base.EnterState();
Camera.fieldOfView = Context.CameraSettingsConfigs[CameraMode.MainMenu].fov;
Cursor.lockState = CursorLockMode.None;
}
protected override void HandlePosition(float deltaTime, float zoomInput, Quaternion targetRotation)
@@ -12,6 +12,7 @@ namespace Code.Gameplay.Camera.CameraStates
base.EnterState();
Camera.fieldOfView = Context.CameraSettingsConfigs[CameraMode.Static].fov;
Cursor.lockState = CursorLockMode.None;
}
protected override void HandlePosition(float deltaTime, float zoomInput, Quaternion targetRotation)
@@ -1,9 +1,13 @@
using UnityEngine;
using DG.Tweening;
using UnityEngine;
namespace Code.Gameplay.Door
{
public class Door : MonoBehaviour
{
[SerializeField] private Transform doorPolotno;
private Vector3 _doorInitialPosition;
private Quaternion _doorInitialRotation;
[SerializeField] private Transform hingeJointAnchor;
[SerializeField] private HingeJoint hingeJoint;
[SerializeField] private Rigidbody rigidbody;
@@ -15,9 +19,19 @@ namespace Code.Gameplay.Door
rigidbody.isKinematic = true;
return;
}
_doorInitialPosition = doorPolotno.position;
_doorInitialRotation = doorPolotno.rotation;
rigidbody.isKinematic = false;
hingeJoint.autoConfigureConnectedAnchor = false;
hingeJoint.connectedAnchor = hingeJointAnchor.position;
}
public void CloseTheDoor()
{
TranslationMode(true);
doorPolotno.DORotate(_doorInitialRotation.eulerAngles, 0.5f);
doorPolotno.DOMove(_doorInitialPosition, 0.5f);
}
}
}
@@ -0,0 +1,53 @@
using System;
using DG.Tweening;
using UnityEngine;
namespace Code.Gameplay.Door
{
public class DoorDebug : MonoBehaviour
{
[SerializeField] private Transform doorSelf;
[SerializeField] private Transform doorPolotno;
private Vector3 _doorInitialPosition;
private Quaternion _doorInitialRotation;
[SerializeField] private Transform hingeJointAnchor;
[SerializeField] private HingeJoint hingeJoint;
[SerializeField] private Rigidbody rigidbody;
[SerializeField] private bool debug;
[SerializeField] private bool closed;
private void Start()
{
_doorInitialPosition = doorPolotno.position;
_doorInitialRotation = doorPolotno.rotation;
}
private void Update()
{
if(debug && !closed)
{
CloseTheDoor();
}
}
public void TranslationMode(bool on)
{
if (on)
{
rigidbody.isKinematic = true;
return;
}
_doorInitialPosition = doorPolotno.position;
_doorInitialRotation = doorPolotno.rotation;
rigidbody.isKinematic = false;
hingeJoint.autoConfigureConnectedAnchor = false;
hingeJoint.connectedAnchor = hingeJointAnchor.position;
}
public void CloseTheDoor()
{
// TranslationMode(true);
doorPolotno.DORotate(_doorInitialRotation.eulerAngles, 0.5f);
doorPolotno.DOMove(_doorInitialPosition, 0.5f);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ed06ed70c7924ca9bc59f33ee7e6cdfa
timeCreated: 1764533216
@@ -0,0 +1,7 @@
namespace Code.Gameplay.Door
{
public class DoorPooler
{
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: acfad6f51f224b51abb761fc22e4356f
timeCreated: 1764521809
@@ -12,5 +12,6 @@ namespace Code.Generator
Room CreateRoomByIndex(int index, RoomType roomType);
void ReleaseRooms();
GameObject GetRandomCachedPrefabOfType(RoomType roomType, out int index);
int GetRandomIndexOfType(RoomType roomType);
}
}
+11 -12
View File
@@ -1,11 +1,12 @@
using System;
using Code.Gameplay.Door;
using Code.Gameplay.Orders.Order;
using Code.UI;
using UnityEngine;
namespace Code.Generator
{
[RequireComponent(typeof(Transform))]
{
// Для написания нормальной системы комнат нужен другой подход в корне, это уже не исправить, только залатать большие дыры
public class Room : MonoBehaviour
{
[SerializeField] protected RoomType roomType;
@@ -15,19 +16,17 @@ namespace Code.Generator
[SerializeField] protected Transform enterMarker;
public Transform EnterMarker => enterMarker;
[SerializeField] protected Transform exitMarker;
[SerializeField] protected Transform doorSlot;
public Transform ExitMarker => exitMarker;
[SerializeField] protected Door door;
protected void Awake()
public void Initialize(IOrderService orderService)
{
if (EnterMarker == null || ExitMarker == null)
{
Debug.LogError($"Але маркеры не найдены у комнаты {gameObject.name}");
}
door.TranslationMode(false);
if(roomTrigger) roomTrigger.OrderService = orderService;
}
public void Initialize() => door.TranslationMode(false);
//PIZDEC
public void Seal() => door.CloseTheDoor();
[SerializeField] public RoomTrigger roomTrigger;
}
}
@@ -47,25 +47,14 @@ namespace Code.Generator
// SpawnInitialRoomsAsync();
_orderService.OnOrderGiven += CreateRoomsStack;
RoomTrigger.PlayerEnteredRoom += OnPlayerEntered;
// RoomTrigger.PlayerEnteredRoom += OnPlayerEntered;
CreateInitialRoom();
SpawnNextRoomAsync();
CreateInitialRoom();
}
private void OnEnable()
private void OnPlayerEntered()
{
RoomTrigger.PlayerEnteredRoom += OnPlayerEntered;
}
private void OnDisable()
{
RoomTrigger.PlayerEnteredRoom -= OnPlayerEntered;
}
public void OnPlayerEntered()
{
SpawnNextRoomAsync();
SpawnNextRoom();
if (_spawnedRooms.Count > 3)
{
@@ -95,42 +84,51 @@ namespace Code.Generator
Debug.Log($"комната {room.name} время {room.RoomTimer} осталось: {remainingTime}");
}
CreateSaveRoom();
AddPickupRoom();
Debug.Log($"добавлена зона заказа");
AddSaveRoom();
Debug.Log($"добавлена сейв зона");
Debug.Log($"стек комнат: {_roomIndexesStack.Count}");
SpawnNextRoomAsync();
SpawnNextRoom();
}
private void CreateSaveRoom()
private void AddSaveRoom()
{
var prefab = _factory.GetRandomCachedPrefabOfType(RoomType.Save, out int roomIndex);
Room saveRoom = prefab.GetComponent<Room>();
_roomIndexesStack.Add(new(RoomType.Save, roomIndex));
Debug.Log($"Первая комната: {saveRoom.name}");
int saveRoomIndex = _factory.GetRandomIndexOfType(RoomType.Save);
_roomIndexesStack.Add(new(RoomType.Save, saveRoomIndex));
}
private void AddPickupRoom()
{
int pickupIndex = _factory.GetRandomIndexOfType(RoomType.PickUp);
int insertPos = Random.Range(1, _roomIndexesStack.Count + 1);
_roomIndexesStack.Insert(insertPos, new(RoomType.PickUp, pickupIndex));
}
[Inject] private CurrentSceneEnvironment _currentSceneEnvironment;
private void CreateInitialRoom()
{
GameplaySceneEnvironment gameplaySceneEnvironment = (GameplaySceneEnvironment)_currentSceneEnvironment;
_factory.GetRandomCachedPrefabOfType(RoomType.Initial, out int roomIndex);
// _roomIndexesStack.Add(new(RoomType.Initial, roomIndex));
int roomIndex = _factory.GetRandomIndexOfType(RoomType.Initial);
InitialRoom instantiated = _factory.CreateRoomByIndex(roomIndex, RoomType.Initial).GetComponent<InitialRoom>();
_spawnedRooms.Add(instantiated);
instantiated.transform.position = Vector3.zero;
instantiated.transform.rotation = Quaternion.identity;
gameplaySceneEnvironment.playerSpawnPoint = instantiated.playerSpawn;
instantiated.Initialize();
instantiated.Initialize(_orderService);
Debug.Log($"Первая комната: {instantiated.name}");
}
private void SpawnNextRoomAsync()
private void SpawnNextRoom()
{
if (_nextRoomStackIndex >= _roomIndexesStack.Count)
return;
@@ -149,23 +147,14 @@ namespace Code.Generator
PlaceRoom(room, previousRoom);
}
// Отписываться можно, но Хатико никогда не дождётся вызова уничтоженного объекта.
room.roomTrigger.OnEnter += OnPlayerEntered;
room.roomTrigger.OnExit += _spawnedRooms[^1].Seal;
_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) return;
int insertPos = Random.Range(1, _roomIndexesStack.Count + 1);
_roomIndexesStack.Insert(insertPos, new(RoomType.PickUp, pickupIndex));
}
private void PlaceRoom(Room current, Room previous)
{
@@ -219,11 +208,11 @@ namespace Code.Generator
current.transform.rotation = Quaternion.Euler(0, segmentOriginYRotation, 0);
// locationSegment.isNeedSomeDoors = true;
// locationSegment.AddBadDoorId(locationSegment.LocationSegment.GetDoorOrigins.IndexOf(randomDoorOrigin));
current.Initialize();
current.Initialize(_orderService);
float frameOnTheBallRotation = segmentOriginYRotation + randomDoorOriginRotation.eulerAngles.y;
if (frameOnTheBallRotation > 305f) frameOnTheBallRotation -= 360f;
else if (frameOnTheBallRotation < -45f) frameOnTheBallRotation += 360f;
// float frameOnTheBallRotation = segmentOriginYRotation + randomDoorOriginRotation.eulerAngles.y;
// if (frameOnTheBallRotation > 305f) frameOnTheBallRotation -= 360f;
// else if (frameOnTheBallRotation < -45f) frameOnTheBallRotation += 360f;
// heOnTheBall.AddSlaveLocationSegment(locationSegment.Id);
// heOnTheBall.ReplaceSlaveSegmentDoorOriginYRotation(frameOnTheBallRotation);
@@ -59,6 +59,7 @@ namespace Code.Generator
index = Random.Range(0, _cashedRooms[roomType].Count);
return _cashedRooms[roomType][index];
}
public int GetRandomIndexOfType(RoomType roomType) => Random.Range(0, _cashedRooms[roomType].Count);
public Room CreateRoomByIndex(int index, RoomType roomType)
{
@@ -1,32 +1,36 @@
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;
// }
public IOrderService OrderService;
public event Action OnEnter;
public event Action OnExit;
private bool _playerEntered, _playerExited;
private void OnTriggerEnter(Collider other)
{
if (_playerEntered) return;
_playerEntered = true;
_orderService.RoomPassed();
OrderService.RoomPassed();
OnEnter?.Invoke();
}
private void OnTriggerExit(Collider other)
{
if (_playerExited) return;
Debug.Log(other.name);
PlayerEnteredRoom?.Invoke();
_playerExited = true;
OnExit?.Invoke();
}
}
}
@@ -1,3 +1,3 @@
fileFormatVersion: 2
guid: 4207b7568dc3482393ac1860a31909b4
timeCreated: 1764087485
guid: 0d6940d73d544f0a8e4a45d956bc2364
timeCreated: 1764525516