Сегодня столкнулся с ошибкой SerializedObject of SerializedProperty has been Disposed. В unity я новичок, так что совсем не знаю что за ошибка.
пролазил все форумы но так и не нашёл решения, поэтому решил обратиться суда
Редактировано: После запуска проекта и отключения его, в инспекторе пропадает поле RoomPrefabs, из за чего выдаёт все эти ошибки, я не знаю почему этот игровой лист пропадает после запуска сцены и остановки.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public enum GenerationState
{
Idle,
GeneratingRooms,
GeneratingLighting,
GeneratingSpawn,
GeneratingExit,
GeneratingBarrier,
}
public class GenerationManager : MonoBehaviour
{
[Header("References")]
[SerializeField] Transform WorldGrid;
[SerializeField] List<GameObject> RoomPrefabs;
[SerializeField] List<GameObject> LightTypes;
[SerializeField] int mapSize = 16;
[SerializeField] Slider MapSizeSlider, EmptinessSlider, BrightnessSlider;
[SerializeField] Button GenerateButton;
[SerializeField] GameObject E_Room;
[SerializeField] GameObject B_Room;
[SerializeField] GameObject SpawnRoom, ExitRoom;
public List<GameObject> GeneratedRooms;
[SerializeField] GameObject PlayerObject, MainCameraObject;
[Header("Settings")]
public int mapEmptiness;
public int mapBrightness;
private int mapSizeSquare;
private Vector3 currentPos;
private float currentPosx, currentPosZ, currentPosTracker, currentRoom;
public float roomSize = 7;
public GenerationState currentState;
private void Update()
{
mapSize = (int)Mathf.Pow(MapSizeSlider.value, 4);
mapSizeSquare = (int)Mathf.Sqrt(mapSize);
mapEmptiness = (int)EmptinessSlider.value;
mapBrightness = (int)BrightnessSlider.value;
}
public void ReloadWorld()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
public void GenerateWorld()
{
for (int i = 0; i < mapEmptiness; i++)
{
RoomPrefabs.Add(E_Room);
}
GenerateButton.interactable = false;
for (int state = 0; state < 6; state++)
{
for (int i = 0; i < mapSize; i++)
{
if (currentPosTracker == mapSizeSquare)
{
if (currentState == GenerationState.GeneratingBarrier) GenerateBarrier();
currentPosx = 0;
currentPosTracker = 0;
currentPosZ += roomSize;
if (currentState == GenerationState.GeneratingBarrier) GenerateBarrier();
}
currentPos = new(currentPosx, 0, currentPosZ);
switch (currentState)
{
case GenerationState.GeneratingRooms:
GeneratedRooms.Add(Instantiate(RoomPrefabs[Random.Range(0, RoomPrefabs.Count)], currentPos, Quaternion.identity, WorldGrid));
break;
case GenerationState.GeneratingLighting:
Instantiate(LightTypes[Random.Range(0, LightTypes.Count)], currentPos, Quaternion.identity, WorldGrid);
break;
case GenerationState.GeneratingBarrier:
if (currentRoom <= mapSizeSquare && currentRoom >= 0)
{
GenerateBarrier();
}
if (currentRoom <= mapSize && currentRoom >= mapSize - mapSizeSquare)
{
GenerateBarrier();
}
break;
}
currentRoom++;
currentPosTracker++;
currentPosx += roomSize;
}
NextState();
switch (currentState)
{
case GenerationState.GeneratingExit:
int roomRoReplace = Random.Range(0, GeneratedRooms.Count);
GameObject exitRoom = Instantiate(ExitRoom, GeneratedRooms[roomRoReplace].transform.position, Quaternion.identity, WorldGrid);
Destroy(GeneratedRooms[roomRoReplace]);
GeneratedRooms[roomRoReplace] = exitRoom;
break;
case GenerationState.GeneratingSpawn:
int _roomRoReplace = Random.Range(0, GeneratedRooms.Count);
GameObject spawnRoom = Instantiate(SpawnRoom, GeneratedRooms[_roomRoReplace].transform.position, Quaternion.identity, WorldGrid);
Destroy(GeneratedRooms[_roomRoReplace]);
GeneratedRooms[_roomRoReplace] = spawnRoom;
break;
}
}
}
public GameObject spawnRoom;
public void SpawnPlayer()
{
PlayerObject.SetActive(false);
PlayerObject.transform.position = new Vector3(SpawnRoom.transform.position.x, 1.8f, SpawnRoom.transform.position.z);
PlayerObject.SetActive(true);
MainCameraObject.SetActive(true);
}
public void NextState()
{
currentState++;
currentRoom = 0;
currentPosx = 0;
currentPosZ = 0;
currentPos = Vector3.zero;
currentPosTracker = 0;
}
public void Win()
{
PlayerObject.SetActive(false);
MainCameraObject.SetActive(true);
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
Debug.Log("Player has exited and won the Game!");
}
public void GenerateBarrier()
{
currentPos = new(currentPosx, 0, currentPosZ);
Instantiate(B_Room, currentPos, Quaternion.identity, WorldGrid);
}
}