Przeglądaj źródła

samples: core: hide core objects' mesh when spawned in-game

Fixes: #226
Daniele Bartolini 1 rok temu
rodzic
commit
c715f8a96b

+ 1 - 0
docs/changelog.rst

@@ -22,6 +22,7 @@ Changelog
 * Items in the Level Tree can now be sorted by name or type.
 * Fixed an issue in the Project Browser that caused a new Unit to be always created even if the user cancelled the "New Unit..." action.
 * Fixed an issue that caused the Level Editor to launch a game with outdated state in some circumnstances.
+* Fixed an issue with some core objects not being hidden when spawned in-game.
 
 **Runtime**
 

+ 1 - 1
samples/core/units/camera.unit

@@ -50,7 +50,7 @@ components = [
 		_guid = "eee01696-8523-4d3f-b49a-59821238f270"
 		_type = "script"
 		data = {
-			script_resource = "core/units/camera"
+			script_resource = "core/units/common"
 		}
 		type = "script"
 	}

+ 1 - 18
samples/core/units/camera.lua → samples/core/units/common.lua

@@ -2,22 +2,12 @@
 -- SPDX-License-Identifier: MIT
 
 local Behavior = Behavior or {}
-local Data = Data or {}
 
 function Behavior.spawned(world, units)
-	if Data[world] == nil then
-		Data[world] = {}
-	end
-
 	for uu = 1, #units do
 		local unit = units[uu]
 
-		-- Store instance-specific data
-		if Data[world][unit] == nil then
-			-- Data[world][unit] = {}
-		end
-
-		-- Hide the camera mesh
+		-- Hide the mesh.
 		local render_world = World.render_world(world)
 		local camera_mesh = RenderWorld.mesh_instance(render_world, unit)
 		if camera_mesh ~= nil then
@@ -27,16 +17,9 @@ function Behavior.spawned(world, units)
 end
 
 function Behavior.update(world, dt)
-	-- Update all units
 end
 
 function Behavior.unspawned(world, units)
-	-- Cleanup
-	for uu = 1, #units do
-		if Data[world][units] then
-			Data[world][units] = nil
-		end
-	end
 end
 
 return Behavior

+ 7 - 0
samples/core/units/light.unit

@@ -51,4 +51,11 @@ components = [
 		}
 		type = "mesh_renderer"
 	}
+	{
+		_guid = "1f56e077-b6b5-402c-8e99-98b541ef5f9b"
+		_type = "script"
+		data = {
+			script_resource = "core/units/common"
+		}
+	}
 ]

+ 7 - 0
samples/core/units/sound.unit

@@ -35,4 +35,11 @@ components = [
 		}
 		type = "transform"
 	}
+	{
+		_guid = "4cb55f73-067a-4009-8a46-260185fcae80"
+		_type = "script"
+		data = {
+			script_resource = "core/units/common"
+		}
+	}
 ]