> For the complete documentation index, see [llms.txt](https://infinitypbr.gitbook.io/magic-pig-games/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://infinitypbr.gitbook.io/magic-pig-games/equipment-systems/prefab-and-object-manager/scripting-examples.md).

# Scripting Examples

Use the following methods to manage the Prefab Groups. Refer to `PrefabAndObjectManager.cs` for full detials.

**Activate a Group**\
Activating a group will turn on Game Objects and instantiate Prefabs. Depending on your settings, it may also automatically deactivate other groups.

```csharp
prefabAndObjectManager.ActivateGroup(groupName); // By name
prefabAndObjectManager.ActivateGroup(groupIndex); // By index
prefabAndObjectManager.ActivateGroup(prefabGroup); // By PrefabGroup
```

**Deactivate a Group**\
Deactivating a group will turn off Game Objects and destroy Prefabs. Depending on your settings, it may also automatically activate a group set as "Default".

```csharp
prefabAndObjectManager.DeactivateGroup(groupName); // By name
prefabAndObjectManager.DeactivateGroup(groupIndex); // By index
prefabAndObjectManager.DeactivateGroup(prefabGroup); // By PrefabGroup

// Deactivate all groups of a specific type
prefabAndObjectManager.DeactivateGroupsOfType(groupType);
```

**Check if a Group is Active**\
As groups may share objects, it is possible that a group is not active, fully active, or partially active, where some, but not all, of the objects are active.

```csharp
// By index
if (prefabAndObjectManager.GroupIsActive(groupIndex) == 0){
   Debug.Log("Group is not active");
}

// By PrefabGroup
if (prefabAndObjectManager.GroupIsActive(prefabGroup) == 1){
   Debug.Log("Group is partially active");
}

// By name
if (prefabAndObjectManager.GroupIsActive(groupName) == 2){
   Debug.Log("Group is fully active");
}

// 0 = Not active
// 1 = Partially active (some of the objects are active, but not all)
// 2 = Active
```

**Getting a `List<string>` of Types**\
If you need to obtain a list of all Types, perhaps for UI, this method will come in handy.

```csharp
// Cached version
foreach(var type in prefabAndObjectManager.GroupTypeNames(){
   Debug.Log($"Type: {type}");
}

// You can also use this method, though it will do more computation each time it is called.
foreach(var type in prefabAndObjectManager.GetGroupTypeNames()){
   Debug.Log($"Type: {type}");
}
```

**Getting a `List<PrefabGroup>` with All Groups of a Type**\
If you need to obtain a list of all Types, perhaps for UI, this method will come in handy.

```csharp
foreach(var type in prefabAndObjectManager.GetGroupsOfType(groupType)){
   Debug.Log($"Type: {type}");
}
```

**Get a Prefab Group**\
This will return a PrefabGroup object, for whatever purposes you see fit.

```csharp
var prefabGroup = prefabAndObjectManager.GetPrefabGroup(groupName);
```

**Activate a Random PrefabGroup**\
There are options for a single type, one from all types, or just one random group from a random type.

```csharp
// Random from a specific type
prefabAndObjectManager.ActivateRandomGroup(groupType);

// One random from all types
prefabAndObjectManager.ActivateRandomAllGroups();

// One random group from one random type
prefabAndObjectManager.ActivateRandomGroupType();
```
