Creates the new scene file. The default scene contains set of simple actors. The path.
(string path)
| 143 | /// </summary> |
| 144 | /// <param name="path">The path.</param> |
| 145 | public void CreateSceneFile(string path) |
| 146 | { |
| 147 | // Create a sample scene |
| 148 | var scene = new Scene |
| 149 | { |
| 150 | StaticFlags = StaticFlags.FullyStatic |
| 151 | }; |
| 152 | |
| 153 | // |
| 154 | var sun = scene.AddChild<DirectionalLight>(); |
| 155 | sun.Name = "Sun"; |
| 156 | sun.LocalPosition = new Vector3(40, 160, 0); |
| 157 | sun.LocalEulerAngles = new Vector3(45, 0, 0); |
| 158 | sun.StaticFlags = StaticFlags.FullyStatic; |
| 159 | // |
| 160 | var sky = scene.AddChild<Sky>(); |
| 161 | sky.Name = "Sky"; |
| 162 | sky.LocalPosition = new Vector3(40, 150, 0); |
| 163 | sky.SunLight = sun; |
| 164 | sky.StaticFlags = StaticFlags.FullyStatic; |
| 165 | // |
| 166 | var skyLight = scene.AddChild<SkyLight>(); |
| 167 | skyLight.Mode = SkyLight.Modes.CustomTexture; |
| 168 | skyLight.Brightness = 2.5f; |
| 169 | skyLight.CustomTexture = FlaxEngine.Content.LoadAsyncInternal<CubeTexture>(EditorAssets.DefaultSkyCubeTexture); |
| 170 | skyLight.StaticFlags = StaticFlags.FullyStatic; |
| 171 | // |
| 172 | var floor = scene.AddChild<StaticModel>(); |
| 173 | floor.Name = "Floor"; |
| 174 | floor.Scale = new Float3(4, 0.5f, 4); |
| 175 | floor.Model = FlaxEngine.Content.LoadAsync<Model>(StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Primitives/Cube.flax")); |
| 176 | if (floor.Model) |
| 177 | { |
| 178 | floor.Model.WaitForLoaded(); |
| 179 | floor.SetMaterial(0, FlaxEngine.Content.LoadAsync<MaterialBase>(StringUtils.CombinePaths(Globals.EngineContentFolder, "Engine/WhiteMaterial.flax"))); |
| 180 | } |
| 181 | floor.StaticFlags = StaticFlags.FullyStatic; |
| 182 | // |
| 183 | var cam = scene.AddChild<Camera>(); |
| 184 | cam.Name = "Camera"; |
| 185 | cam.Position = new Vector3(0, 150, -300); |
| 186 | // |
| 187 | var audioListener = cam.AddChild<AudioListener>(); |
| 188 | audioListener.Name = "Audio Listener"; |
| 189 | |
| 190 | // Serialize |
| 191 | var bytes = Level.SaveSceneToBytes(scene); |
| 192 | |
| 193 | // Cleanup |
| 194 | Object.Destroy(ref scene); |
| 195 | |
| 196 | if (bytes == null || bytes.Length == 0) |
| 197 | throw new Exception("Failed to serialize scene."); |
| 198 | |
| 199 | // Write to file |
| 200 | using (var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read)) |
| 201 | fileStream.Write(bytes, 0, bytes.Length); |
| 202 | } |
no test coverage detected