@@ -24,6 +24,12 @@ public sealed class LDtkComponentLevel : MonoBehaviour
2424 [ field: Tooltip ( "The size of this level in Unity units." ) ]
2525 [ field: SerializeField ] public Vector2 Size { get ; private set ; }
2626
27+ [ field: Tooltip ( "The world-space rectangle of this level.\n Useful for getting a level's bounds for a camera, for example." ) ]
28+ [ field: SerializeField ] public Rect BorderRect { get ; private set ; }
29+
30+ [ field: Tooltip ( "The world-space bounds of this level.\n Useful for getting a level's bounds for a camera, for example." ) ]
31+ [ field: SerializeField ] public Bounds BorderBounds { get ; private set ; }
32+
2733 #endregion
2834
2935 [ field: Header ( "Redundant Fields" ) ]
@@ -93,7 +99,7 @@ public sealed class LDtkComponentLevel : MonoBehaviour
9399
94100 /// <summary>
95101 /// A static collection of all active level GameObjects in the scene during runtime.<br/>
96- /// This list will actively update as level GameObjects are set active/inactive.
102+ /// This list will actively update as level GameObjects are set active/inactive. So only query this during Start and not Awake.
97103 /// </summary>
98104 [ PublicAPI ] public static IReadOnlyCollection < LDtkComponentLevel > Levels => Lvls ;
99105
@@ -140,20 +146,10 @@ internal void OnImport(Level lvl, LDtkLevelFile file, LDtkComponentLayer[] layer
140146
141147 //custom
142148 Size = unitySize ;
149+ BorderRect = new Rect ( transform . position , unitySize ) ;
150+ BorderBounds = new Bounds ( transform . position + new Vector3 ( unitySize . x * 0.5f , unitySize . y * 0.5f , 0 ) , unitySize ) ;
143151 Json = file ;
144152 Parent = world ;
145153 }
146-
147- /// <value>
148- /// The world-space rectangle of this level. <br/>
149- /// Useful for getting a level's bounds for a camera, for example.
150- /// </value>
151- [ PublicAPI ] public Rect BorderRect => new Rect ( transform . position , Size ) ;
152-
153- /// <value>
154- /// The world-space bounds of this level. <br/>
155- /// Useful for getting a level's bounds for a camera, for example.
156- /// </value>
157- [ PublicAPI ] public Bounds BorderBounds => new Bounds ( transform . position + ( Vector3 ) ( Vector2 . one * Size * 0.5f ) , Size ) ;
158154 }
159155}
0 commit comments