File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 33
44
55using System ;
6+ using System . Diagnostics ;
67using System . Diagnostics . CodeAnalysis ;
78using System . Reflection ;
89using System . Text ;
10+ using static System . Diagnostics . DebuggerBrowsableState ;
11+ using Browse = System . Diagnostics . DebuggerBrowsableAttribute ;
912
1013// ReSharper disable InconsistentNaming
1114// ReSharper disable once CheckNamespace
@@ -14,6 +17,7 @@ namespace Friflo.Engine.ECS;
1417/// <summary>
1518/// Contains the relations of a specific entity returned by <see cref="RelationExtensions.GetRelations{TRelation}"/>.
1619/// </summary>
20+ [ DebuggerTypeProxy ( typeof ( RelationsDebugView < > ) ) ]
1721public readonly struct Relations < TRelation >
1822 where TRelation : struct
1923{
@@ -140,4 +144,29 @@ public void Reset() {
140144
141145 // --- IDisposable
142146 public void Dispose ( ) { }
147+ }
148+
149+ internal class RelationsDebugView < TRelation >
150+ where TRelation : struct
151+ {
152+ [ Browse ( RootHidden ) ]
153+ public TRelation [ ] Relations => GetRelations ( ) ;
154+
155+ [ Browse ( Never ) ]
156+ private readonly Relations < TRelation > relations ;
157+
158+ internal RelationsDebugView ( Relations < TRelation > relations )
159+ {
160+ this . relations = relations ;
161+ }
162+
163+ private TRelation [ ] GetRelations ( )
164+ {
165+ var array = new TRelation [ relations . Length ] ;
166+ int n = 0 ;
167+ foreach ( var relation in relations ) {
168+ array [ n ++ ] = relation ;
169+ }
170+ return array ;
171+ }
143172}
Original file line number Diff line number Diff line change @@ -69,6 +69,19 @@ public static void Test_Relations_LinkRelationUtils()
6969 LinkRelationUtils . RemoveComponentValue ( 42 , 2 , relations ) ;
7070 AreEqual ( 1 , relations . Count ) ;
7171 }
72+
73+ [ Test ]
74+ public static void Test_Relations_DebugView ( )
75+ {
76+ var store = new EntityStore ( ) ;
77+ var entity = store . CreateEntity ( ) ;
78+ entity . AddRelation ( new StringRelation { value = "test" } ) ;
79+ var relations = entity . GetRelations < StringRelation > ( ) ;
80+
81+ var debugView = new RelationsDebugView < StringRelation > ( relations ) ;
82+ AreEqual ( 1 , debugView . Relations . Length ) ;
83+ AreEqual ( "test" , debugView . Relations [ 0 ] . value ) ;
84+ }
7285}
7386
7487}
You can’t perform that action at this time.
0 commit comments