@@ -123,11 +123,71 @@ public int OffscreenIndex
123123 }
124124 }
125125
126+ /// <summary>
127+ /// <see cref="AllChildOffscreens"/>'s backing field.
128+ /// </summary>
129+ private CubismOffscreen [ ] _allChildOffscreens = null ;
130+
131+ /// <summary>
132+ /// All child drawables of this part, including children of children.
133+ /// </summary>
134+ public CubismOffscreen [ ] AllChildOffscreens
135+ {
136+ get
137+ {
138+ if ( _allChildOffscreens == null )
139+ {
140+ var model = this . FindCubismModel ( true ) ;
141+ if ( ! model )
142+ {
143+ return null ;
144+ }
145+
146+ if ( model . Offscreens == null )
147+ {
148+ return null ;
149+ }
150+
151+ var parts = model . Parts ;
152+
153+ var childrenParts = Array . Empty < CubismPart > ( ) ;
154+
155+ for ( var index = 0 ; index < parts . Length ; index ++ )
156+ {
157+ if ( parts [ index ] . UnmanagedParentIndex == UnmanagedIndex )
158+ {
159+ Array . Resize ( ref childrenParts , childrenParts . Length + 1 ) ;
160+ childrenParts [ ^ 1 ] = parts [ index ] ;
161+ }
162+ }
163+
164+ // Initialize the array of all children drawables.
165+ _allChildOffscreens = Array . Empty < CubismOffscreen > ( ) ;
166+
167+ // Add the drawables of this part.
168+ Array . Resize ( ref _allChildOffscreens , ChildOffscreens . Length ) ;
169+ Array . Copy ( ChildOffscreens , _allChildOffscreens , ChildOffscreens . Length ) ;
170+
171+ // Collect all children drawables from child parts.
172+ for ( var index = 0 ; index < childrenParts . Length ; index ++ )
173+ {
174+ Array . Resize ( ref _allChildOffscreens , _allChildOffscreens . Length + childrenParts [ index ] . AllChildOffscreens . Length ) ;
175+ Array . Copy ( childrenParts [ index ] . AllChildOffscreens ,
176+ 0 ,
177+ _allChildOffscreens ,
178+ _allChildOffscreens . Length - childrenParts [ index ] . AllChildOffscreens . Length ,
179+ childrenParts [ index ] . AllChildOffscreens . Length ) ;
180+ }
181+ }
182+
183+ return _allChildOffscreens ;
184+ }
185+ }
186+
126187 /// <summary>
127188 /// <see cref="AllChildDrawables"/>'s backing field.
128189 /// </summary>
129- [ SerializeField , HideInInspector ]
130- private CubismDrawable [ ] _allChildrenDrawables = null ;
190+ private CubismDrawable [ ] _allChildDrawables = null ;
131191
132192 /// <summary>
133193 /// All child drawables of this part, including children of children.
@@ -136,10 +196,10 @@ public CubismDrawable[] AllChildDrawables
136196 {
137197 get
138198 {
139- if ( _allChildrenDrawables == null )
199+ if ( _allChildDrawables == null )
140200 {
141201 var model = this . FindCubismModel ( true ) ;
142- if ( ! model )
202+ if ( ! model || ( model . Drawables ? . Length ?? - 1 ) < 1 )
143203 {
144204 return null ;
145205 }
@@ -158,25 +218,30 @@ public CubismDrawable[] AllChildDrawables
158218 }
159219
160220 // Initialize the array of all children drawables.
161- _allChildrenDrawables = Array . Empty < CubismDrawable > ( ) ;
221+ _allChildDrawables = Array . Empty < CubismDrawable > ( ) ;
162222
163223 // Add the drawables of this part.
164- Array . Resize ( ref _allChildrenDrawables , ChildDrawables . Length ) ;
165- Array . Copy ( ChildDrawables , _allChildrenDrawables , ChildDrawables . Length ) ;
224+ Array . Resize ( ref _allChildDrawables , ChildDrawables . Length ) ;
225+ Array . Copy ( ChildDrawables , _allChildDrawables , ChildDrawables . Length ) ;
166226
167227 // Collect all children drawables from child parts.
168228 for ( var index = 0 ; index < childrenParts . Length ; index ++ )
169229 {
170- Array . Resize ( ref _allChildrenDrawables , _allChildrenDrawables . Length + childrenParts [ index ] . AllChildDrawables . Length ) ;
230+ if ( ( childrenParts [ index ] ? . AllChildDrawables ? . Length ?? - 1 ) < 1 )
231+ {
232+ continue ;
233+ }
234+
235+ Array . Resize ( ref _allChildDrawables , _allChildDrawables . Length + childrenParts [ index ] . AllChildDrawables . Length ) ;
171236 Array . Copy ( childrenParts [ index ] . AllChildDrawables ,
172237 0 ,
173- _allChildrenDrawables ,
174- _allChildrenDrawables . Length - childrenParts [ index ] . AllChildDrawables . Length ,
238+ _allChildDrawables ,
239+ _allChildDrawables . Length - childrenParts [ index ] . AllChildDrawables . Length ,
175240 childrenParts [ index ] . AllChildDrawables . Length ) ;
176241 }
177242 }
178243
179- return _allChildrenDrawables ;
244+ return _allChildDrawables ;
180245 }
181246 }
182247
@@ -261,7 +326,7 @@ public CubismDrawable[] ChildDrawables
261326 private CubismOffscreen [ ] _childOffscreens ;
262327
263328 /// <summary>
264- /// Child offscreens of this part.
329+ /// Array of offscreen from child parts;
265330 /// </summary>
266331 public CubismOffscreen [ ] ChildOffscreens
267332 {
@@ -282,14 +347,21 @@ public CubismOffscreen[] ChildOffscreens
282347 return null ;
283348 }
284349
350+ _childOffscreens = Array . Empty < CubismOffscreen > ( ) ;
351+
285352 for ( var index = 0 ; index < offscreens . Length ; index ++ )
286353 {
354+ var part = model . Parts [ offscreens [ index ] . OwnerIndex ] ;
355+
287356 // When this object is the parent part.
288- if ( offscreens [ index ] . OwnerIndex == UnmanagedIndex )
357+ if ( part . UnmanagedParentIndex < 0
358+ || part . UnmanagedParentIndex != UnmanagedIndex )
289359 {
290- Array . Resize ( ref _childOffscreens , _childOffscreens ? . Length ?? 0 + 1 ) ;
291- _childOffscreens [ ^ 1 ] = offscreens [ index ] ;
360+ continue ;
292361 }
362+
363+ Array . Resize ( ref _childOffscreens , _childOffscreens . Length + 1 ) ;
364+ _childOffscreens [ ^ 1 ] = offscreens [ index ] ;
293365 }
294366 }
295367 return _childOffscreens ;
@@ -331,15 +403,14 @@ private void InitializePartInfo()
331403 }
332404
333405 var childObjectCount = ChildDrawables . Length + ChildParts . Length ;
334-
335406 _partInfo = new CubismModelTypes . PartInfo
336407 {
337408 PartUnmanagedIndex = UnmanagedIndex ,
338409 ChildObjects = new CubismModelTypes . PartChildObjectInfo [ childObjectCount ] ,
339410 DrawObjects = new CubismModelTypes . PartDrawObjectInfo
340411 {
341412 Drawables = AllChildDrawables ,
342- Offscreens = ChildOffscreens
413+ Offscreens = AllChildOffscreens
343414 }
344415 } ;
345416
@@ -394,7 +465,8 @@ private void Reset(CubismUnmanagedModel unmanagedModel, int unmanagedIndex)
394465 name = Id ;
395466 Opacity = UnmanagedParts . Opacities [ unmanagedIndex ] ;
396467
397- _allChildrenDrawables = null ;
468+ _allChildDrawables = null ;
469+ _allChildOffscreens = null ;
398470 _childParts = null ;
399471 _childDrawables = null ;
400472 _childOffscreens = null ;
0 commit comments