@@ -120,6 +120,10 @@ public PartialPrefab(ushort id)
120120 {
121121 }
122122
123+ /// <summary>
124+ /// Initializes a new instance of the <see cref="PartialPrefab"/> class.
125+ /// </summary>
126+ /// <param name="prefab">A <see cref="Prefab"/> to copy values from.</param>
123127 public PartialPrefab ( Prefab prefab )
124128 {
125129 ThrowIfNull ( prefab , nameof ( prefab ) ) ;
@@ -135,7 +139,7 @@ public PartialPrefab(Prefab prefab)
135139 /// <summary>
136140 /// Initializes a new instance of the <see cref="PartialPrefab"/> class.
137141 /// </summary>
138- /// <param name="other">The <see cref="PartialPrefab"/> to copy values from.</param>
142+ /// <param name="other">A <see cref="PartialPrefab"/> to copy values from.</param>
139143 /// <param name="deepCopy">If deep copy should be performed.</param>
140144 public PartialPrefab ( PartialPrefab other , bool deepCopy )
141145 {
@@ -213,7 +217,10 @@ public ushort Id
213217 /// <inheritdoc/>
214218 public ICollection < PartialPrefabSegment > Values => _segments . Values ;
215219
216- /// <inheritdoc/>
220+ /// <summary>
221+ /// Gets the number of segments in the <see cref="Prefab"/>.
222+ /// </summary>
223+ /// <value>The number of segments in the <see cref="Prefab"/>.</value>
217224 public int Count => _segments . Count ;
218225
219226 /// <inheritdoc/>
@@ -228,7 +235,7 @@ public PartialPrefabSegment this[byte3 index]
228235 }
229236
230237 /// <inheritdoc/>
231- public void Add ( byte3 key , PartialPrefabSegment value )
238+ void IDictionary < byte3 , PartialPrefabSegment > . Add ( byte3 key , PartialPrefabSegment value )
232239 {
233240 ValidatePos ( key , nameof ( key ) ) ;
234241
@@ -239,6 +246,10 @@ public void Add(byte3 key, PartialPrefabSegment value)
239246 Size = byte3 . Max ( Size , key + byte3 . One ) ;
240247 }
241248
249+ /// <summary>
250+ /// Adds a segment to the prefab.
251+ /// </summary>
252+ /// <param name="value">The segment to add.</param>
242253 public void Add ( PartialPrefabSegment value )
243254 {
244255 ValidatePos ( value . PosInPrefab , $ "{ nameof ( value ) } .{ nameof ( value . PosInPrefab ) } ") ;
@@ -248,21 +259,11 @@ public void Add(PartialPrefabSegment value)
248259 Size = byte3 . Max ( Size , value . PosInPrefab + byte3 . One ) ;
249260 }
250261
251- public bool TryAdd ( byte3 key , PartialPrefabSegment value )
252- {
253- ValidatePos ( key , nameof ( key ) ) ;
254-
255- if ( ! _segments . TryAdd ( key , ValidateSegment ( value , nameof ( value ) ) ) )
256- {
257- return false ;
258- }
259-
260- value . PosInPrefab = key ; // only change pos if successfully added
261-
262- Size = byte3 . Max ( Size , key + byte3 . One ) ;
263- return true ;
264- }
265-
262+ /// <summary>
263+ /// Adds a segment to the prefab, if one isn't already at it's position.
264+ /// </summary>
265+ /// <param name="value">The segment to add.</param>
266+ /// <returns><see langword="true"/> if the value was added; otherwise, <see langword="false"/>.</returns>
266267 public bool TryAdd ( PartialPrefabSegment value )
267268 {
268269 ValidatePos ( value . PosInPrefab , $ "{ nameof ( value ) } .{ nameof ( value . PosInPrefab ) } ") ;
@@ -280,7 +281,15 @@ public bool TryAdd(PartialPrefabSegment value)
280281 public bool ContainsKey ( byte3 key )
281282 => _segments . ContainsKey ( key ) ;
282283
283- /// <inheritdoc/>
284+ /// <summary>
285+ /// Removes a segment at the specified position.
286+ /// </summary>
287+ /// <remarks>
288+ /// <see cref="PartialPrefab"/> cannot be empty, this method will not succeed if <see cref="Count"/> is <c>1</c>.
289+ /// <para>The segment at index <c>0</c> (<see cref="IndexOf(byte3)"/>) cannot be removed.</para>
290+ /// </remarks>
291+ /// <param name="key">Position of the segment to remove.</param>
292+ /// <returns><see langword="true"/> if the segment was removed; otherwise, <see langword="true"/>.</returns>
284293 public bool Remove ( byte3 key )
285294 {
286295 // can't remove the first segment
@@ -299,6 +308,16 @@ public bool Remove(byte3 key)
299308 return removed ;
300309 }
301310
311+ /// <summary>
312+ /// Removes the segment at the specified position.
313+ /// </summary>
314+ /// <remarks>
315+ /// <see cref="PartialPrefab"/> cannot be empty, this method will not succeed if <see cref="Count"/> is <c>1</c>.
316+ /// <para>The segment at index <c>0</c> (<see cref="IndexOf(byte3)"/>) cannot be removed.</para>
317+ /// </remarks>
318+ /// <param name="key">The position of the segment to remove.</param>
319+ /// <param name="value">The removed segment.</param>
320+ /// <returns><see langword="true"/> if the segment is successfully found and removed; otherwise, <see langword="false"/>.</returns>
302321 public bool Remove ( byte3 key , [ MaybeNullWhen ( false ) ] out PartialPrefabSegment value )
303322 {
304323 // can't remove the first segment
@@ -326,15 +345,27 @@ public bool TryGetValue(byte3 key, out PartialPrefabSegment value)
326345#endif
327346 => _segments . TryGetValue ( key , out value ) ;
328347
348+ /// <summary>
349+ /// Determines the indes of a specified segment.
350+ /// </summary>
351+ /// <param name="key">Position of the segment.</param>
352+ /// <returns>The index of the segment if found; otherwise, <c>-1</c>.</returns>
329353 public int IndexOf ( byte3 key )
330354 => _segments . IndexOf ( key ) ;
331355
332- /// <inheritdoc/>
356+ /// <summary>
357+ /// Removes all, but the first segment.
358+ /// </summary>
333359 public void Clear ( )
334360 {
361+ var first = _segments . GetAt ( 0 ) . Value ;
362+
335363 _segments . Clear ( ) ;
336364
337- Size = byte3 . Zero ;
365+ first . PosInPrefab = byte3 . Zero ;
366+ _segments . Add ( first . PosInPrefab , first ) ;
367+
368+ Size = byte3 . One ;
338369 }
339370
340371 /// <inheritdoc/>
@@ -383,6 +414,10 @@ bool ICollection<KeyValuePair<byte3, PartialPrefabSegment>>.Remove(KeyValuePair<
383414 return removed ;
384415 }
385416
417+ /// <summary>
418+ /// Returns an <see cref="IEnumerable{T}"/>, that enumerates the segments with their ids.
419+ /// </summary>
420+ /// <returns>An <see cref="IEnumerable{T}"/>, that enumerates the segments with their ids.</returns>
386421 public IEnumerable < ( PartialPrefabSegment Segment , ushort Id ) > EnumerateWithId ( )
387422 {
388423 ushort id = Id ;
0 commit comments