-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from Doprez/fix-getcamera
Thank you @Doprez
- Loading branch information
Showing
3 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Stride.Engine; | ||
|
||
namespace Stride.CommunityToolkit.Engine; | ||
public static class SceneExtensions | ||
{ | ||
|
||
/// <summary> | ||
/// Gets the first camera in the scene. | ||
/// </summary> | ||
/// <param name="scene"></param> | ||
/// <returns></returns> | ||
public static CameraComponent? GetCamera(this Scene scene) | ||
{ | ||
var entities = scene.Entities; | ||
CameraComponent? camera = null; | ||
foreach (var entity in entities) | ||
{ | ||
camera = entity.GetComponentInChildren<CameraComponent>(); | ||
if (camera != null) | ||
{ | ||
break; | ||
} | ||
} | ||
return camera; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the first camera in the scene with the specified <see cref="Entity"/> name. | ||
/// </summary> | ||
/// <param name="scene"></param> | ||
/// <param name="name"></param> | ||
/// <returns></returns> | ||
public static CameraComponent? GetCamera(this Scene scene, string name) | ||
{ | ||
var entities = scene.Entities; | ||
CameraComponent? camera = null; | ||
foreach (var entity in entities) | ||
{ | ||
camera = entity.GetComponentInChildren<CameraComponent>(); | ||
if (camera != null && camera.Entity.Name == name) | ||
{ | ||
break; | ||
} | ||
} | ||
return camera; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters