using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering; public class GameState { private readonly UniQuake uq; private GameObject worldGameObject; public GameState(UniQuake uniQuake) { uq = uniQuake; } public void Destroy() { DestroyWorld(); } public void NewMap(BrushModel worldModel) { DestroyWorld(); // DEBUG - we'll want to instantiate prefabs for each submodel and assign materials from a preset collection worldGameObject = new GameObject(worldModel.Name); for (int i = 0; i < worldModel.SubModelCount; ++i) { var subModel = worldModel.GetSubModel(i); var subModelGO = new GameObject($"SubModel_{i}"); subModelGO.transform.SetParent(worldGameObject.transform); foreach (var surfaceMesh in subModel.SurfaceMeshes) { var meshGO = new GameObject(surfaceMesh.Mesh.name); meshGO.transform.SetParent(subModelGO.transform); var mf = meshGO.AddComponent(); mf.sharedMesh = surfaceMesh.Mesh; var material = new Material(Shader.Find("Universal Render Pipeline/Simple Lit")); uint texNum = surfaceMesh.Texture.TextureNum; if (uq.GameAssets.TryGetTexture(texNum, out var texture)) { material.mainTexture = texture; } var mr = meshGO.AddComponent(); mr.sharedMaterial = material; mr.shadowCastingMode = ShadowCastingMode.Off; mr.receiveShadows = false; mr.lightProbeUsage = LightProbeUsage.Off; mr.reflectionProbeUsage = ReflectionProbeUsage.Off; } } } private void DestroyWorld() { if (worldGameObject != null) { Object.Destroy(worldGameObject); worldGameObject = null; } } }