Browse Source
Moved creation of game objects for the world to GameState, which is where the bridge between Quake's game logic and Unity's game objects will happen. Also includes destruction of said game objects, so that the world is properly destroyed and recreated on map change.
console
Moved creation of game objects for the world to GameState, which is where the bridge between Quake's game logic and Unity's game objects will happen. Also includes destruction of said game objects, so that the world is properly destroyed and recreated on map change.
console
4 changed files with 62 additions and 37 deletions
-
2Assets/Scripts/Game/GameAssets.cs
-
54Assets/Scripts/Game/GameState.cs
-
39Assets/Scripts/Modules/RenderModule.cs
-
4Assets/Scripts/UniQuake.cs
@ -1,13 +1,67 @@ |
|||
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<MeshFilter>(); |
|||
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<MeshRenderer>(); |
|||
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; |
|||
} |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue