механики

This commit is contained in:
lapich committed 2026-10-19 20:14:24 +03:00
1 parent dd5a95a4d3
commit 11d57bec19
129 files changed
+21889 -62

No files matched your search

@@ -0,0 +1,787 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.AI;
using Unity.AI.Navigation;
public static class LaboratoryLevelGenerator
{
private const float WALL_HEIGHT = 4.25f;
private const float WALL_THICKNESS = 0.35f;
[MenuItem("Tools/Generate Full Laboratory Location")]
public static void Generate()
{
Debug.Log("<color=cyan>=== GENERATING LABORATORY LOCATION ===</color>");
// 1. Remove previous Laboratory_Complex or old maze if present
var oldLab = GameObject.Find("Laboratory_Complex");
if (oldLab != null)
{
Undo.DestroyObjectImmediate(oldLab);
}
var oldMaze = GameObject.Find("Maze");
if (oldMaze != null)
{
oldMaze.SetActive(false);
}
// Disable or cleanup old planes
for (int i = 0; i <= 4; i++)
{
string pName = i == 0 ? "Plane" : $"Plane ({i})";
var pl = GameObject.Find(pName);
if (pl != null)
{
pl.SetActive(false);
}
}
// Load assets and materials
Material echoMat = AssetDatabase.LoadAssetAtPath<Material>("Assets/EchoCloudMat.mat");
if (echoMat == null)
{
echoMat = AssetDatabase.LoadAssetAtPath<Material>("Assets/EchoMat.mat");
}
Material woodMat = AssetDatabase.LoadAssetAtPath<Material>("Assets/3D Laboratory Environment with Appratus/Materials/Laboratory03_Wood_BaseMap.mat");
Material otherMat = AssetDatabase.LoadAssetAtPath<Material>("Assets/3D Laboratory Environment with Appratus/Materials/Laboratory03_Others_BaseMap.mat");
Material glassMat = AssetDatabase.LoadAssetAtPath<Material>("Assets/3D Laboratory Environment with Appratus/Materials/Laboratory03_Glass_BaseMap 1.mat");
GameObject tablePrefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/3D Laboratory Environment with Appratus/Prefabs/table with drawers.prefab");
GameObject shelfShowcasePrefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/3D Laboratory Environment with Appratus/Prefabs/shelf showcase.prefab");
GameObject shelf2Prefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/3D Laboratory Environment with Appratus/Prefabs/shelf (2).prefab");
GameObject rackPrefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/3D Laboratory Environment with Appratus/Prefabs/rack.prefab");
GameObject chairPrefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/3D Laboratory Environment with Appratus/Prefabs/chair.prefab");
GameObject pillarPrefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/3D Laboratory Environment with Appratus/Prefabs/pillar.prefab");
GameObject boxPrefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/3D Laboratory Environment with Appratus/Prefabs/Box.prefab");
GameObject beakerPrefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/3D Laboratory Environment with Appratus/Prefabs/Beaker.prefab");
GameObject flaskPrefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/3D Laboratory Environment with Appratus/Prefabs/Erlenmeyer_flask.prefab");
GameObject testTubePrefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/3D Laboratory Environment with Appratus/Prefabs/Glass_Lab_test_tube.prefab");
GameObject instPrefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/3D Laboratory Environment with Appratus/Prefabs/analytical_lab_instruments.prefab");
GameObject tapPrefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/3D Laboratory Environment with Appratus/Prefabs/tap.prefab");
// Root object
GameObject labRoot = new GameObject("Laboratory_Complex");
Undo.RegisterCreatedObjectUndo(labRoot, "Create Laboratory_Complex");
GameObject floorsParent = new GameObject("Floors");
floorsParent.transform.SetParent(labRoot.transform);
GameObject wallsParent = new GameObject("Walls");
wallsParent.transform.SetParent(labRoot.transform);
GameObject roomsParent = new GameObject("Rooms_Props");
roomsParent.transform.SetParent(labRoot.transform);
GameObject lightsParent = new GameObject("Atmospheric_Lighting");
lightsParent.transform.SetParent(labRoot.transform);
GameObject pickupsParent = new GameObject("Throwable_Distractions");
pickupsParent.transform.SetParent(labRoot.transform);
// 2. Build Floor Grid (64m x 64m, from -32 to +32 in X and Z)
CreateFloorGrid(floorsParent.transform, echoMat, -32f, 32f, -32f, 32f);
// 3. Build Perimeter Exterior Walls
CreateWall(wallsParent.transform, echoMat, new Vector3(0, WALL_HEIGHT / 2f, -32f), new Vector3(64f, WALL_HEIGHT, WALL_THICKNESS), "Wall_Perimeter_South");
CreateWall(wallsParent.transform, echoMat, new Vector3(0, WALL_HEIGHT / 2f, 32f), new Vector3(64f, WALL_HEIGHT, WALL_THICKNESS), "Wall_Perimeter_North");
CreateWall(wallsParent.transform, echoMat, new Vector3(-32f, WALL_HEIGHT / 2f, 0), new Vector3(WALL_THICKNESS, WALL_HEIGHT, 64f), "Wall_Perimeter_West");
CreateWall(wallsParent.transform, echoMat, new Vector3(32f, WALL_HEIGHT / 2f, 0), new Vector3(WALL_THICKNESS, WALL_HEIGHT, 64f), "Wall_Perimeter_East");
// 4. Build Rooms Walls with Doorways
// We define rooms as bounding boxes [minX, maxX, minZ, maxZ] and doors on specific sides with cutout [doorMin, doorMax]
// Room 1: Entrance / Decontamination (X: -6 to +6, Z: -32 to -22)
BuildRoomWalls(wallsParent.transform, echoMat, -6f, 6f, -32f, -22f,
southDoor: null, // sealed
northDoor: new Vector2(-1.8f, 1.8f),
westDoor: null,
eastDoor: null,
roomName: "Decontamination");
// Room 4: Cryo Archive (X: -30 to -14, Z: -32 to -20)
BuildRoomWalls(wallsParent.transform, echoMat, -30f, -14f, -32f, -20f,
southDoor: null,
northDoor: new Vector2(-24f, -20f),
westDoor: null,
eastDoor: new Vector2(-27f, -23f),
roomName: "CryoArchive");
// Room 8: Security & Surveillance (X: 14 to 30, Z: -32 to -20)
BuildRoomWalls(wallsParent.transform, echoMat, 14f, 30f, -32f, -20f,
southDoor: null,
northDoor: new Vector2(20f, 24f),
westDoor: new Vector2(-27f, -23f),
eastDoor: null,
roomName: "SecurityOffice");
// Room 2: Biochemistry Research Lab (X: -30 to -14, Z: -14 to 2)
BuildRoomWalls(wallsParent.transform, echoMat, -30f, -14f, -14f, 2f,
southDoor: new Vector2(-24f, -20f),
northDoor: new Vector2(-24f, -20f),
westDoor: null,
eastDoor: new Vector2(-8f, -4f),
roomName: "BiochemLab");
// Room 6: Surgical Theatre & Medical Bay (X: 14 to 30, Z: -14 to 2)
BuildRoomWalls(wallsParent.transform, echoMat, 14f, 30f, -14f, 2f,
southDoor: new Vector2(20f, 24f),
northDoor: new Vector2(20f, 24f),
westDoor: new Vector2(-8f, -4f),
eastDoor: null,
roomName: "SurgicalBay");
// Room 3: Bio-Hazard Containment Vault (X: -30 to -12, Z: 8 to 26)
BuildRoomWalls(wallsParent.transform, echoMat, -30f, -12f, 8f, 26f,
southDoor: new Vector2(-23f, -19f),
northDoor: new Vector2(-23f, -19f), // leads to North Maintenance bypass
westDoor: null,
eastDoor: new Vector2(15f, 19f),
roomName: "BioContainment");
// Room 5: Central Bio-Dome & Core Reactor (X: -7 to 7, Z: 8 to 26)
BuildRoomWalls(wallsParent.transform, echoMat, -7f, 7f, 8f, 26f,
southDoor: new Vector2(-2f, 2f),
northDoor: new Vector2(-2f, 2f), // leads to North Maintenance bypass
westDoor: new Vector2(15f, 19f),
eastDoor: new Vector2(15f, 19f),
roomName: "CentralCore");
// Room 7: Genetics Sequencing Lab (X: 12 to 30, Z: 6 to 18)
BuildRoomWalls(wallsParent.transform, echoMat, 12f, 30f, 6f, 18f,
southDoor: new Vector2(19f, 23f),
northDoor: new Vector2(19f, 23f),
westDoor: new Vector2(10f, 14f),
eastDoor: null,
roomName: "GeneticsLab");
// Room 9: Generator Substation (X: 12 to 30, Z: 20 to 30)
BuildRoomWalls(wallsParent.transform, echoMat, 12f, 30f, 20f, 30f,
southDoor: new Vector2(19f, 23f),
northDoor: null,
westDoor: new Vector2(23f, 27f), // leads to North Maintenance bypass
eastDoor: null,
roomName: "GeneratorRoom");
// 5. Build Tangled Corridor Internal Walls & Partitions (Maze structure)
BuildCorridorMaze(wallsParent.transform, echoMat);
// 6. Populate Rooms with Furniture & Props
PopulateDecontamination(roomsParent.transform, pillarPrefab, rackPrefab, chairPrefab, echoMat);
PopulateBiochemLab(roomsParent.transform, tablePrefab, shelfShowcasePrefab, shelf2Prefab, tapPrefab, instPrefab, beakerPrefab, flaskPrefab, testTubePrefab, pickupsParent.transform);
PopulateBioContainment(roomsParent.transform, pillarPrefab, tablePrefab, boxPrefab, beakerPrefab, instPrefab, pickupsParent.transform);
PopulateCryoArchive(roomsParent.transform, rackPrefab, shelf2Prefab, boxPrefab, beakerPrefab, pickupsParent.transform);
PopulateCentralCore(roomsParent.transform, pillarPrefab, tablePrefab, instPrefab, boxPrefab, beakerPrefab, pickupsParent.transform);
PopulateSurgicalBay(roomsParent.transform, tablePrefab, shelfShowcasePrefab, chairPrefab, beakerPrefab, pickupsParent.transform);
PopulateGeneticsLab(roomsParent.transform, tablePrefab, shelfShowcasePrefab, instPrefab, chairPrefab, beakerPrefab, pickupsParent.transform);
PopulateGeneratorRoom(roomsParent.transform, pillarPrefab, boxPrefab, beakerPrefab, pickupsParent.transform);
PopulateCorridorNiches(roomsParent.transform, pillarPrefab, boxPrefab, rackPrefab);
// 7. Atmospheric Lighting setup
CreateLighting(lightsParent.transform);
// 8. Reconfigure Player Position
var player = GameObject.Find("Capsule");
if (player != null)
{
player.transform.position = new Vector3(0f, 1.05f, -28f);
player.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
Debug.Log("Moved Player to Entrance Airlock (0, 1.05, -28)");
}
// 9. Reconfigure Enemy (BlindMutantAI) & Patrol Waypoints
var enemy = GameObject.Find("enemy");
SetupPatrolWaypoints(labRoot.transform, enemy);
// 10. Re-bake NavMesh Surface
var navMeshSurface = Object.FindAnyObjectByType<NavMeshSurface>();
if (navMeshSurface != null)
{
navMeshSurface.transform.position = Vector3.zero;
navMeshSurface.collectObjects = CollectObjects.All;
navMeshSurface.BuildNavMesh();
Debug.Log("<color=green>NavMesh successfully baked for the entire laboratory complex!</color>");
}
// Mark scene dirty
EditorUtility.SetDirty(labRoot);
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
Debug.Log("<color=green>=== LABORATORY COMPLEX GENERATION COMPLETE! ===</color>");
}
private static void CreateFloorGrid(Transform parent, Material mat, float minX, float maxX, float minZ, float maxZ)
{
// 4 large floor quadrants for clean rendering and collision
float midX = (minX + maxX) / 2f;
float midZ = (minZ + maxZ) / 2f;
float sizeX = (maxX - minX) / 2f;
float sizeZ = (maxZ - minZ) / 2f;
Vector2[] quads = new Vector2[]
{
new Vector2((minX + midX) / 2f, (minZ + midZ) / 2f),
new Vector2((midX + maxX) / 2f, (minZ + midZ) / 2f),
new Vector2((minX + midX) / 2f, (midZ + maxZ) / 2f),
new Vector2((midX + maxX) / 2f, (midZ + maxZ) / 2f)
};
for (int i = 0; i < quads.Length; i++)
{
var floorGo = GameObject.CreatePrimitive(PrimitiveType.Cube);
floorGo.name = $"Floor_Quadrant_{i + 1}";
floorGo.transform.SetParent(parent);
floorGo.transform.position = new Vector3(quads[i].x, -0.25f, quads[i].y);
floorGo.transform.localScale = new Vector3(sizeX, 0.5f, sizeZ);
if (mat != null) floorGo.GetComponent<Renderer>().sharedMaterial = mat;
}
}
private static void BuildRoomWalls(Transform parent, Material mat, float minX, float maxX, float minZ, float maxZ,
Vector2? southDoor, Vector2? northDoor, Vector2? westDoor, Vector2? eastDoor, string roomName)
{
GameObject roomWalls = new GameObject($"Walls_{roomName}");
roomWalls.transform.SetParent(parent);
// South Wall (along X at Z = minZ)
CreateWallWithDoor(roomWalls.transform, mat, minX, maxX, minZ, true, southDoor, $"{roomName}_South");
// North Wall (along X at Z = maxZ)
CreateWallWithDoor(roomWalls.transform, mat, minX, maxX, maxZ, true, northDoor, $"{roomName}_North");
// West Wall (along Z at X = minX)
CreateWallWithDoor(roomWalls.transform, mat, minZ, maxZ, minX, false, westDoor, $"{roomName}_West");
// East Wall (along Z at X = maxX)
CreateWallWithDoor(roomWalls.transform, mat, minZ, maxZ, maxX, false, eastDoor, $"{roomName}_East");
}
private static void CreateWallWithDoor(Transform parent, Material mat, float startCoord, float endCoord, float fixedCoord,
bool isHorizontal, Vector2? doorRange, string wallName)
{
if (startCoord > endCoord)
{
float t = startCoord; startCoord = endCoord; endCoord = t;
}
if (!doorRange.HasValue)
{
// Full solid wall
float length = endCoord - startCoord;
float mid = (startCoord + endCoord) / 2f;
Vector3 pos = isHorizontal ? new Vector3(mid, WALL_HEIGHT / 2f, fixedCoord) : new Vector3(fixedCoord, WALL_HEIGHT / 2f, mid);
Vector3 scale = isHorizontal ? new Vector3(length, WALL_HEIGHT, WALL_THICKNESS) : new Vector3(WALL_THICKNESS, WALL_HEIGHT, length);
CreateWall(parent, mat, pos, scale, wallName);
return;
}
float dMin = Mathf.Clamp(doorRange.Value.x, startCoord, endCoord);
float dMax = Mathf.Clamp(doorRange.Value.y, startCoord, endCoord);
// Left / Start section
if (dMin > startCoord + 0.2f)
{
float len1 = dMin - startCoord;
float mid1 = (startCoord + dMin) / 2f;
Vector3 pos1 = isHorizontal ? new Vector3(mid1, WALL_HEIGHT / 2f, fixedCoord) : new Vector3(fixedCoord, WALL_HEIGHT / 2f, mid1);
Vector3 scale1 = isHorizontal ? new Vector3(len1, WALL_HEIGHT, WALL_THICKNESS) : new Vector3(WALL_THICKNESS, WALL_HEIGHT, len1);
CreateWall(parent, mat, pos1, scale1, $"{wallName}_PartA");
}
// Right / End section
if (endCoord > dMax + 0.2f)
{
float len2 = endCoord - dMax;
float mid2 = (dMax + endCoord) / 2f;
Vector3 pos2 = isHorizontal ? new Vector3(mid2, WALL_HEIGHT / 2f, fixedCoord) : new Vector3(fixedCoord, WALL_HEIGHT / 2f, mid2);
Vector3 scale2 = isHorizontal ? new Vector3(len2, WALL_HEIGHT, WALL_THICKNESS) : new Vector3(WALL_THICKNESS, WALL_HEIGHT, len2);
CreateWall(parent, mat, pos2, scale2, $"{wallName}_PartB");
}
// Over-door Lintel (bulkhead arch)
float doorLen = dMax - dMin;
float doorMid = (dMin + dMax) / 2f;
float lintelHeight = WALL_HEIGHT - 2.5f;
float lintelPosY = 2.5f + (lintelHeight / 2f);
Vector3 lintelPos = isHorizontal ? new Vector3(doorMid, lintelPosY, fixedCoord) : new Vector3(fixedCoord, lintelPosY, doorMid);
Vector3 lintelScale = isHorizontal ? new Vector3(doorLen, lintelHeight, WALL_THICKNESS) : new Vector3(WALL_THICKNESS, lintelHeight, doorLen);
CreateWall(parent, mat, lintelPos, lintelScale, $"{wallName}_Lintel");
}
private static GameObject CreateWall(Transform parent, Material mat, Vector3 pos, Vector3 scale, string name)
{
var wall = GameObject.CreatePrimitive(PrimitiveType.Cube);
wall.name = name;
wall.transform.SetParent(parent);
wall.transform.position = pos;
wall.transform.localScale = scale;
if (mat != null) wall.GetComponent<Renderer>().sharedMaterial = mat;
return wall;
}
private static void BuildCorridorMaze(Transform parent, Material mat)
{
GameObject mazeGo = new GameObject("Tangled_Corridors_Maze");
mazeGo.transform.SetParent(parent);
// 1. Central Core Elevator Shaft / Ventilation Pillar divider (splits Central Hallway into two paths)
// Position: X: -3 to +3, Z: -6 to 2
CreateWall(mazeGo.transform, mat, new Vector3(0f, WALL_HEIGHT / 2f, -2f), new Vector3(5f, WALL_HEIGHT, 6f), "Central_Ventilation_Core");
// 2. West Serpentine Hallway Dividers (creating zig-zags between X: -14 and -6)
// Horizontal baffle at Z = -17 (X from -14 to -9)
CreateWall(mazeGo.transform, mat, new Vector3(-11.5f, WALL_HEIGHT / 2f, -17f), new Vector3(5f, WALL_HEIGHT, WALL_THICKNESS), "Baffle_West_1");
// Vertical wall at X = -9 (Z from -17 to -12) with opening
CreateWall(mazeGo.transform, mat, new Vector3(-9f, WALL_HEIGHT / 2f, -14.5f), new Vector3(WALL_THICKNESS, WALL_HEIGHT, 5f), "Baffle_West_2");
// Horizontal baffle at Z = -11 (X from -11 to -7)
CreateWall(mazeGo.transform, mat, new Vector3(-9f, WALL_HEIGHT / 2f, -11f), new Vector3(4f, WALL_HEIGHT, WALL_THICKNESS), "Baffle_West_3");
// Vertical wall at X = -10 (Z from -4 to 3)
CreateWall(mazeGo.transform, mat, new Vector3(-10f, WALL_HEIGHT / 2f, -0.5f), new Vector3(WALL_THICKNESS, WALL_HEIGHT, 7f), "Baffle_West_4");
// Alcove cover at X = -7 (Z = 5)
CreateWall(mazeGo.transform, mat, new Vector3(-8.5f, WALL_HEIGHT / 2f, 5f), new Vector3(3f, WALL_HEIGHT, WALL_THICKNESS), "Baffle_West_Alcove");
// 3. East Serpentine Hallway Dividers (creating zig-zags between X: +6 and +14)
// Horizontal baffle at Z = -17 (X from 9 to 14)
CreateWall(mazeGo.transform, mat, new Vector3(11.5f, WALL_HEIGHT / 2f, -17f), new Vector3(5f, WALL_HEIGHT, WALL_THICKNESS), "Baffle_East_1");
// Vertical wall at X = 9 (Z from -17 to -12)
CreateWall(mazeGo.transform, mat, new Vector3(9f, WALL_HEIGHT / 2f, -14.5f), new Vector3(WALL_THICKNESS, WALL_HEIGHT, 5f), "Baffle_East_2");
// Horizontal baffle at Z = -11 (X from 7 to 11)
CreateWall(mazeGo.transform, mat, new Vector3(9f, WALL_HEIGHT / 2f, -11f), new Vector3(4f, WALL_HEIGHT, WALL_THICKNESS), "Baffle_East_3");
// Vertical wall at X = 10 (Z from -4 to 3)
CreateWall(mazeGo.transform, mat, new Vector3(10f, WALL_HEIGHT / 2f, -0.5f), new Vector3(WALL_THICKNESS, WALL_HEIGHT, 7f), "Baffle_East_4");
// Alcove cover at X = 7 (Z = 5)
CreateWall(mazeGo.transform, mat, new Vector3(8.5f, WALL_HEIGHT / 2f, 5f), new Vector3(3f, WALL_HEIGHT, WALL_THICKNESS), "Baffle_East_Alcove");
// 4. North Maintenance Crawlway / Bypass (Long narrow bypass at Z: 28 to 31, spanning X: -27 to +27)
// Southern guide wall of the crawlway:
// Section A (X: -30 to -9 at Z = 28.5) with door into BioContainment at X: -21
CreateWallWithDoor(mazeGo.transform, mat, -30f, -9f, 28.5f, true, new Vector2(-23f, -19f), "NorthCrawl_WestGuide");
// Section B (X: -5 to +5 at Z = 28.5) behind Central Core with center access door
CreateWallWithDoor(mazeGo.transform, mat, -7f, 7f, 28.5f, true, new Vector2(-2f, 2f), "NorthCrawl_MidGuide");
// Section C (X: 9 to 30 at Z = 28.5) leading to Generator room with door at X: 21
CreateWallWithDoor(mazeGo.transform, mat, 9f, 30f, 28.5f, true, new Vector2(19f, 23f), "NorthCrawl_EastGuide");
// 5. South Crossroads Corridor Dividers (between Decontamination and Wings)
// Partition at X = -6, Z = -18 (creating blind corner from Decon to Cryo)
CreateWall(mazeGo.transform, mat, new Vector3(-6f, WALL_HEIGHT / 2f, -18f), new Vector3(WALL_THICKNESS, WALL_HEIGHT, 4f), "Crossroad_West_Corner");
// Partition at X = +6, Z = -18 (creating blind corner from Decon to Security)
CreateWall(mazeGo.transform, mat, new Vector3(6f, WALL_HEIGHT / 2f, -18f), new Vector3(WALL_THICKNESS, WALL_HEIGHT, 4f), "Crossroad_East_Corner");
}
private static void PopulateDecontamination(Transform parent, GameObject pillarPrefab, GameObject rackPrefab, GameObject chairPrefab, Material echoMat)
{
GameObject room = new GameObject("Decontamination_Props");
room.transform.SetParent(parent);
// Decontamination Frame (two pillars with lintel)
SpawnProp(pillarPrefab, room.transform, new Vector3(-2f, 0f, -25f), Quaternion.identity);
SpawnProp(pillarPrefab, room.transform, new Vector3(2f, 0f, -25f), Quaternion.identity);
// Lockers / Racks along West wall
SpawnProp(rackPrefab, room.transform, new Vector3(-4.8f, 0f, -29f), Quaternion.Euler(0f, 90f, 0f));
SpawnProp(rackPrefab, room.transform, new Vector3(-4.8f, 0f, -27f), Quaternion.Euler(0f, 90f, 0f));
// Benches along East wall
SpawnProp(chairPrefab, room.transform, new Vector3(4.5f, 0f, -29f), Quaternion.Euler(0f, -90f, 0f));
SpawnProp(chairPrefab, room.transform, new Vector3(4.5f, 0f, -27f), Quaternion.Euler(0f, -90f, 0f));
}
private static void PopulateBiochemLab(Transform parent, GameObject tablePrefab, GameObject showcasePrefab, GameObject shelfPrefab,
GameObject tapPrefab, GameObject instPrefab, GameObject beakerPrefab, GameObject flaskPrefab, GameObject tubePrefab, Transform pickupsParent)
{
GameObject room = new GameObject("BiochemLab_Props");
room.transform.SetParent(parent);
// Central Lab Island 1
SpawnProp(tablePrefab, room.transform, new Vector3(-24f, 0f, -8f), Quaternion.identity);
SpawnProp(tablePrefab, room.transform, new Vector3(-20f, 0f, -8f), Quaternion.identity);
SpawnProp(instPrefab, room.transform, new Vector3(-24f, 1.07f, -8f), Quaternion.identity);
SpawnProp(tapPrefab, room.transform, new Vector3(-20f, 1.07f, -8f), Quaternion.identity);
// Central Lab Island 2
SpawnProp(tablePrefab, room.transform, new Vector3(-24f, 0f, -4f), Quaternion.identity);
SpawnProp(tablePrefab, room.transform, new Vector3(-20f, 0f, -4f), Quaternion.identity);
SpawnProp(tubePrefab, room.transform, new Vector3(-23.5f, 1.07f, -4f), Quaternion.identity);
SpawnProp(flaskPrefab, room.transform, new Vector3(-20.5f, 1.07f, -4f), Quaternion.identity);
// Shelves along West Wall
SpawnProp(showcasePrefab, room.transform, new Vector3(-29f, 0f, -10f), Quaternion.Euler(0f, 90f, 0f));
SpawnProp(showcasePrefab, room.transform, new Vector3(-29f, 0f, -2f), Quaternion.Euler(0f, 90f, 0f));
SpawnProp(shelfPrefab, room.transform, new Vector3(-29f, 0f, -6f), Quaternion.Euler(0f, 90f, 0f));
// Throwable Beaker distraction on bench
SpawnThrowableBeaker(beakerPrefab, pickupsParent, new Vector3(-19.5f, 1.15f, -8f), "Throwable_Beaker_Biochem1");
SpawnThrowableBeaker(beakerPrefab, pickupsParent, new Vector3(-24.5f, 1.15f, -4f), "Throwable_Beaker_Biochem2");
}
private static void PopulateBioContainment(Transform parent, GameObject pillarPrefab, GameObject tablePrefab, GameObject boxPrefab,
GameObject beakerPrefab, GameObject instPrefab, Transform pickupsParent)
{
GameObject room = new GameObject("BioContainment_Props");
room.transform.SetParent(parent);
// 4 massive containment corner pillars
SpawnProp(pillarPrefab, room.transform, new Vector3(-26f, 0f, 12f), Quaternion.identity);
SpawnProp(pillarPrefab, room.transform, new Vector3(-15f, 0f, 12f), Quaternion.identity);
SpawnProp(pillarPrefab, room.transform, new Vector3(-26f, 0f, 22f), Quaternion.identity);
SpawnProp(pillarPrefab, room.transform, new Vector3(-15f, 0f, 22f), Quaternion.identity);
// Broken containment center vat/chamber
var vatBase = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
vatBase.name = "Containment_Vat_Broken";
vatBase.transform.SetParent(room.transform);
vatBase.transform.position = new Vector3(-20.5f, 1.5f, 17f);
vatBase.transform.localScale = new Vector3(3.5f, 1.5f, 3.5f);
// Observation console desk
SpawnProp(tablePrefab, room.transform, new Vector3(-20.5f, 0f, 10.5f), Quaternion.identity);
SpawnProp(instPrefab, room.transform, new Vector3(-20.5f, 1.07f, 10.5f), Quaternion.identity);
// Overturned boxes and cover
SpawnProp(boxPrefab, room.transform, new Vector3(-24f, 0f, 15f), Quaternion.Euler(0f, 35f, 0f));
SpawnProp(boxPrefab, room.transform, new Vector3(-24f, 0f, 16.5f), Quaternion.Euler(0f, 15f, 0f));
SpawnProp(boxPrefab, room.transform, new Vector3(-16f, 0f, 20f), Quaternion.Euler(0f, 60f, 0f));
// Throwable distraction beaker
SpawnThrowableBeaker(beakerPrefab, pickupsParent, new Vector3(-20f, 1.15f, 10.5f), "Throwable_Beaker_Containment");
}
private static void PopulateCryoArchive(Transform parent, GameObject rackPrefab, GameObject shelfPrefab, GameObject boxPrefab,
GameObject beakerPrefab, Transform pickupsParent)
{
GameObject room = new GameObject("CryoArchive_Props");
room.transform.SetParent(parent);
// Rows of storage racks creating narrow aisles
SpawnProp(rackPrefab, room.transform, new Vector3(-26f, 0f, -28f), Quaternion.identity);
SpawnProp(rackPrefab, room.transform, new Vector3(-26f, 0f, -24f), Quaternion.identity);
SpawnProp(rackPrefab, room.transform, new Vector3(-21f, 0f, -28f), Quaternion.identity);
SpawnProp(rackPrefab, room.transform, new Vector3(-21f, 0f, -24f), Quaternion.identity);
SpawnProp(rackPrefab, room.transform, new Vector3(-16f, 0f, -28f), Quaternion.identity);
// Storage boxes stacked for cover
SpawnProp(boxPrefab, room.transform, new Vector3(-28.5f, 0f, -22f), Quaternion.identity);
SpawnProp(boxPrefab, room.transform, new Vector3(-28.5f, 1.08f, -22f), Quaternion.identity);
SpawnProp(boxPrefab, room.transform, new Vector3(-17f, 0f, -22f), Quaternion.identity);
// Shelves along back wall
SpawnProp(shelfPrefab, room.transform, new Vector3(-23f, 0f, -31f), Quaternion.identity);
// Throwable distraction beaker in storage
SpawnThrowableBeaker(beakerPrefab, pickupsParent, new Vector3(-26f, 1.15f, -28f), "Throwable_Beaker_Cryo");
}
private static void PopulateCentralCore(Transform parent, GameObject pillarPrefab, GameObject tablePrefab, GameObject instPrefab,
GameObject boxPrefab, GameObject beakerPrefab, Transform pickupsParent)
{
GameObject room = new GameObject("CentralCore_Props");
room.transform.SetParent(parent);
// 4 massive observation pillars
SpawnProp(pillarPrefab, room.transform, new Vector3(-5.5f, 0f, 10.5f), Quaternion.identity);
SpawnProp(pillarPrefab, room.transform, new Vector3(5.5f, 0f, 10.5f), Quaternion.identity);
SpawnProp(pillarPrefab, room.transform, new Vector3(-5.5f, 0f, 23.5f), Quaternion.identity);
SpawnProp(pillarPrefab, room.transform, new Vector3(5.5f, 0f, 23.5f), Quaternion.identity);
// Central Specimen Reactor Vat
var coreCylinder = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
coreCylinder.name = "Central_Mutant_Reactor_Core";
coreCylinder.transform.SetParent(room.transform);
coreCylinder.transform.position = new Vector3(0f, 2.0f, 17f);
coreCylinder.transform.localScale = new Vector3(4.5f, 2.0f, 4.5f);
// Observation console desks
SpawnProp(tablePrefab, room.transform, new Vector3(-3f, 0f, 13f), Quaternion.Euler(0f, 45f, 0f));
SpawnProp(instPrefab, room.transform, new Vector3(-3f, 1.07f, 13f), Quaternion.Euler(0f, 45f, 0f));
SpawnProp(tablePrefab, room.transform, new Vector3(3f, 0f, 13f), Quaternion.Euler(0f, -45f, 0f));
SpawnProp(instPrefab, room.transform, new Vector3(3f, 1.07f, 13f), Quaternion.Euler(0f, -45f, 0f));
// Cover crates in corners
SpawnProp(boxPrefab, room.transform, new Vector3(-5.5f, 0f, 17f), Quaternion.identity);
SpawnProp(boxPrefab, room.transform, new Vector3(5.5f, 0f, 17f), Quaternion.identity);
// Throwable distraction beaker on console
SpawnThrowableBeaker(beakerPrefab, pickupsParent, new Vector3(-2.8f, 1.15f, 13.2f), "Throwable_Beaker_Core");
}
private static void PopulateSurgicalBay(Transform parent, GameObject tablePrefab, GameObject showcasePrefab, GameObject chairPrefab,
GameObject beakerPrefab, Transform pickupsParent)
{
GameObject room = new GameObject("SurgicalBay_Props");
room.transform.SetParent(parent);
// Dual operating / dissection tables
SpawnProp(tablePrefab, room.transform, new Vector3(18f, 0f, -6f), Quaternion.identity);
SpawnProp(tablePrefab, room.transform, new Vector3(24f, 0f, -6f), Quaternion.identity);
// Surgeon stools
SpawnProp(chairPrefab, room.transform, new Vector3(18f, 0f, -4.5f), Quaternion.Euler(0f, 180f, 0f));
SpawnProp(chairPrefab, room.transform, new Vector3(24f, 0f, -4.5f), Quaternion.Euler(0f, 180f, 0f));
// Medical supply showcases along East Wall
SpawnProp(showcasePrefab, room.transform, new Vector3(29f, 0f, -10f), Quaternion.Euler(0f, -90f, 0f));
SpawnProp(showcasePrefab, room.transform, new Vector3(29f, 0f, -2f), Quaternion.Euler(0f, -90f, 0f));
// Throwable beaker
SpawnThrowableBeaker(beakerPrefab, pickupsParent, new Vector3(23.5f, 1.15f, -6f), "Throwable_Beaker_Surgery");
}
private static void PopulateGeneticsLab(Transform parent, GameObject tablePrefab, GameObject showcasePrefab, GameObject instPrefab,
GameObject chairPrefab, GameObject beakerPrefab, Transform pickupsParent)
{
GameObject room = new GameObject("GeneticsLab_Props");
room.transform.SetParent(parent);
// Genetic sequencer workstations
SpawnProp(tablePrefab, room.transform, new Vector3(18f, 0f, 12f), Quaternion.identity);
SpawnProp(instPrefab, room.transform, new Vector3(18f, 1.07f, 12f), Quaternion.identity);
SpawnProp(chairPrefab, room.transform, new Vector3(18f, 0f, 10.5f), Quaternion.identity);
SpawnProp(tablePrefab, room.transform, new Vector3(24f, 0f, 12f), Quaternion.identity);
SpawnProp(instPrefab, room.transform, new Vector3(24f, 1.07f, 12f), Quaternion.identity);
SpawnProp(chairPrefab, room.transform, new Vector3(24f, 0f, 10.5f), Quaternion.identity);
// Showcases along East Wall
SpawnProp(showcasePrefab, room.transform, new Vector3(29f, 0f, 12f), Quaternion.Euler(0f, -90f, 0f));
// Throwable beaker
SpawnThrowableBeaker(beakerPrefab, pickupsParent, new Vector3(24.5f, 1.15f, 12f), "Throwable_Beaker_Genetics");
}
private static void PopulateGeneratorRoom(Transform parent, GameObject pillarPrefab, GameObject boxPrefab, GameObject beakerPrefab, Transform pickupsParent)
{
GameObject room = new GameObject("GeneratorRoom_Props");
room.transform.SetParent(parent);
// 2 Massive Transformer Generator Blocks
var gen1 = GameObject.CreatePrimitive(PrimitiveType.Cube);
gen1.name = "Generator_Core_1";
gen1.transform.SetParent(room.transform);
gen1.transform.position = new Vector3(18f, 2.0f, 25f);
gen1.transform.localScale = new Vector3(3f, 4f, 4f);
var gen2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
gen2.name = "Generator_Core_2";
gen2.transform.SetParent(room.transform);
gen2.transform.position = new Vector3(25f, 2.0f, 25f);
gen2.transform.localScale = new Vector3(3f, 4f, 4f);
// Support pillars
SpawnProp(pillarPrefab, room.transform, new Vector3(14f, 0f, 28f), Quaternion.identity);
SpawnProp(pillarPrefab, room.transform, new Vector3(28f, 0f, 28f), Quaternion.identity);
// Power supply crates
SpawnProp(boxPrefab, room.transform, new Vector3(21.5f, 0f, 27.5f), Quaternion.identity);
SpawnProp(boxPrefab, room.transform, new Vector3(21.5f, 1.08f, 27.5f), Quaternion.identity);
// Throwable distraction
SpawnThrowableBeaker(beakerPrefab, pickupsParent, new Vector3(21.5f, 1.15f, 22f), "Throwable_Beaker_Generator");
}
private static void PopulateCorridorNiches(Transform parent, GameObject pillarPrefab, GameObject boxPrefab, GameObject rackPrefab)
{
GameObject niches = new GameObject("Corridor_Niches_Cover");
niches.transform.SetParent(parent);
// South Concourse pillars & crates
SpawnProp(pillarPrefab, niches.transform, new Vector3(-3f, 0f, -18f), Quaternion.identity);
SpawnProp(pillarPrefab, niches.transform, new Vector3(3f, 0f, -18f), Quaternion.identity);
SpawnProp(boxPrefab, niches.transform, new Vector3(0f, 0f, -17f), Quaternion.identity);
// West corridor alcove hiding spot
SpawnProp(boxPrefab, niches.transform, new Vector3(-8.5f, 0f, 6.5f), Quaternion.identity);
SpawnProp(rackPrefab, niches.transform, new Vector3(-8.5f, 0f, -12.5f), Quaternion.Euler(0f, 90f, 0f));
// East corridor alcove hiding spot
SpawnProp(boxPrefab, niches.transform, new Vector3(8.5f, 0f, 6.5f), Quaternion.identity);
SpawnProp(rackPrefab, niches.transform, new Vector3(8.5f, 0f, -12.5f), Quaternion.Euler(0f, -90f, 0f));
// North Crawlway mid-point cover
SpawnProp(boxPrefab, niches.transform, new Vector3(-8f, 0f, 30f), Quaternion.identity);
SpawnProp(boxPrefab, niches.transform, new Vector3(8f, 0f, 30f), Quaternion.identity);
}
private static void SpawnProp(GameObject prefab, Transform parent, Vector3 pos, Quaternion rot)
{
if (prefab == null) return;
GameObject instance = (GameObject)PrefabUtility.InstantiatePrefab(prefab, parent);
if (instance != null)
{
instance.transform.position = pos;
instance.transform.rotation = rot;
}
}
private static void SpawnThrowableBeaker(GameObject beakerPrefab, Transform parent, Vector3 pos, string name)
{
GameObject beaker;
if (beakerPrefab != null)
{
beaker = (GameObject)PrefabUtility.InstantiatePrefab(beakerPrefab, parent);
}
else
{
beaker = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
beaker.transform.localScale = new Vector3(0.3f, 0.5f, 0.3f);
}
beaker.name = name;
beaker.transform.position = pos;
// Ensure collider
var col = beaker.GetComponent<Collider>();
if (col == null)
{
col = beaker.AddComponent<CapsuleCollider>();
}
// Rigidbody for throwing physics
var rb = beaker.GetComponent<Rigidbody>();
if (rb == null)
{
rb = beaker.AddComponent<Rigidbody>();
}
rb.mass = 1.0f;
rb.collisionDetectionMode = CollisionDetectionMode.Continuous;
// ImpactWave component so it triggers echolocation wave and mutant alert when landing!
var wave = beaker.GetComponent<ImpactWave>();
if (wave == null)
{
wave = beaker.AddComponent<ImpactWave>();
}
wave.soundRadius = 18f;
wave.minImpactForce = 1.5f;
// Load EchoPulse prefab if available
var pulsePrefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/EchoPulse.prefab");
if (pulsePrefab != null)
{
wave.wavePrefab = pulsePrefab;
}
}
private static void CreateLighting(Transform parent)
{
// Entrance Airlock - Warning Red emergency light
CreatePointLight(parent, "Light_Decon_Red", new Vector3(0f, 3.8f, -27f), new Color(1f, 0.2f, 0.15f), 2.5f, 12f);
// South Concourse - Dim Amber light
CreatePointLight(parent, "Light_SouthConcourse", new Vector3(0f, 3.8f, -18f), new Color(1f, 0.75f, 0.4f), 1.8f, 14f);
// Cryo Archive - Cold Cyan/Blue
CreatePointLight(parent, "Light_Cryo_Cyan", new Vector3(-20f, 3.8f, -26f), new Color(0.2f, 0.7f, 1f), 1.6f, 16f);
// Security Office - Amber Terminal light
CreatePointLight(parent, "Light_Security_Amber", new Vector3(20f, 3.8f, -26f), new Color(1f, 0.65f, 0.2f), 1.8f, 16f);
// Biochem Lab - Toxic Pale Green
CreatePointLight(parent, "Light_Biochem_Green", new Vector3(-20f, 3.8f, -6f), new Color(0.35f, 0.95f, 0.5f), 2.0f, 18f);
// Surgical Theatre - Clinical Cold White
CreatePointLight(parent, "Light_Surgery_White", new Vector3(20f, 3.8f, -6f), new Color(0.85f, 0.92f, 1f), 2.2f, 18f);
// Bio-Containment Vault - Deep Pulsing Red
CreatePointLight(parent, "Light_BioContainment_Alarm", new Vector3(-20f, 3.8f, 17f), new Color(1f, 0.1f, 0.1f), 2.5f, 20f);
// Central Core Bio-Reactor - Eerie Glowing Cyan/Emerald Spotlight from above
CreatePointLight(parent, "Light_CentralReactor_Glow", new Vector3(0f, 3.8f, 17f), new Color(0.2f, 1f, 0.85f), 3.0f, 22f);
// Genetics Lab - Blue / Violet
CreatePointLight(parent, "Light_Genetics_Violet", new Vector3(20f, 3.8f, 12f), new Color(0.6f, 0.4f, 1f), 1.8f, 16f);
// Generator Room - Warning Amber
CreatePointLight(parent, "Light_Generator_Amber", new Vector3(20f, 3.8f, 25f), new Color(1f, 0.5f, 0.1f), 2.0f, 16f);
// North Crawlway Corridor lights
CreatePointLight(parent, "Light_NorthCrawl_West", new Vector3(-15f, 3.2f, 29.5f), new Color(1f, 0.7f, 0.3f), 1.2f, 10f);
CreatePointLight(parent, "Light_NorthCrawl_Mid", new Vector3(0f, 3.2f, 29.5f), new Color(1f, 0.7f, 0.3f), 1.2f, 10f);
CreatePointLight(parent, "Light_NorthCrawl_East", new Vector3(15f, 3.2f, 29.5f), new Color(1f, 0.7f, 0.3f), 1.2f, 10f);
// Serpentine Corridor Waypoint lights
CreatePointLight(parent, "Light_WestSerpentine", new Vector3(-10f, 3.5f, -8f), new Color(0.5f, 0.6f, 0.7f), 1.0f, 10f);
CreatePointLight(parent, "Light_EastSerpentine", new Vector3(10f, 3.5f, -8f), new Color(0.5f, 0.6f, 0.7f), 1.0f, 10f);
}
private static void CreatePointLight(Transform parent, string name, Vector3 pos, Color color, float intensity, float range)
{
GameObject lightGo = new GameObject(name);
lightGo.transform.SetParent(parent);
lightGo.transform.position = pos;
var light = lightGo.AddComponent<Light>();
light.type = LightType.Point;
light.color = color;
light.intensity = intensity;
light.range = range;
light.shadows = LightShadows.Soft;
}
private static void SetupPatrolWaypoints(Transform parent, GameObject enemy)
{
// Clean up any old patrol points
var oldPatrol = GameObject.Find("PatrolWaypoints");
if (oldPatrol != null)
{
Undo.DestroyObjectImmediate(oldPatrol);
}
// Also disable old 1 .. 1 (13) if present in scene root
for (int i = 0; i <= 15; i++)
{
string oldName = i == 0 ? "1" : $"1 ({i})";
var oldGo = GameObject.Find(oldName);
if (oldGo != null)
{
oldGo.SetActive(false);
}
}
GameObject patrolParent = new GameObject("PatrolWaypoints");
patrolParent.transform.SetParent(parent);
// 20 Waypoints looping smoothly through all sections of the lab!
Vector3[] waypoints = new Vector3[]
{
new Vector3(0f, 0f, -20f), // WP0: South Concourse
new Vector3(-10f, 0f, -20f), // WP1: West Concourse
new Vector3(-20f, 0f, -26f), // WP2: Cryo Archive
new Vector3(-10f, 0f, -14f), // WP3: West Serpentine South
new Vector3(-20f, 0f, -10f), // WP4: Biochem Lab South
new Vector3(-20f, 0f, -2f), // WP5: Biochem Lab North
new Vector3(-10f, 0f, 4f), // WP6: West Serpentine North
new Vector3(-20f, 0f, 12f), // WP7: Bio-Containment South
new Vector3(-20f, 0f, 22f), // WP8: Bio-Containment North
new Vector3(-15f, 0f, 29.5f), // WP9: North Crawlway West
new Vector3(0f, 0f, 29.5f), // WP10: North Crawlway Center
new Vector3(15f, 0f, 29.5f), // WP11: North Crawlway East
new Vector3(20f, 0f, 25f), // WP12: Generator Room
new Vector3(20f, 0f, 12f), // WP13: Genetics Lab
new Vector3(0f, 0f, 21f), // WP14: Central Core North
new Vector3(0f, 0f, 13f), // WP15: Central Core South
new Vector3(10f, 0f, 4f), // WP16: East Serpentine North
new Vector3(20f, 0f, -6f), // WP17: Surgical Theatre
new Vector3(10f, 0f, -14f), // WP18: East Serpentine South
new Vector3(20f, 0f, -26f) // WP19: Security Office
};
Transform[] transforms = new Transform[waypoints.Length];
for (int i = 0; i < waypoints.Length; i++)
{
var wpGo = new GameObject($"Waypoint_{i}");
wpGo.transform.SetParent(patrolParent.transform);
wpGo.transform.position = waypoints[i];
transforms[i] = wpGo.transform;
}
if (enemy != null)
{
enemy.transform.position = new Vector3(0f, 0.5f, 17f); // Start mutant in Central Core
var ai = enemy.GetComponent<BlindMutantAI>();
if (ai != null)
{
ai.patrolPoints = transforms;
Debug.Log($"Configured {transforms.Length} patrol points on BlindMutantAI.");
}
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: a3c64d1d83957dd4098c862118aabf51
@@ -0,0 +1,579 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem.UI;
using UnityEngine.Rendering.Universal;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;
public static class MainMenuSceneBuilder
{
private static DefaultControls.Resources uiResources;
private static Font standardFont;
[MenuItem("Tools/Build Main Menu Scene")]
public static string BuildScene()
{
standardFont = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
uiResources = new DefaultControls.Resources
{
standard = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/UISprite.psd"),
background = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/Background.psd"),
knob = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/Knob.psd"),
checkmark = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/Checkmark.psd"),
dropdown = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/DropdownArrow.psd"),
mask = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/UIMask.psd")
};
// Создаем новую пустую сцену
Scene newScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
// 1. Камера
GameObject camGo = new GameObject("Main Camera");
Camera cam = camGo.AddComponent<Camera>();
cam.clearFlags = CameraClearFlags.SolidColor;
cam.backgroundColor = new Color(0.035f, 0.05f, 0.075f, 1f);
camGo.AddComponent<UniversalAdditionalCameraData>();
camGo.AddComponent<AudioListener>();
camGo.tag = "MainCamera";
camGo.transform.position = new Vector3(0, 0, -10);
// 2. EventSystem
GameObject eventSysGo = new GameObject("EventSystem");
eventSysGo.AddComponent<EventSystem>();
eventSysGo.AddComponent<InputSystemUIInputModule>();
// 3. Canvas
GameObject canvasGo = new GameObject("Canvas");
Canvas canvas = canvasGo.AddComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
canvas.pixelPerfect = true;
CanvasScaler scaler = canvasGo.AddComponent<CanvasScaler>();
scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
scaler.referenceResolution = new Vector2(1920, 1080);
scaler.screenMatchMode = CanvasScaler.ScreenMatchMode.MatchWidthOrHeight;
scaler.matchWidthOrHeight = 0.5f;
canvasGo.AddComponent<GraphicRaycaster>();
// 4. Менеджер Главного Меню
GameObject managerGo = new GameObject("MainMenuManager");
MainMenuManager manager = managerGo.AddComponent<MainMenuManager>();
// 5. Задний фон Canvas
CreateImage("Background_Dark", canvasGo.transform,
new Color(0.025f, 0.04f, 0.065f, 1f),
Vector2.zero, Vector2.one, Vector2.zero, Vector2.zero);
// Декоративная подложка с мягким сине-зеленым свечением
CreateImage("Decor_Tint", canvasGo.transform,
new Color(0.00f, 0.45f, 0.60f, 0.06f),
Vector2.zero, Vector2.one, Vector2.zero, Vector2.zero);
// Декоративная неоновая полоса слева
CreateImage("AccentLine_Left", canvasGo.transform,
new Color(0.00f, 0.85f, 0.95f, 0.70f),
new Vector2(0f, 0f), new Vector2(0f, 1f),
new Vector2(6f, 0f), new Vector2(3f, 0f));
// Копирайт / версия в правом нижнем углу
CreateText("Version_Text", canvasGo.transform,
"Версия 1.0.0 | Лаборатория 'Эхо'",
14, FontStyle.Normal, TextAnchor.MiddleRight,
new Color(0.40f, 0.52f, 0.62f, 0.75f),
new Vector2(0.70f, 0.02f), new Vector2(0.98f, 0.06f), Vector2.zero, Vector2.zero);
// 6. Заголовок игры (Логотип и подзаголовок)
GameObject headerContainer = CreateEmptyRect("Header_Container", canvasGo.transform,
new Vector2(0.08f, 0.64f), new Vector2(0.55f, 0.90f), Vector2.zero, Vector2.zero);
CreateText("Title_Text", headerContainer.transform,
"ECHO // PROTOCOL",
48, FontStyle.Bold, TextAnchor.MiddleLeft,
new Color(0.92f, 0.97f, 1f, 1f),
new Vector2(0f, 0.40f), new Vector2(1f, 1f), Vector2.zero, Vector2.zero);
CreateText("Subtitle_Text", headerContainer.transform,
"ТАКТИЧЕСКИЙ СТЕЛС-ЭКШЕН • СЕКРЕТНЫЙ ОБЪЕКТ",
16, FontStyle.Normal, TextAnchor.MiddleLeft,
new Color(0.00f, 0.85f, 0.95f, 0.85f),
new Vector2(0f, 0.12f), new Vector2(1f, 0.40f), Vector2.zero, Vector2.zero);
CreateImage("Header_Divider", headerContainer.transform,
new Color(0.00f, 0.85f, 0.95f, 0.45f),
new Vector2(0f, 0.02f), new Vector2(0.85f, 0.05f), Vector2.zero, Vector2.zero);
// 7. Основная панель кнопок меню (MainMenuPanel)
GameObject mainMenuPanel = CreateEmptyRect("MainMenuPanel", canvasGo.transform,
new Vector2(0.08f, 0.18f), new Vector2(0.38f, 0.60f), Vector2.zero, Vector2.zero);
VerticalLayoutGroup menuLayout = mainMenuPanel.AddComponent<VerticalLayoutGroup>();
menuLayout.childAlignment = TextAnchor.UpperLeft;
menuLayout.spacing = 18f;
menuLayout.childControlWidth = true;
menuLayout.childControlHeight = false;
menuLayout.childForceExpandWidth = true;
menuLayout.childForceExpandHeight = false;
// Кнопка "ИГРАТЬ"
Button playBtn = CreateStyledButton("Button_Play", mainMenuPanel.transform,
"► ИГРАТЬ",
new Color(0.08f, 0.22f, 0.32f, 0.95f),
new Color(0.00f, 0.65f, 0.85f, 1.0f),
new Color(0.04f, 0.14f, 0.22f, 1.0f),
new Color(0.90f, 0.98f, 1.0f, 1.0f),
66f, 24);
// Кнопка "НАСТРОЙКИ"
Button settingsBtn = CreateStyledButton("Button_Settings", mainMenuPanel.transform,
"⚙ НАСТРОЙКИ",
new Color(0.07f, 0.12f, 0.18f, 0.90f),
new Color(0.18f, 0.38f, 0.52f, 1.0f),
new Color(0.04f, 0.08f, 0.12f, 1.0f),
new Color(0.85f, 0.92f, 0.98f, 1.0f),
62f, 22);
// Кнопка "ВЫХОД"
Button quitBtn = CreateStyledButton("Button_Quit", mainMenuPanel.transform,
"✖ ВЫХОД ИЗ ИГРЫ",
new Color(0.18f, 0.08f, 0.10f, 0.90f),
new Color(0.55f, 0.16f, 0.22f, 1.0f),
new Color(0.10f, 0.04f, 0.06f, 1.0f),
new Color(0.95f, 0.85f, 0.85f, 1.0f),
62f, 22);
// ==========================================
// 8. Панель настроек (SettingsPanel)
// ==========================================
GameObject settingsPanel = CreateEmptyRect("SettingsPanel", canvasGo.transform,
Vector2.zero, Vector2.one, Vector2.zero, Vector2.zero);
// Затемняющий фон
CreateImage("Backdrop_Dim", settingsPanel.transform,
new Color(0.01f, 0.02f, 0.03f, 0.78f),
Vector2.zero, Vector2.one, Vector2.zero, Vector2.zero);
// Модальное окно
GameObject settingsCard = CreateImage("Settings_Card", settingsPanel.transform,
new Color(0.05f, 0.08f, 0.12f, 0.98f),
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f),
new Vector2(920f, 720f), Vector2.zero);
Outline panelOutline = settingsCard.AddComponent<Outline>();
panelOutline.effectColor = new Color(0.00f, 0.85f, 0.95f, 0.50f);
panelOutline.effectDistance = new Vector2(2f, -2f);
// Заголовок панели настроек
CreateText("Settings_Header", settingsCard.transform,
"НАСТРОЙКИ СИСТЕМЫ",
28, FontStyle.Bold, TextAnchor.MiddleCenter,
new Color(0.90f, 0.97f, 1.0f, 1.0f),
new Vector2(0.05f, 0.90f), new Vector2(0.95f, 0.98f), Vector2.zero, Vector2.zero);
CreateImage("Settings_Divider", settingsCard.transform,
new Color(0.00f, 0.85f, 0.95f, 0.35f),
new Vector2(0.05f, 0.89f), new Vector2(0.95f, 0.895f), Vector2.zero, Vector2.zero);
// Контейнер списка настроек
GameObject settingsList = CreateEmptyRect("Settings_List", settingsCard.transform,
new Vector2(0.06f, 0.14f), new Vector2(0.94f, 0.87f), Vector2.zero, Vector2.zero);
VerticalLayoutGroup settingsLayout = settingsList.AddComponent<VerticalLayoutGroup>();
settingsLayout.spacing = 16f;
settingsLayout.childAlignment = TextAnchor.UpperCenter;
settingsLayout.childControlWidth = true;
settingsLayout.childControlHeight = false;
settingsLayout.childForceExpandWidth = true;
settingsLayout.childForceExpandHeight = false;
// --- Раздел: Звук ---
CreateCategoryHeader("HEADER_AUDIO", settingsList.transform, "— АУДИО И ЗВУК —");
var volumeRow = CreateSliderRow("Row_Volume", settingsList.transform, "Общая громкость", 0f, 1f, 1f, "%");
Slider volSlider = volumeRow.slider;
Text volText = volumeRow.valueText;
Toggle muteToggle = CreateToggleRow("Row_Mute", settingsList.transform, "Отключить звук (Mute)");
// --- Раздел: Графика ---
CreateCategoryHeader("HEADER_GRAPHICS", settingsList.transform, "— ГРАФИКА И ДИСПЛЕЙ —");
Dropdown qualityDropdown = CreateDropdownRow("Row_Quality", settingsList.transform, "Качество графики");
Toggle fullscreenToggle = CreateToggleRow("Row_Fullscreen", settingsList.transform, "Полноэкранный режим");
Dropdown resolutionDropdown = CreateDropdownRow("Row_Resolution", settingsList.transform, "Разрешение экрана");
// --- Раздел: Управление ---
CreateCategoryHeader("HEADER_CONTROLS", settingsList.transform, "— УПРАВЛЕНИЕ —");
var sensRow = CreateSliderRow("Row_Sensitivity", settingsList.transform, "Чувствительность мыши", 0.2f, 3.0f, 1.0f, "x");
Slider sensSlider = sensRow.slider;
Text sensText = sensRow.valueText;
// Нижняя строка кнопок в панели настроек
GameObject bottomButtonsRow = CreateEmptyRect("Settings_BottomButtons", settingsCard.transform,
new Vector2(0.06f, 0.03f), new Vector2(0.94f, 0.12f), Vector2.zero, Vector2.zero);
HorizontalLayoutGroup bottomLayout = bottomButtonsRow.AddComponent<HorizontalLayoutGroup>();
bottomLayout.spacing = 30f;
bottomLayout.childAlignment = TextAnchor.MiddleCenter;
bottomLayout.childControlWidth = true;
bottomLayout.childControlHeight = true;
bottomLayout.childForceExpandWidth = true;
bottomLayout.childForceExpandHeight = true;
Button resetBtn = CreateStyledButton("Button_ResetDefaults", bottomButtonsRow.transform,
"Сбросить настройки",
new Color(0.18f, 0.12f, 0.14f, 0.95f),
new Color(0.35f, 0.18f, 0.22f, 1.0f),
new Color(0.12f, 0.06f, 0.08f, 1.0f),
new Color(0.95f, 0.85f, 0.85f, 1.0f),
50f, 18);
Button backBtn = CreateStyledButton("Button_Back", bottomButtonsRow.transform,
"✔ НАЗАД В МЕНЮ",
new Color(0.08f, 0.22f, 0.30f, 0.95f),
new Color(0.00f, 0.65f, 0.85f, 1.0f),
new Color(0.05f, 0.14f, 0.20f, 1.0f),
new Color(0.90f, 0.98f, 1.0f, 1.0f),
50f, 20);
// ==========================================
// 9. Панель загрузки (LoadingPanel)
// ==========================================
GameObject loadingPanel = CreateImage("LoadingPanel", canvasGo.transform,
new Color(0.02f, 0.03f, 0.05f, 0.97f),
Vector2.zero, Vector2.one, Vector2.zero, Vector2.zero);
GameObject loadingContainer = CreateEmptyRect("Loading_Container", loadingPanel.transform,
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f),
new Vector2(600f, 200f), Vector2.zero);
CreateText("Loading_Title", loadingContainer.transform,
"ЗАГРУЗКА МИССИИ...",
28, FontStyle.Bold, TextAnchor.MiddleCenter,
new Color(0.00f, 0.85f, 0.95f, 1.0f),
new Vector2(0f, 0.60f), new Vector2(1f, 1f), Vector2.zero, Vector2.zero);
GameObject sliderObj = DefaultControls.CreateSlider(uiResources);
sliderObj.name = "Loading_ProgressBar";
sliderObj.transform.SetParent(loadingContainer.transform, false);
RectTransform sliderRt = sliderObj.GetComponent<RectTransform>();
sliderRt.anchorMin = new Vector2(0.05f, 0.35f);
sliderRt.anchorMax = new Vector2(0.95f, 0.55f);
sliderRt.offsetMin = Vector2.zero;
sliderRt.offsetMax = Vector2.zero;
Slider loadingSlider = sliderObj.GetComponent<Slider>();
loadingSlider.interactable = false;
Transform fillTransform = sliderObj.transform.Find("Fill Area/Fill");
if (fillTransform != null)
{
Image fillImg = fillTransform.GetComponent<Image>();
if (fillImg != null) fillImg.color = new Color(0.00f, 0.85f, 0.95f, 1f);
}
GameObject loadingPercent = CreateText("Loading_Text", loadingContainer.transform,
"0%",
18, FontStyle.Normal, TextAnchor.MiddleCenter,
new Color(0.80f, 0.90f, 1.0f, 0.9f),
new Vector2(0f, 0f), new Vector2(1f, 0.30f), Vector2.zero, Vector2.zero);
Text loadingText = loadingPercent.GetComponent<Text>();
// ==========================================
// 10. Привязка ссылок к MainMenuManager
// ==========================================
manager.headerContainer = headerContainer;
manager.mainMenuPanel = mainMenuPanel;
manager.settingsPanel = settingsPanel;
manager.loadingPanel = loadingPanel;
manager.gameSceneName = "SampleScene";
manager.loadingSlider = loadingSlider;
manager.loadingText = loadingText;
manager.volumeSlider = volSlider;
manager.volumeValueText = volText;
manager.muteToggle = muteToggle;
manager.qualityDropdown = qualityDropdown;
manager.fullscreenToggle = fullscreenToggle;
manager.resolutionDropdown = resolutionDropdown;
manager.sensitivitySlider = sensSlider;
manager.sensitivityValueText = sensText;
UnityEditor.Events.UnityEventTools.AddPersistentListener(playBtn.onClick, manager.PlayGame);
UnityEditor.Events.UnityEventTools.AddPersistentListener(settingsBtn.onClick, manager.OpenSettings);
UnityEditor.Events.UnityEventTools.AddPersistentListener(quitBtn.onClick, manager.QuitGame);
UnityEditor.Events.UnityEventTools.AddPersistentListener(backBtn.onClick, manager.CloseSettings);
UnityEditor.Events.UnityEventTools.AddPersistentListener(resetBtn.onClick, manager.ResetToDefaults);
// Изначальная видимость панелей
headerContainer.SetActive(true);
mainMenuPanel.SetActive(true);
settingsPanel.SetActive(false);
loadingPanel.SetActive(false);
// 11. Сохранение сцены и Build Settings
string scenePath = "Assets/Scenes/MainMenu.unity";
EditorSceneManager.SaveScene(newScene, scenePath);
Debug.Log("[MainMenuSceneBuilder] Сцена создана: " + scenePath);
List<EditorBuildSettingsScene> buildScenes = new List<EditorBuildSettingsScene>();
buildScenes.Add(new EditorBuildSettingsScene(scenePath, true));
buildScenes.Add(new EditorBuildSettingsScene("Assets/Scenes/SampleScene.unity", true));
EditorBuildSettings.scenes = buildScenes.ToArray();
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
return "SUCCESS: MainMenu created and configured!";
}
#region Хелперы создания UI элементов
private static GameObject CreateEmptyRect(string name, Transform parent, Vector2 anchorMin, Vector2 anchorMax, Vector2 sizeDelta, Vector2 anchoredPosition)
{
GameObject go = new GameObject(name, typeof(RectTransform));
go.transform.SetParent(parent, false);
RectTransform rt = go.GetComponent<RectTransform>();
rt.anchorMin = anchorMin;
rt.anchorMax = anchorMax;
rt.sizeDelta = sizeDelta;
rt.anchoredPosition = anchoredPosition;
return go;
}
private static GameObject CreateImage(string name, Transform parent, Color color, Vector2 anchorMin, Vector2 anchorMax, Vector2 sizeDelta, Vector2 anchoredPosition)
{
GameObject go = CreateEmptyRect(name, parent, anchorMin, anchorMax, sizeDelta, anchoredPosition);
Image img = go.AddComponent<Image>();
img.color = color;
img.sprite = uiResources.background;
img.type = Image.Type.Sliced;
return go;
}
private static GameObject CreateText(string name, Transform parent, string text, int fontSize, FontStyle style, TextAnchor alignment, Color color, Vector2 anchorMin, Vector2 anchorMax, Vector2 sizeDelta, Vector2 anchoredPosition)
{
GameObject go = CreateEmptyRect(name, parent, anchorMin, anchorMax, sizeDelta, anchoredPosition);
Text t = go.AddComponent<Text>();
t.font = standardFont;
t.text = text;
t.fontSize = fontSize;
t.fontStyle = style;
t.alignment = alignment;
t.color = color;
t.horizontalOverflow = HorizontalWrapMode.Wrap;
t.verticalOverflow = VerticalWrapMode.Overflow;
return go;
}
private static Button CreateStyledButton(string name, Transform parent, string label, Color normalColor, Color highlightedColor, Color pressedColor, Color textColor, float height, int fontSize)
{
GameObject btnObj = DefaultControls.CreateButton(uiResources);
btnObj.name = name;
btnObj.transform.SetParent(parent, false);
LayoutElement layout = btnObj.AddComponent<LayoutElement>();
layout.minHeight = height;
layout.preferredHeight = height;
Image img = btnObj.GetComponent<Image>();
img.color = normalColor;
img.type = Image.Type.Sliced;
Button btn = btnObj.GetComponent<Button>();
ColorBlock colors = btn.colors;
colors.normalColor = normalColor;
colors.highlightedColor = highlightedColor;
colors.pressedColor = pressedColor;
colors.selectedColor = highlightedColor;
colors.colorMultiplier = 1f;
colors.fadeDuration = 0.12f;
btn.colors = colors;
Text text = btnObj.GetComponentInChildren<Text>();
if (text != null)
{
text.font = standardFont;
text.text = label;
text.fontSize = fontSize;
text.fontStyle = FontStyle.Bold;
text.color = textColor;
text.alignment = TextAnchor.MiddleCenter;
}
return btn;
}
private static void CreateCategoryHeader(string name, Transform parent, string text)
{
GameObject go = CreateEmptyRect(name, parent, Vector2.zero, Vector2.one, new Vector2(0f, 32f), Vector2.zero);
LayoutElement layout = go.AddComponent<LayoutElement>();
layout.minHeight = 32f;
layout.preferredHeight = 32f;
Text t = go.AddComponent<Text>();
t.font = standardFont;
t.text = text;
t.fontSize = 17;
t.fontStyle = FontStyle.Bold;
t.alignment = TextAnchor.MiddleLeft;
t.color = new Color(0.00f, 0.85f, 0.95f, 0.95f);
}
private struct SliderRow
{
public Slider slider;
public Text valueText;
}
private static SliderRow CreateSliderRow(string name, Transform parent, string label, float min, float max, float def, string unit)
{
GameObject row = CreateEmptyRect(name, parent, Vector2.zero, Vector2.one, new Vector2(0f, 42f), Vector2.zero);
LayoutElement layout = row.AddComponent<LayoutElement>();
layout.minHeight = 42f;
layout.preferredHeight = 42f;
HorizontalLayoutGroup hLayout = row.AddComponent<HorizontalLayoutGroup>();
hLayout.spacing = 18f;
hLayout.childAlignment = TextAnchor.MiddleLeft;
hLayout.childControlWidth = false;
hLayout.childControlHeight = true;
hLayout.childForceExpandWidth = false;
hLayout.childForceExpandHeight = true;
// Метка названия
GameObject lblGo = CreateEmptyRect("Label", row.transform, Vector2.zero, Vector2.one, new Vector2(280f, 42f), Vector2.zero);
LayoutElement lblLayout = lblGo.AddComponent<LayoutElement>();
lblLayout.minWidth = 280f;
lblLayout.preferredWidth = 280f;
Text lbl = lblGo.AddComponent<Text>();
lbl.font = standardFont;
lbl.text = label;
lbl.fontSize = 18;
lbl.alignment = TextAnchor.MiddleLeft;
lbl.color = new Color(0.85f, 0.92f, 0.98f, 1f);
// Slider
GameObject sliderObj = DefaultControls.CreateSlider(uiResources);
sliderObj.name = "Slider";
sliderObj.transform.SetParent(row.transform, false);
LayoutElement sliderLayout = sliderObj.AddComponent<LayoutElement>();
sliderLayout.minWidth = 360f;
sliderLayout.preferredWidth = 360f;
Slider slider = sliderObj.GetComponent<Slider>();
slider.minValue = min;
slider.maxValue = max;
slider.value = def;
// Значение текстом
GameObject valGo = CreateEmptyRect("ValueText", row.transform, Vector2.zero, Vector2.one, new Vector2(90f, 42f), Vector2.zero);
LayoutElement valLayout = valGo.AddComponent<LayoutElement>();
valLayout.minWidth = 90f;
valLayout.preferredWidth = 90f;
Text valText = valGo.AddComponent<Text>();
valText.font = standardFont;
valText.text = unit == "%" ? $"{Mathf.RoundToInt(def * 100)}%" : $"{def:F1}{unit}";
valText.fontSize = 18;
valText.fontStyle = FontStyle.Bold;
valText.alignment = TextAnchor.MiddleCenter;
valText.color = new Color(0.00f, 0.85f, 0.95f, 1f);
return new SliderRow { slider = slider, valueText = valText };
}
private static Toggle CreateToggleRow(string name, Transform parent, string label)
{
GameObject row = CreateEmptyRect(name, parent, Vector2.zero, Vector2.one, new Vector2(0f, 40f), Vector2.zero);
LayoutElement layout = row.AddComponent<LayoutElement>();
layout.minHeight = 40f;
layout.preferredHeight = 40f;
HorizontalLayoutGroup hLayout = row.AddComponent<HorizontalLayoutGroup>();
hLayout.spacing = 18f;
hLayout.childAlignment = TextAnchor.MiddleLeft;
hLayout.childControlWidth = false;
hLayout.childControlHeight = true;
hLayout.childForceExpandWidth = false;
hLayout.childForceExpandHeight = true;
// Метка названия
GameObject lblGo = CreateEmptyRect("Label", row.transform, Vector2.zero, Vector2.one, new Vector2(280f, 40f), Vector2.zero);
LayoutElement lblLayout = lblGo.AddComponent<LayoutElement>();
lblLayout.minWidth = 280f;
lblLayout.preferredWidth = 280f;
Text lbl = lblGo.AddComponent<Text>();
lbl.font = standardFont;
lbl.text = label;
lbl.fontSize = 18;
lbl.alignment = TextAnchor.MiddleLeft;
lbl.color = new Color(0.85f, 0.92f, 0.98f, 1f);
// Toggle
GameObject toggleObj = DefaultControls.CreateToggle(uiResources);
toggleObj.name = "Toggle";
toggleObj.transform.SetParent(row.transform, false);
LayoutElement toggleLayout = toggleObj.AddComponent<LayoutElement>();
toggleLayout.minWidth = 50f;
toggleLayout.preferredWidth = 50f;
Text toggleLabel = toggleObj.GetComponentInChildren<Text>();
if (toggleLabel != null) toggleLabel.text = "";
Toggle toggle = toggleObj.GetComponent<Toggle>();
return toggle;
}
private static Dropdown CreateDropdownRow(string name, Transform parent, string label)
{
GameObject row = CreateEmptyRect(name, parent, Vector2.zero, Vector2.one, new Vector2(0f, 44f), Vector2.zero);
LayoutElement layout = row.AddComponent<LayoutElement>();
layout.minHeight = 44f;
layout.preferredHeight = 44f;
HorizontalLayoutGroup hLayout = row.AddComponent<HorizontalLayoutGroup>();
hLayout.spacing = 18f;
hLayout.childAlignment = TextAnchor.MiddleLeft;
hLayout.childControlWidth = false;
hLayout.childControlHeight = true;
hLayout.childForceExpandWidth = false;
hLayout.childForceExpandHeight = true;
// Метка названия
GameObject lblGo = CreateEmptyRect("Label", row.transform, Vector2.zero, Vector2.one, new Vector2(280f, 44f), Vector2.zero);
LayoutElement lblLayout = lblGo.AddComponent<LayoutElement>();
lblLayout.minWidth = 280f;
lblLayout.preferredWidth = 280f;
Text lbl = lblGo.AddComponent<Text>();
lbl.font = standardFont;
lbl.text = label;
lbl.fontSize = 18;
lbl.alignment = TextAnchor.MiddleLeft;
lbl.color = new Color(0.85f, 0.92f, 0.98f, 1f);
// Dropdown
GameObject dropdownObj = DefaultControls.CreateDropdown(uiResources);
dropdownObj.name = "Dropdown";
dropdownObj.transform.SetParent(row.transform, false);
LayoutElement ddLayout = dropdownObj.AddComponent<LayoutElement>();
ddLayout.minWidth = 420f;
ddLayout.preferredWidth = 420f;
Dropdown dropdown = dropdownObj.GetComponent<Dropdown>();
Text caption = dropdown.captionText;
if (caption != null) caption.font = standardFont;
Text item = dropdown.itemText;
if (item != null) item.font = standardFont;
return dropdown;
}
#endregion
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1f74c7b4416e74b48a61ff45e7b3c88e
+462
View File
@@ -0,0 +1,462 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem.UI;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;
public static class PauseMenuBuilder
{
private static DefaultControls.Resources uiResources;
private static Font standardFont;
[MenuItem("Tools/Add Pause Menu to SampleScene")]
public static string Build()
{
standardFont = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
uiResources = new DefaultControls.Resources
{
standard = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/UISprite.psd"),
background = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/Background.psd"),
knob = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/Knob.psd"),
checkmark = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/Checkmark.psd"),
dropdown = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/DropdownArrow.psd"),
mask = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/UIMask.psd")
};
// Открываем сцену геймплея
Scene gameplayScene = EditorSceneManager.OpenScene("Assets/Scenes/SampleScene.unity", OpenSceneMode.Single);
// Проверяем, есть ли уже EventSystem
if (Object.FindAnyObjectByType<EventSystem>() == null)
{
GameObject esGo = new GameObject("EventSystem");
esGo.AddComponent<EventSystem>();
esGo.AddComponent<InputSystemUIInputModule>();
}
// Удаляем старый PauseMenu, если был
var old = GameObject.Find("PauseCanvas");
if (old != null) Object.DestroyImmediate(old);
// Создаем Canvas паузы
GameObject canvasGo = new GameObject("PauseCanvas");
Canvas canvas = canvasGo.AddComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
canvas.sortingOrder = 100; // Поверх всего
CanvasScaler scaler = canvasGo.AddComponent<CanvasScaler>();
scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
scaler.referenceResolution = new Vector2(1920, 1080);
scaler.screenMatchMode = CanvasScaler.ScreenMatchMode.MatchWidthOrHeight;
scaler.matchWidthOrHeight = 0.5f;
canvasGo.AddComponent<GraphicRaycaster>();
PauseMenu pauseMenu = canvasGo.AddComponent<PauseMenu>();
// 1. Панель паузы (PauseMenuPanel)
GameObject pausePanel = CreateImage("PauseMenuPanel", canvasGo.transform,
new Color(0.02f, 0.035f, 0.055f, 0.88f),
Vector2.zero, Vector2.one, Vector2.zero, Vector2.zero);
GameObject card = CreateImage("Pause_Card", pausePanel.transform,
new Color(0.06f, 0.09f, 0.14f, 0.98f),
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f),
new Vector2(460f, 520f), Vector2.zero);
Outline outline = card.AddComponent<Outline>();
outline.effectColor = new Color(0.00f, 0.85f, 0.95f, 0.45f);
outline.effectDistance = new Vector2(2f, -2f);
CreateText("Pause_Title", card.transform,
"ПАУЗА",
34, FontStyle.Bold, TextAnchor.MiddleCenter,
new Color(0.92f, 0.97f, 1f, 1f),
new Vector2(0.05f, 0.84f), new Vector2(0.95f, 0.96f), Vector2.zero, Vector2.zero);
CreateImage("Pause_Divider", card.transform,
new Color(0.00f, 0.85f, 0.95f, 0.40f),
new Vector2(0.10f, 0.82f), new Vector2(0.90f, 0.825f), Vector2.zero, Vector2.zero);
GameObject btnContainer = CreateEmptyRect("Buttons_Container", card.transform,
new Vector2(0.08f, 0.06f), new Vector2(0.92f, 0.78f), Vector2.zero, Vector2.zero);
VerticalLayoutGroup vLayout = btnContainer.AddComponent<VerticalLayoutGroup>();
vLayout.spacing = 16f;
vLayout.childAlignment = TextAnchor.MiddleCenter;
vLayout.childControlWidth = true;
vLayout.childControlHeight = false;
vLayout.childForceExpandWidth = true;
vLayout.childForceExpandHeight = false;
Button resumeBtn = CreateStyledButton("Btn_Resume", btnContainer.transform,
"► ПРОДОЛЖИТЬ",
new Color(0.08f, 0.22f, 0.32f, 0.95f),
new Color(0.00f, 0.65f, 0.85f, 1.0f),
new Color(0.04f, 0.14f, 0.22f, 1.0f),
new Color(0.90f, 0.98f, 1.0f, 1.0f),
60f, 22);
Button settingsBtn = CreateStyledButton("Btn_Settings", btnContainer.transform,
"⚙ НАСТРОЙКИ",
new Color(0.07f, 0.12f, 0.18f, 0.90f),
new Color(0.18f, 0.38f, 0.52f, 1.0f),
new Color(0.04f, 0.08f, 0.12f, 1.0f),
new Color(0.85f, 0.92f, 0.98f, 1.0f),
56f, 20);
Button menuBtn = CreateStyledButton("Btn_MainMenu", btnContainer.transform,
"⌂ ГЛАВНОЕ МЕНЮ",
new Color(0.07f, 0.12f, 0.18f, 0.90f),
new Color(0.18f, 0.38f, 0.52f, 1.0f),
new Color(0.04f, 0.08f, 0.12f, 1.0f),
new Color(0.85f, 0.92f, 0.98f, 1.0f),
56f, 20);
Button quitBtn = CreateStyledButton("Btn_Quit", btnContainer.transform,
"✖ ВЫХОД ИЗ ИГРЫ",
new Color(0.18f, 0.08f, 0.10f, 0.90f),
new Color(0.55f, 0.16f, 0.22f, 1.0f),
new Color(0.10f, 0.04f, 0.06f, 1.0f),
new Color(0.95f, 0.85f, 0.85f, 1.0f),
56f, 20);
// 2. Панель настроек (SettingsPanel)
GameObject settingsPanel = CreateEmptyRect("SettingsPanel", canvasGo.transform,
Vector2.zero, Vector2.one, Vector2.zero, Vector2.zero);
CreateImage("Backdrop_Dim", settingsPanel.transform,
new Color(0.01f, 0.02f, 0.03f, 0.80f),
Vector2.zero, Vector2.one, Vector2.zero, Vector2.zero);
GameObject settingsCard = CreateImage("Settings_Card", settingsPanel.transform,
new Color(0.05f, 0.08f, 0.12f, 0.98f),
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f),
new Vector2(880f, 680f), Vector2.zero);
Outline setOutline = settingsCard.AddComponent<Outline>();
setOutline.effectColor = new Color(0.00f, 0.85f, 0.95f, 0.50f);
setOutline.effectDistance = new Vector2(2f, -2f);
CreateText("Settings_Header", settingsCard.transform,
"НАСТРОЙКИ",
28, FontStyle.Bold, TextAnchor.MiddleCenter,
new Color(0.90f, 0.97f, 1.0f, 1.0f),
new Vector2(0.05f, 0.90f), new Vector2(0.95f, 0.98f), Vector2.zero, Vector2.zero);
CreateImage("Settings_Divider", settingsCard.transform,
new Color(0.00f, 0.85f, 0.95f, 0.35f),
new Vector2(0.05f, 0.89f), new Vector2(0.95f, 0.895f), Vector2.zero, Vector2.zero);
GameObject settingsList = CreateEmptyRect("Settings_List", settingsCard.transform,
new Vector2(0.06f, 0.14f), new Vector2(0.94f, 0.87f), Vector2.zero, Vector2.zero);
VerticalLayoutGroup sLayout = settingsList.AddComponent<VerticalLayoutGroup>();
sLayout.spacing = 16f;
sLayout.childAlignment = TextAnchor.UpperCenter;
sLayout.childControlWidth = true;
sLayout.childControlHeight = false;
sLayout.childForceExpandWidth = true;
sLayout.childForceExpandHeight = false;
// Разделы
CreateCategoryHeader("HEADER_AUDIO", settingsList.transform, "— АУДИО —");
var volumeRow = CreateSliderRow("Row_Volume", settingsList.transform, "Общая громкость", 0f, 1f, 1f, "%");
Toggle muteToggle = CreateToggleRow("Row_Mute", settingsList.transform, "Отключить звук");
CreateCategoryHeader("HEADER_GRAPHICS", settingsList.transform, "— ГРАФИКА —");
Dropdown qualityDropdown = CreateDropdownRow("Row_Quality", settingsList.transform, "Качество графики");
Toggle fullscreenToggle = CreateToggleRow("Row_Fullscreen", settingsList.transform, "Полноэкранный режим");
CreateCategoryHeader("HEADER_CONTROLS", settingsList.transform, "— УПРАВЛЕНИЕ —");
var sensRow = CreateSliderRow("Row_Sensitivity", settingsList.transform, "Чувствительность мыши", 0.2f, 3.0f, 1.0f, "x");
GameObject botRow = CreateEmptyRect("Settings_BottomButtons", settingsCard.transform,
new Vector2(0.06f, 0.03f), new Vector2(0.94f, 0.12f), Vector2.zero, Vector2.zero);
HorizontalLayoutGroup bLayout = botRow.AddComponent<HorizontalLayoutGroup>();
bLayout.spacing = 30f;
bLayout.childAlignment = TextAnchor.MiddleCenter;
bLayout.childControlWidth = true;
bLayout.childControlHeight = true;
Button backBtn = CreateStyledButton("Button_Back", botRow.transform,
"✔ НАЗАД В ПАУЗУ",
new Color(0.08f, 0.22f, 0.30f, 0.95f),
new Color(0.00f, 0.65f, 0.85f, 1.0f),
new Color(0.05f, 0.14f, 0.20f, 1.0f),
new Color(0.90f, 0.98f, 1.0f, 1.0f),
48f, 18);
// Привязываем ссылки
pauseMenu.pauseMenuPanel = pausePanel;
pauseMenu.settingsPanel = settingsPanel;
pauseMenu.volumeSlider = volumeRow.slider;
pauseMenu.volumeValueText = volumeRow.valueText;
pauseMenu.muteToggle = muteToggle;
pauseMenu.qualityDropdown = qualityDropdown;
pauseMenu.fullscreenToggle = fullscreenToggle;
pauseMenu.sensitivitySlider = sensRow.slider;
pauseMenu.sensitivityValueText = sensRow.valueText;
UnityEditor.Events.UnityEventTools.AddPersistentListener(resumeBtn.onClick, pauseMenu.ResumeGame);
UnityEditor.Events.UnityEventTools.AddPersistentListener(settingsBtn.onClick, pauseMenu.OpenSettings);
UnityEditor.Events.UnityEventTools.AddPersistentListener(menuBtn.onClick, pauseMenu.ReturnToMainMenu);
UnityEditor.Events.UnityEventTools.AddPersistentListener(quitBtn.onClick, pauseMenu.QuitGame);
UnityEditor.Events.UnityEventTools.AddPersistentListener(backBtn.onClick, pauseMenu.CloseSettings);
pausePanel.SetActive(false);
settingsPanel.SetActive(false);
// Сохраняем сцену геймплея
EditorSceneManager.SaveScene(gameplayScene);
Debug.Log("[PauseMenuBuilder] PauseMenu успешно добавлен в SampleScene.unity");
// Открываем обратно сцену MainMenu
EditorSceneManager.OpenScene("Assets/Scenes/MainMenu.unity", OpenSceneMode.Single);
return "SUCCESS: PauseMenu added to SampleScene and MainMenu restored!";
}
#region Хелперы UI
private static GameObject CreateEmptyRect(string name, Transform parent, Vector2 anchorMin, Vector2 anchorMax, Vector2 sizeDelta, Vector2 anchoredPosition)
{
GameObject go = new GameObject(name, typeof(RectTransform));
go.transform.SetParent(parent, false);
RectTransform rt = go.GetComponent<RectTransform>();
rt.anchorMin = anchorMin;
rt.anchorMax = anchorMax;
rt.sizeDelta = sizeDelta;
rt.anchoredPosition = anchoredPosition;
return go;
}
private static GameObject CreateImage(string name, Transform parent, Color color, Vector2 anchorMin, Vector2 anchorMax, Vector2 sizeDelta, Vector2 anchoredPosition)
{
GameObject go = CreateEmptyRect(name, parent, anchorMin, anchorMax, sizeDelta, anchoredPosition);
Image img = go.AddComponent<Image>();
img.color = color;
img.sprite = uiResources.background;
img.type = Image.Type.Sliced;
return go;
}
private static GameObject CreateText(string name, Transform parent, string text, int fontSize, FontStyle style, TextAnchor alignment, Color color, Vector2 anchorMin, Vector2 anchorMax, Vector2 sizeDelta, Vector2 anchoredPosition)
{
GameObject go = CreateEmptyRect(name, parent, anchorMin, anchorMax, sizeDelta, anchoredPosition);
Text t = go.AddComponent<Text>();
t.font = standardFont;
t.text = text;
t.fontSize = fontSize;
t.fontStyle = style;
t.alignment = alignment;
t.color = color;
t.horizontalOverflow = HorizontalWrapMode.Wrap;
t.verticalOverflow = VerticalWrapMode.Overflow;
return go;
}
private static Button CreateStyledButton(string name, Transform parent, string label, Color normalColor, Color highlightedColor, Color pressedColor, Color textColor, float height, int fontSize)
{
GameObject btnObj = DefaultControls.CreateButton(uiResources);
btnObj.name = name;
btnObj.transform.SetParent(parent, false);
LayoutElement layout = btnObj.AddComponent<LayoutElement>();
layout.minHeight = height;
layout.preferredHeight = height;
Image img = btnObj.GetComponent<Image>();
img.color = normalColor;
img.type = Image.Type.Sliced;
Button btn = btnObj.GetComponent<Button>();
ColorBlock colors = btn.colors;
colors.normalColor = normalColor;
colors.highlightedColor = highlightedColor;
colors.pressedColor = pressedColor;
colors.selectedColor = highlightedColor;
colors.colorMultiplier = 1f;
colors.fadeDuration = 0.12f;
btn.colors = colors;
Text text = btnObj.GetComponentInChildren<Text>();
if (text != null)
{
text.font = standardFont;
text.text = label;
text.fontSize = fontSize;
text.fontStyle = FontStyle.Bold;
text.color = textColor;
text.alignment = TextAnchor.MiddleCenter;
}
return btn;
}
private static void CreateCategoryHeader(string name, Transform parent, string text)
{
GameObject go = CreateEmptyRect(name, parent, Vector2.zero, Vector2.one, new Vector2(0f, 30f), Vector2.zero);
LayoutElement layout = go.AddComponent<LayoutElement>();
layout.minHeight = 30f;
layout.preferredHeight = 30f;
Text t = go.AddComponent<Text>();
t.font = standardFont;
t.text = text;
t.fontSize = 16;
t.fontStyle = FontStyle.Bold;
t.alignment = TextAnchor.MiddleLeft;
t.color = new Color(0.00f, 0.85f, 0.95f, 0.95f);
}
private struct SliderRow
{
public Slider slider;
public Text valueText;
}
private static SliderRow CreateSliderRow(string name, Transform parent, string label, float min, float max, float def, string unit)
{
GameObject row = CreateEmptyRect(name, parent, Vector2.zero, Vector2.one, new Vector2(0f, 40f), Vector2.zero);
LayoutElement layout = row.AddComponent<LayoutElement>();
layout.minHeight = 40f;
layout.preferredHeight = 40f;
HorizontalLayoutGroup hLayout = row.AddComponent<HorizontalLayoutGroup>();
hLayout.spacing = 18f;
hLayout.childAlignment = TextAnchor.MiddleLeft;
hLayout.childControlWidth = false;
hLayout.childControlHeight = true;
hLayout.childForceExpandWidth = false;
hLayout.childForceExpandHeight = true;
GameObject lblGo = CreateEmptyRect("Label", row.transform, Vector2.zero, Vector2.one, new Vector2(260f, 40f), Vector2.zero);
LayoutElement lblLayout = lblGo.AddComponent<LayoutElement>();
lblLayout.minWidth = 260f;
lblLayout.preferredWidth = 260f;
Text lbl = lblGo.AddComponent<Text>();
lbl.font = standardFont;
lbl.text = label;
lbl.fontSize = 17;
lbl.alignment = TextAnchor.MiddleLeft;
lbl.color = new Color(0.85f, 0.92f, 0.98f, 1f);
GameObject sliderObj = DefaultControls.CreateSlider(uiResources);
sliderObj.name = "Slider";
sliderObj.transform.SetParent(row.transform, false);
LayoutElement sliderLayout = sliderObj.AddComponent<LayoutElement>();
sliderLayout.minWidth = 360f;
sliderLayout.preferredWidth = 360f;
Slider slider = sliderObj.GetComponent<Slider>();
slider.minValue = min;
slider.maxValue = max;
slider.value = def;
GameObject valGo = CreateEmptyRect("ValueText", row.transform, Vector2.zero, Vector2.one, new Vector2(80f, 40f), Vector2.zero);
LayoutElement valLayout = valGo.AddComponent<LayoutElement>();
valLayout.minWidth = 80f;
valLayout.preferredWidth = 80f;
Text valText = valGo.AddComponent<Text>();
valText.font = standardFont;
valText.text = unit == "%" ? $"{Mathf.RoundToInt(def * 100)}%" : $"{def:F1}{unit}";
valText.fontSize = 17;
valText.fontStyle = FontStyle.Bold;
valText.alignment = TextAnchor.MiddleCenter;
valText.color = new Color(0.00f, 0.85f, 0.95f, 1f);
return new SliderRow { slider = slider, valueText = valText };
}
private static Toggle CreateToggleRow(string name, Transform parent, string label)
{
GameObject row = CreateEmptyRect(name, parent, Vector2.zero, Vector2.one, new Vector2(0f, 38f), Vector2.zero);
LayoutElement layout = row.AddComponent<LayoutElement>();
layout.minHeight = 38f;
layout.preferredHeight = 38f;
HorizontalLayoutGroup hLayout = row.AddComponent<HorizontalLayoutGroup>();
hLayout.spacing = 18f;
hLayout.childAlignment = TextAnchor.MiddleLeft;
hLayout.childControlWidth = false;
hLayout.childControlHeight = true;
hLayout.childForceExpandWidth = false;
hLayout.childForceExpandHeight = true;
GameObject lblGo = CreateEmptyRect("Label", row.transform, Vector2.zero, Vector2.one, new Vector2(260f, 38f), Vector2.zero);
LayoutElement lblLayout = lblGo.AddComponent<LayoutElement>();
lblLayout.minWidth = 260f;
lblLayout.preferredWidth = 260f;
Text lbl = lblGo.AddComponent<Text>();
lbl.font = standardFont;
lbl.text = label;
lbl.fontSize = 17;
lbl.alignment = TextAnchor.MiddleLeft;
lbl.color = new Color(0.85f, 0.92f, 0.98f, 1f);
GameObject toggleObj = DefaultControls.CreateToggle(uiResources);
toggleObj.name = "Toggle";
toggleObj.transform.SetParent(row.transform, false);
LayoutElement toggleLayout = toggleObj.AddComponent<LayoutElement>();
toggleLayout.minWidth = 50f;
toggleLayout.preferredWidth = 50f;
Text toggleLabel = toggleObj.GetComponentInChildren<Text>();
if (toggleLabel != null) toggleLabel.text = "";
return toggleObj.GetComponent<Toggle>();
}
private static Dropdown CreateDropdownRow(string name, Transform parent, string label)
{
GameObject row = CreateEmptyRect(name, parent, Vector2.zero, Vector2.one, new Vector2(0f, 42f), Vector2.zero);
LayoutElement layout = row.AddComponent<LayoutElement>();
layout.minHeight = 42f;
layout.preferredHeight = 42f;
HorizontalLayoutGroup hLayout = row.AddComponent<HorizontalLayoutGroup>();
hLayout.spacing = 18f;
hLayout.childAlignment = TextAnchor.MiddleLeft;
hLayout.childControlWidth = false;
hLayout.childControlHeight = true;
hLayout.childForceExpandWidth = false;
hLayout.childForceExpandHeight = true;
GameObject lblGo = CreateEmptyRect("Label", row.transform, Vector2.zero, Vector2.one, new Vector2(260f, 42f), Vector2.zero);
LayoutElement lblLayout = lblGo.AddComponent<LayoutElement>();
lblLayout.minWidth = 260f;
lblLayout.preferredWidth = 260f;
Text lbl = lblGo.AddComponent<Text>();
lbl.font = standardFont;
lbl.text = label;
lbl.fontSize = 17;
lbl.alignment = TextAnchor.MiddleLeft;
lbl.color = new Color(0.85f, 0.92f, 0.98f, 1f);
GameObject dropdownObj = DefaultControls.CreateDropdown(uiResources);
dropdownObj.name = "Dropdown";
dropdownObj.transform.SetParent(row.transform, false);
LayoutElement ddLayout = dropdownObj.AddComponent<LayoutElement>();
ddLayout.minWidth = 380f;
ddLayout.preferredWidth = 380f;
Dropdown dropdown = dropdownObj.GetComponent<Dropdown>();
Text caption = dropdown.captionText;
if (caption != null) caption.font = standardFont;
Text item = dropdown.itemText;
if (item != null) item.font = standardFont;
return dropdown;
}
#endregion
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b79d9f06926eeac4e9bbcdc7b7ca7bba
+140
View File
@@ -0,0 +1,140 @@
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public static class SetupHealthBarHUD
{
[MenuItem("Tools/Setup Health Bar HUD")]
public static void Setup()
{
var existingCanvas = GameObject.Find("HUD_Canvas");
if (existingCanvas != null)
{
Object.DestroyImmediate(existingCanvas);
}
// Canvas
GameObject canvasGo = new GameObject("HUD_Canvas");
Canvas canvas = canvasGo.AddComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
CanvasScaler scaler = canvasGo.AddComponent<CanvasScaler>();
scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
scaler.referenceResolution = new Vector2(1920, 1080);
scaler.matchWidthOrHeight = 0.5f;
canvasGo.AddComponent<GraphicRaycaster>();
// EventSystem
if (Object.FindAnyObjectByType<EventSystem>() == null)
{
GameObject esGo = new GameObject("EventSystem");
esGo.AddComponent<EventSystem>();
esGo.AddComponent<UnityEngine.InputSystem.UI.InputSystemUIInputModule>();
Undo.RegisterCreatedObjectUndo(esGo, "Create EventSystem");
}
// HealthBar Root Container (Top-Right)
GameObject hbContainer = new GameObject("HealthBar", typeof(RectTransform));
hbContainer.transform.SetParent(canvasGo.transform, false);
RectTransform hbRect = hbContainer.GetComponent<RectTransform>();
hbRect.anchorMin = new Vector2(1f, 1f);
hbRect.anchorMax = new Vector2(1f, 1f);
hbRect.pivot = new Vector2(1f, 1f);
hbRect.anchoredPosition = new Vector2(-40f, -40f);
hbRect.sizeDelta = new Vector2(280f, 36f);
// Background
GameObject bgGo = new GameObject("Background", typeof(RectTransform), typeof(Image));
bgGo.transform.SetParent(hbContainer.transform, false);
RectTransform bgRect = bgGo.GetComponent<RectTransform>();
bgRect.anchorMin = Vector2.zero;
bgRect.anchorMax = Vector2.one;
bgRect.offsetMin = Vector2.zero;
bgRect.offsetMax = Vector2.zero;
Image bgImg = bgGo.GetComponent<Image>();
bgImg.color = new Color(0.08f, 0.08f, 0.08f, 0.85f);
// Health Fill (Filled Image)
GameObject fillGo = new GameObject("HealthFill", typeof(RectTransform), typeof(Image));
fillGo.transform.SetParent(hbContainer.transform, false);
RectTransform fillRect = fillGo.GetComponent<RectTransform>();
fillRect.anchorMin = Vector2.zero;
fillRect.anchorMax = Vector2.one;
fillRect.offsetMin = new Vector2(4f, 4f);
fillRect.offsetMax = new Vector2(-4f, -4f);
Image fillImg = fillGo.GetComponent<Image>();
fillImg.type = Image.Type.Filled;
fillImg.fillMethod = Image.FillMethod.Horizontal;
fillImg.fillOrigin = (int)Image.OriginHorizontal.Left;
fillImg.fillAmount = 1f;
fillImg.color = new Color(0.2f, 0.85f, 0.3f, 1f);
// Text (Current / Max HP)
GameObject textGo = new GameObject("Text_HP", typeof(RectTransform), typeof(Text));
textGo.transform.SetParent(hbContainer.transform, false);
RectTransform textRect = textGo.GetComponent<RectTransform>();
textRect.anchorMin = Vector2.zero;
textRect.anchorMax = Vector2.one;
textRect.offsetMin = Vector2.zero;
textRect.offsetMax = Vector2.zero;
Text hpText = textGo.GetComponent<Text>();
hpText.text = "100 / 100";
hpText.alignment = TextAnchor.MiddleCenter;
hpText.fontSize = 20;
hpText.fontStyle = FontStyle.Bold;
hpText.color = Color.white;
Font defaultFont = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
if (defaultFont == null) defaultFont = Resources.GetBuiltinResource<Font>("Arial.ttf");
hpText.font = defaultFont;
// PlayerHealthUI
PlayerHealthUI uiComp = hbContainer.AddComponent<PlayerHealthUI>();
uiComp.healthFillImage = fillImg;
uiComp.healthText = hpText;
uiComp.playerHealth = Object.FindAnyObjectByType<PlayerHealth>();
// Crosshair / Center Cursor (Center of Screen)
GameObject crosshairGo = new GameObject("Crosshair", typeof(RectTransform));
crosshairGo.transform.SetParent(canvasGo.transform, false);
RectTransform crosshairRect = crosshairGo.GetComponent<RectTransform>();
crosshairRect.anchorMin = new Vector2(0.5f, 0.5f);
crosshairRect.anchorMax = new Vector2(0.5f, 0.5f);
crosshairRect.pivot = new Vector2(0.5f, 0.5f);
crosshairRect.anchoredPosition = Vector2.zero;
crosshairRect.sizeDelta = new Vector2(8f, 8f);
// Outline
GameObject chOutlineGo = new GameObject("Outline", typeof(RectTransform), typeof(Image));
chOutlineGo.transform.SetParent(crosshairGo.transform, false);
RectTransform chOutlineRect = chOutlineGo.GetComponent<RectTransform>();
chOutlineRect.anchorMin = Vector2.zero;
chOutlineRect.anchorMax = Vector2.one;
chOutlineRect.offsetMin = new Vector2(-1f, -1f);
chOutlineRect.offsetMax = new Vector2(1f, 1f);
Image chOutlineImg = chOutlineGo.GetComponent<Image>();
chOutlineImg.color = new Color(0f, 0f, 0f, 0.7f);
// Center Dot
GameObject chDotGo = new GameObject("Dot", typeof(RectTransform), typeof(Image));
chDotGo.transform.SetParent(crosshairGo.transform, false);
RectTransform chDotRect = chDotGo.GetComponent<RectTransform>();
chDotRect.anchorMin = Vector2.zero;
chDotRect.anchorMax = Vector2.one;
chDotRect.offsetMin = Vector2.zero;
chDotRect.offsetMax = Vector2.zero;
Image chDotImg = chDotGo.GetComponent<Image>();
chDotImg.color = new Color(1f, 1f, 1f, 0.95f);
// CrosshairUI component
CrosshairUI chScript = crosshairGo.AddComponent<CrosshairUI>();
chScript.dotImage = chDotImg;
chScript.outlineImage = chOutlineImg;
Undo.RegisterCreatedObjectUndo(canvasGo, "Create HUD_Canvas with HealthBar and Crosshair");
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(canvasGo.scene);
Debug.Log("HUD HealthBar и прицел в центре экрана успешно созданы!");
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 4495f70ce2eb87d478a3ba7d4fd3f906
@@ -0,0 +1,233 @@
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
public static class SetupShootingAndAmmo
{
[MenuItem("Tools/Setup Shooting & Ammo System")]
public static void Setup()
{
// 1. Находим игрока (PlayerMovement)
PlayerMovement playerMovement = Object.FindAnyObjectByType<PlayerMovement>();
if (playerMovement == null)
{
Debug.LogError("[Setup] Не найден объект игрока с компонентом PlayerMovement!");
return;
}
GameObject playerGo = playerMovement.gameObject;
Undo.RegisterFullObjectHierarchyUndo(playerGo, "Setup Shooting");
// 2. Добавляем / настраиваем PlayerGun на игроке
PlayerGun playerGun = playerGo.GetComponent<PlayerGun>();
if (playerGun == null)
{
playerGun = playerGo.AddComponent<PlayerGun>();
}
// 3. Создаем плейсхолдер модель оружия (GunHolder), если еще нет
Transform existingGun = playerGo.transform.Find("GunHolder");
if (existingGun != null)
{
Object.DestroyImmediate(existingGun.gameObject);
}
GameObject gunHolder = new GameObject("GunHolder");
gunHolder.transform.SetParent(playerGo.transform, false);
// Позиционируем справа на уровне пояса / руки
gunHolder.transform.localPosition = new Vector3(0.35f, 1.0f, 0.45f);
gunHolder.transform.localRotation = Quaternion.identity;
// Создаем детали пистолета-заглушки
// А. Затвор / Ствол
GameObject slide = GameObject.CreatePrimitive(PrimitiveType.Cube);
slide.name = "Pistol_Slide";
slide.transform.SetParent(gunHolder.transform, false);
slide.transform.localPosition = new Vector3(0f, 0.05f, 0.1f);
slide.transform.localScale = new Vector3(0.08f, 0.08f, 0.3f);
Object.DestroyImmediate(slide.GetComponent<Collider>());
// Б. Рукоятка
GameObject grip = GameObject.CreatePrimitive(PrimitiveType.Cube);
grip.name = "Pistol_Grip";
grip.transform.SetParent(gunHolder.transform, false);
grip.transform.localPosition = new Vector3(0f, -0.05f, 0.02f);
grip.transform.localRotation = Quaternion.Euler(15f, 0f, 0f);
grip.transform.localScale = new Vector3(0.07f, 0.16f, 0.08f);
Object.DestroyImmediate(grip.GetComponent<Collider>());
// В. Ствол на конце
GameObject barrel = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
barrel.name = "Pistol_Barrel";
barrel.transform.SetParent(gunHolder.transform, false);
barrel.transform.localPosition = new Vector3(0f, 0.05f, 0.26f);
barrel.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
barrel.transform.localScale = new Vector3(0.04f, 0.04f, 0.04f);
Object.DestroyImmediate(barrel.GetComponent<Collider>());
// Точка вылета пули
GameObject muzzleGo = new GameObject("MuzzlePoint");
muzzleGo.transform.SetParent(gunHolder.transform, false);
muzzleGo.transform.localPosition = new Vector3(0f, 0.05f, 0.32f);
// Вспышка (свет)
GameObject flashGo = new GameObject("MuzzleFlashLight");
flashGo.transform.SetParent(muzzleGo.transform, false);
flashGo.transform.localPosition = Vector3.zero;
Light flashLight = flashGo.AddComponent<Light>();
flashLight.type = LightType.Point;
flashLight.color = new Color(1f, 0.85f, 0.4f);
flashLight.range = 5f;
flashLight.intensity = 3f;
flashLight.enabled = false;
// Назначаем ссылки в PlayerGun
playerGun.gunModelTransform = gunHolder.transform;
playerGun.muzzlePoint = muzzleGo.transform;
playerGun.muzzleFlashLight = flashLight;
playerGun.isGunEquipped = false;
playerGun.UpdateGunVisibility();
// Покрасим пистолет в стильный темный цвет
Material gunMat = new Material(Shader.Find("Universal Render Pipeline/Lit"));
if (gunMat.shader == null || !gunMat.shader.isSupported)
{
gunMat = new Material(Shader.Find("Standard"));
}
gunMat.color = new Color(0.15f, 0.16f, 0.18f, 1f);
slide.GetComponent<Renderer>().material = gunMat;
grip.GetComponent<Renderer>().material = gunMat;
barrel.GetComponent<Renderer>().material = gunMat;
// 4. Настраиваем UI патронов на HUD_Canvas
GameObject canvasGo = GameObject.Find("HUD_Canvas");
if (canvasGo == null)
{
SetupHealthBarHUD.Setup();
canvasGo = GameObject.Find("HUD_Canvas");
}
Transform existingAmmoUI = canvasGo.transform.Find("AmmoPanel");
if (existingAmmoUI != null)
{
Object.DestroyImmediate(existingAmmoUI.gameObject);
}
// Ammo Root Container (под полоской здоровья)
GameObject ammoContainer = new GameObject("AmmoPanel", typeof(RectTransform));
ammoContainer.transform.SetParent(canvasGo.transform, false);
RectTransform ammoRect = ammoContainer.GetComponent<RectTransform>();
ammoRect.anchorMin = new Vector2(1f, 1f);
ammoRect.anchorMax = new Vector2(1f, 1f);
ammoRect.pivot = new Vector2(1f, 1f);
ammoRect.anchoredPosition = new Vector2(-40f, -84f);
ammoRect.sizeDelta = new Vector2(280f, 40f);
// Background
GameObject bgGo = new GameObject("Background", typeof(RectTransform), typeof(Image));
bgGo.transform.SetParent(ammoContainer.transform, false);
RectTransform bgRect = bgGo.GetComponent<RectTransform>();
bgRect.anchorMin = Vector2.zero;
bgRect.anchorMax = Vector2.one;
bgRect.offsetMin = Vector2.zero;
bgRect.offsetMax = Vector2.zero;
Image bgImg = bgGo.GetComponent<Image>();
bgImg.color = new Color(0.08f, 0.08f, 0.08f, 0.85f);
Font defaultFont = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
if (defaultFont == null) defaultFont = Resources.GetBuiltinResource<Font>("Arial.ttf");
// Иконка / Лейбл "AMMO"
GameObject labelGo = new GameObject("Text_Label", typeof(RectTransform), typeof(Text));
labelGo.transform.SetParent(ammoContainer.transform, false);
RectTransform labelRect = labelGo.GetComponent<RectTransform>();
labelRect.anchorMin = new Vector2(0f, 0f);
labelRect.anchorMax = new Vector2(0.4f, 1f);
labelRect.offsetMin = new Vector2(12f, 0f);
labelRect.offsetMax = Vector2.zero;
Text labelText = labelGo.GetComponent<Text>();
labelText.text = "ПАТРОНЫ";
labelText.font = defaultFont;
labelText.fontSize = 14;
labelText.fontStyle = FontStyle.Bold;
labelText.alignment = TextAnchor.MiddleLeft;
labelText.color = new Color(0.7f, 0.7f, 0.7f, 0.9f);
// Текст патронов (7 / 21)
GameObject countGo = new GameObject("Text_Count", typeof(RectTransform), typeof(Text));
countGo.transform.SetParent(ammoContainer.transform, false);
RectTransform countRect = countGo.GetComponent<RectTransform>();
countRect.anchorMin = new Vector2(0.4f, 0f);
countRect.anchorMax = new Vector2(1f, 1f);
countRect.offsetMin = Vector2.zero;
countRect.offsetMax = new Vector2(-12f, 0f);
Text countText = countGo.GetComponent<Text>();
countText.text = "7 / 21";
countText.font = defaultFont;
countText.fontSize = 20;
countText.fontStyle = FontStyle.Bold;
countText.alignment = TextAnchor.MiddleRight;
countText.color = Color.white;
// Текст статуса / подсказки под панелью
GameObject statusGo = new GameObject("Text_Status", typeof(RectTransform), typeof(Text));
statusGo.transform.SetParent(ammoContainer.transform, false);
RectTransform statusRect = statusGo.GetComponent<RectTransform>();
statusRect.anchorMin = new Vector2(0f, 0f);
statusRect.anchorMax = new Vector2(1f, 0f);
statusRect.pivot = new Vector2(0.5f, 1f);
statusRect.anchoredPosition = new Vector2(0f, -4f);
statusRect.sizeDelta = new Vector2(280f, 22f);
Text statusText = statusGo.GetComponent<Text>();
statusText.text = "";
statusText.font = defaultFont;
statusText.fontSize = 13;
statusText.fontStyle = FontStyle.Bold;
statusText.alignment = TextAnchor.MiddleRight;
statusText.color = new Color(1f, 0.85f, 0.2f, 1f);
// PlayerAmmoUI компонент
PlayerAmmoUI ammoUI = ammoContainer.AddComponent<PlayerAmmoUI>();
ammoUI.playerGun = playerGun;
ammoUI.ammoText = countText;
ammoUI.statusText = statusText;
// 5. Создаем 2 коробки с патронами на уровне рядом с игроком
CreateAmmoBox(playerGo.transform.position + playerGo.transform.forward * 3f + playerGo.transform.right * 1.5f, 14);
CreateAmmoBox(playerGo.transform.position + playerGo.transform.forward * 6f - playerGo.transform.right * 2f, 21);
Undo.RegisterCreatedObjectUndo(gunHolder, "Create Gun Holder");
Undo.RegisterCreatedObjectUndo(ammoContainer, "Create Ammo HUD");
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(playerGo.scene);
Debug.Log("<color=green>[Setup] Механика стрельбы, пистолет, патроны и UI успешно настроены!</color>");
}
private static void CreateAmmoBox(Vector3 position, int ammoCount)
{
GameObject boxGo = GameObject.CreatePrimitive(PrimitiveType.Cube);
boxGo.name = $"AmmoBox_({ammoCount})";
boxGo.transform.position = position + Vector3.up * 0.25f;
boxGo.transform.localScale = new Vector3(0.4f, 0.3f, 0.3f);
// Коллайдер делаем триггером
Collider col = boxGo.GetComponent<Collider>();
col.isTrigger = true;
// Скрипт подбора
AmmoPickup pickup = boxGo.AddComponent<AmmoPickup>();
pickup.ammoAmount = ammoCount;
pickup.pickupOnTouch = true;
// Военный зеленый / оранжевый материал
Material boxMat = new Material(Shader.Find("Universal Render Pipeline/Lit"));
if (boxMat.shader == null || !boxMat.shader.isSupported)
{
boxMat = new Material(Shader.Find("Standard"));
}
boxMat.color = new Color(0.2f, 0.45f, 0.25f, 1f); // Темно-зеленый армейский ящик
boxGo.GetComponent<Renderer>().material = boxMat;
Undo.RegisterCreatedObjectUndo(boxGo, "Create Ammo Box");
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 41488dce66056594a89389df1a6bc9cb