Barotrauma Client Doc
Barotrauma.PrefabCollection< T > Class Template Reference
Inheritance diagram for Barotrauma.PrefabCollection< T >:

Public Member Functions

 PrefabCollection ()
 Default constructor. More...
 
 PrefabCollection (Action< T, bool >? onAdd, Action< T >? onRemove, Action? onSort, Action< ContentFile >? onAddOverrideFile, Action< ContentFile >? onRemoveOverrideFile)
 Constructor with OnAdd and OnRemove callbacks provided. More...
 
 PrefabCollection (Action? onSort)
 Constructor with only the OnSort callback provided. More...
 
bool TryGet (Identifier identifier, [NotNullWhen(true)] out T? result)
 Returns true if a prefab with the identifier exists, false otherwise. More...
 
bool TryGet (string identifier, out T? result)
 
T? Find (Predicate< T > predicate)
 Finds the first active prefab that returns true given the predicate, or null if no such prefab is found. More...
 
bool ContainsKey (Identifier identifier)
 Returns true if a prefab with the given identifier exists, false otherwise. More...
 
bool ContainsKey (string k)
 
bool IsOverride (T prefab)
 Determines whether a prefab is implemented as an override or not. More...
 
void Add (T prefab, bool isOverride)
 Add a prefab to the collection. If not marked as an override, fail if a prefab with the same identifier already exists. Otherwise, add to the corresponding list, without making any changes to the base prefab. More...
 
void Remove (T prefab)
 Removes a prefab from the collection. More...
 
void RemoveByFile (ContentFile file)
 Removes all prefabs that were loaded from a certain file. More...
 
void AddOverrideFile (ContentFile file)
 Adds an override file to the collection. More...
 
void RemoveOverrideFile (ContentFile file)
 Removes an override file from the collection. More...
 
void SortAll ()
 Sorts all prefabs in the collection based on the content package load order. More...
 
IEnumerator< T > GetEnumerator ()
 GetEnumerator implementation to enable foreach More...
 

Properties

IEnumerable< KeyValuePair< Identifier, PrefabSelector< T > > > AllPrefabs [get]
 AllPrefabs exposes all prefabs instead of just the active ones. More...
 
this[Identifier identifier] [get]
 Returns the active prefab with the given identifier. More...
 
this[string identifier] [get]
 
IEnumerable< IdentifierKeys [get]
 

Detailed Description

Type Constraints
T :notnull 
T :Prefab 

Definition at line 13 of file PrefabCollection.cs.

Constructor & Destructor Documentation

◆ PrefabCollection() [1/3]

Default constructor.

Definition at line 18 of file PrefabCollection.cs.

◆ PrefabCollection() [2/3]

Barotrauma.PrefabCollection< T >.PrefabCollection ( Action< T, bool >?  onAdd,
Action< T >?  onRemove,
Action?  onSort,
Action< ContentFile >?  onAddOverrideFile,
Action< ContentFile >?  onRemoveOverrideFile 
)

Constructor with OnAdd and OnRemove callbacks provided.

Definition at line 27 of file PrefabCollection.cs.

◆ PrefabCollection() [3/3]

Constructor with only the OnSort callback provided.

Definition at line 44 of file PrefabCollection.cs.

Member Function Documentation

◆ Add()

void Barotrauma.PrefabCollection< T >.Add ( prefab,
bool  isOverride 
)

Add a prefab to the collection. If not marked as an override, fail if a prefab with the same identifier already exists. Otherwise, add to the corresponding list, without making any changes to the base prefab.

Parameters
prefabPrefab
isOverrideIs marked as override

Definition at line 366 of file PrefabCollection.cs.

◆ AddOverrideFile()

void Barotrauma.PrefabCollection< T >.AddOverrideFile ( ContentFile  file)

Adds an override file to the collection.

Definition at line 457 of file PrefabCollection.cs.

◆ ContainsKey() [1/2]

bool Barotrauma.PrefabCollection< T >.ContainsKey ( Identifier  identifier)

Returns true if a prefab with the given identifier exists, false otherwise.

Parameters
identifierPrefab identifier
Returns
Whether a prefab with the given identifier exists or not

Definition at line 334 of file PrefabCollection.cs.

◆ ContainsKey() [2/2]

bool Barotrauma.PrefabCollection< T >.ContainsKey ( string  k)

◆ Find()

T? Barotrauma.PrefabCollection< T >.Find ( Predicate< T >  predicate)

Finds the first active prefab that returns true given the predicate, or null if no such prefab is found.

Parameters
predicatePredicate to perform the search with.
Returns

Definition at line 316 of file PrefabCollection.cs.

◆ GetEnumerator()

IEnumerator<T> Barotrauma.PrefabCollection< T >.GetEnumerator ( )

GetEnumerator implementation to enable foreach

Returns
IEnumerator

Definition at line 512 of file PrefabCollection.cs.

◆ IsOverride()

bool Barotrauma.PrefabCollection< T >.IsOverride ( prefab)

Determines whether a prefab is implemented as an override or not.

Parameters
prefabPrefab in this collection
Returns
Whether a prefab is implemented as an override or not

Definition at line 347 of file PrefabCollection.cs.

◆ Remove()

void Barotrauma.PrefabCollection< T >.Remove ( prefab)

Removes a prefab from the collection.

Parameters
prefabPrefab

Definition at line 419 of file PrefabCollection.cs.

◆ RemoveByFile()

void Barotrauma.PrefabCollection< T >.RemoveByFile ( ContentFile  file)

Removes all prefabs that were loaded from a certain file.

Definition at line 437 of file PrefabCollection.cs.

◆ RemoveOverrideFile()

void Barotrauma.PrefabCollection< T >.RemoveOverrideFile ( ContentFile  file)

Removes an override file from the collection.

Definition at line 470 of file PrefabCollection.cs.

◆ SortAll()

void Barotrauma.PrefabCollection< T >.SortAll ( )

Sorts all prefabs in the collection based on the content package load order.

Definition at line 483 of file PrefabCollection.cs.

◆ TryGet() [1/2]

bool Barotrauma.PrefabCollection< T >.TryGet ( Identifier  identifier,
[NotNullWhen(true)] out T?  result 
)

Returns true if a prefab with the identifier exists, false otherwise.

Parameters
identifierPrefab identifier
resultThe matching prefab (if one is found)
Returns
Whether a prefab with the identifier exists or not

Definition at line 285 of file PrefabCollection.cs.

◆ TryGet() [2/2]

bool Barotrauma.PrefabCollection< T >.TryGet ( string  identifier,
out T?  result 
)

Property Documentation

◆ AllPrefabs

IEnumerable<KeyValuePair<Identifier, PrefabSelector<T> > > Barotrauma.PrefabCollection< T >.AllPrefabs
get

AllPrefabs exposes all prefabs instead of just the active ones.

Definition at line 234 of file PrefabCollection.cs.

◆ Keys

IEnumerable<Identifier> Barotrauma.PrefabCollection< T >.Keys
get

Definition at line 308 of file PrefabCollection.cs.

◆ this[Identifier identifier]

T Barotrauma.PrefabCollection< T >.this[Identifier identifier]
get

Returns the active prefab with the given identifier.

Parameters
identifierPrefab identifier
Returns
Active prefab with the given identifier

Definition at line 252 of file PrefabCollection.cs.

◆ this[string identifier]

T Barotrauma.PrefabCollection< T >.this[string identifier]
get

Definition at line 267 of file PrefabCollection.cs.