функция генерирования коридора

This commit is contained in:
vladislove committed 2026-09-30 20:04:18 +03:00
1 parent 236fd9d9f6
commit 3a73877096
11 files changed
+332 -35

No files matched your search

@@ -0,0 +1,139 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &-1320640688500226478
MonoBehaviour:
m_ObjectHideFlags: 11
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
m_Name:
m_EditorClassIdentifier: Unity.RenderPipelines.Universal.Editor::UnityEditor.Rendering.Universal.AssetVersion
version: 10
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: New Material 1
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 1
m_CustomRenderQueue: 2000
stringTagMap:
RenderType: Opaque
disabledShaderPasses:
- MOTIONVECTORS
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_Lightmaps:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_LightmapsInd:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_ShadowMasks:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _AddPrecomputedVelocity: 0
- _AlphaClip: 0
- _AlphaToMask: 0
- _Blend: 0
- _BlendModePreserveSpecular: 1
- _BumpScale: 1
- _ClearCoatMask: 0
- _ClearCoatSmoothness: 0
- _Cull: 1
- _Cutoff: 0.5
- _DetailAlbedoMapScale: 1
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _DstBlendAlpha: 0
- _EnvironmentReflections: 1
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossyReflections: 0
- _Metallic: 0
- _OcclusionStrength: 1
- _Parallax: 0.005
- _QueueOffset: 0
- _ReceiveShadows: 1
- _ScreenSpaceReflections: 1
- _ScreenSpaceReflectionsContributeTransparent: 1
- _Smoothness: 0.936
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _SrcBlendAlpha: 1
- _Surface: 0
- _WorkflowMode: 1
- _XRMotionVectorsPass: 1
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: []
m_AllowLocking: 1
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 05c40618138553b3f9c385bda42bd974
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
@@ -10,7 +10,7 @@ namespace _Project.Scripts.LevelGenerating
public static List<Room> Rooms = new List<Room>();
[SerializeField] private readonly int curFloor;
void AddRoom(ref Room room)
public void AddRoom(ref Room room)
{
Rooms.Add(room);
}
@@ -3,6 +3,7 @@ namespace _Project.Scripts.LevelGenerating
public enum RoomType
{
Start,
Corridor,
Lift,
Laboratory,
Boss,
@@ -1,3 +1,5 @@
using System.ComponentModel.Design.Serialization;
using System.Linq;
using UnityEngine;
namespace _Project.Scripts.LevelGenerating
{
@@ -10,9 +12,13 @@ namespace _Project.Scripts.LevelGenerating
[SerializeField] private int lengthWallMax;
[SerializeField] private int lengthStartRoom;
[SerializeField] private int lengthFloor;
[SerializeField] private int corridorLength;
[SerializeField] private int corridorWigth;
[SerializeField] private GameObject GameObjectA;
[SerializeField] private GameObject GameObjectB;
private int RoomCount;
private LevelManager levelManager;
@@ -30,8 +36,76 @@ namespace _Project.Scripts.LevelGenerating
}
void CreateCorridor(Vector2 posRoom, int Length, int Wigth, ExitsInRoomType exitType)
{
Vector2 corridorPos = Vector2.zero;
int cLength = 0;
int cWidth = 0;
switch (exitType)
{
// Выход направо (+X)
case ExitsInRoomType.XAxisP:
// Начинается у правой стены комнаты (posRoom.x + Length)
// Центрируем коридор по высоте/оси Z: смещаем на половину разницы ширин
corridorPos = new Vector2(
posRoom.x + Length,
posRoom.y + (Wigth - corridorWigth) / 2f
);
cLength = corridorLength;
cWidth = corridorWigth;
break;
// Выход налево (-X)
case ExitsInRoomType.XAxisN:
// Начинается слева от комнаты, отступая на длину коридора
corridorPos = new Vector2(
posRoom.x - corridorLength,
posRoom.y + (Wigth - corridorWigth) / 2f
);
cLength = corridorLength;
cWidth = corridorWigth;
break;
// Выход вперед/вверх (+Z / в Vector2 это Y)
case ExitsInRoomType.ZAxisP:
// Начинается у верхней стены комнаты (posRoom.y + Wigth)
// Центрируем коридор по горизонтали/оси X:
corridorPos = new Vector2(
posRoom.x + (Length - corridorWigth) / 2f,
posRoom.y + Wigth
);
// По оси X коридор узкий, по оси Z — длинный:
cLength = corridorWigth;
cWidth = corridorLength;
break;
// Выход назад/вниз (-Z / в Vector2 это Y)
case ExitsInRoomType.ZAxisN:
// Начинается ниже комнаты, отступая на длину коридора
corridorPos = new Vector2(
posRoom.x + (Length - corridorWigth) / 2f,
posRoom.y - corridorLength
);
cLength = corridorWigth;
cWidth = corridorLength;
break;
}
// Создаем коридор как отдельную комнату
// (Убедись, что в enum RoomType добавлен тип Corridor, либо используй Normal)
Room corridor = new Room(cLength, cWidth, RoomType.Corridor);
// Либо через твой конструктор с позицией:
// Room corridor = new Room(corridorPos, cLength, cWidth, RoomType.Normal);
LevelManager.Rooms.Add(corridor);
// Визуализация коридора (расставляем маркеры по углам коридора для наглядности)
Instantiate(GameObjectB, new Vector3(corridorPos.x, 0, corridorPos.y), Quaternion.identity);
Instantiate(GameObjectB, new Vector3(corridorPos.x + cLength, 0, corridorPos.y), Quaternion.identity);
Instantiate(GameObjectB, new Vector3(corridorPos.x + cLength, 0, corridorPos.y + cWidth), Quaternion.identity);
Instantiate(GameObjectB, new Vector3(corridorPos.x, 0, corridorPos.y + cWidth), Quaternion.identity);
}
void CreateRoom()
{
int a = Random.Range(lengthWallMin, lengthWallMax);
@@ -39,6 +113,7 @@ namespace _Project.Scripts.LevelGenerating
Room room = new Room();
room.Length = a;
room.Wigth = b;
}
void CreateStartRoom()
@@ -114,7 +189,7 @@ namespace _Project.Scripts.LevelGenerating
Instantiate(GameObjectB, new Vector3(xR+lengthStartRoom,0,zR+lengthStartRoom), Quaternion.identity);
Instantiate(GameObjectB, new Vector3(xR,0,zR+lengthStartRoom), Quaternion.identity);
CreateCorridor(new Vector2Int(xR, zR),lengthStartRoom,lengthStartRoom,room.exits.First());
}