> 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/other/runtime-color-sampler/scripting.md).

# Scripting

v1.1

The system allows for overriding the values, enabling custom UI experiences for your project. There are also some additional scripts included in the package which you may find useful.

{% hint style="success" %}
Many of the scripts have `virtual` methods. This means you can create your own child classes which override these methods with custom logic, or even add additional methods for your game.
{% endhint %}

## Blending Mode

**Runtime Color Settings** and **Runtime Color Listeners** have the option to blend colors, and can select different blend modes. The **Runtime Color Utilities** class contains the `BlendMode` `enum` with the following options:

* Replace
* Multiply
* Overlay
* Screen
* Soft Light
* Hard Light
* Difference
* Addition

## Runtime Color

You can get a **Runtime Color Settings** object by name.

{% code overflow="wrap" %}

```csharp
var settings = RuntimeColor.instance.Settings("Settings Object Name");
```

{% endcode %}

## Runtime Color Settings

Any changes made to the Runtime Color Settings will be passed to all of the Runtime Color Listeners which are watching the Settings. This is a convenient way to effect all of those objects at once.

### Override the Min or Max Color

```csharp
// Enable the override
runtimeColorSettings.OverrideMinColor(Color.white);
runtimeColorSettings.OverrideMaxColor(myColorValue);

// Disable the override
runtimeColorSettings.ResetMinColor();
runtimeColorSettings.ResetMaxColor();
```

### Blend Output to New Color

This will modify the output value to a specific color, blending from 0% to 100%, with the `float` `blendAmount` set from `0f` to `1f`. There are also blending options you can choose from.

{% hint style="info" %}
Blending the output to a new color on the Runtime Color Settings object happens before the option to do the same thing on objects which are listening to the Settings object. This means that any overrides on this will take in this output as input, and then override it for just that one object.
{% endhint %}

```csharp
runtimeColorSettings.SetBlendColor(colorValue);
runtimeColorSettings.SetBlendMode(RuntimeColorUtilities.BlendMode.Replace);
runtimeColorSettings.SetBlendAmount(0.75f);
```

### Sampling Rate & Manual Sampling

By default, the Runtime Color Sampler renders its camera and reads the average color 20 times per second, rather than every frame. The listener transitions smooth over the gaps, so visually this is indistinguishable from per-frame sampling — it just costs a lot less. You can change the rate in the Inspector or from code:

{% code overflow="wrap" %}

```
// Sample 10 times per secondRuntimeColor.instance.samplesPerSecond = 10f;
// Sample every frame (the camera stays enabled and renders normally)RuntimeColor.instance.samplesPerSecond = 0f;
```

{% endcode %}

You can also trigger a sample yourself at any moment, regardless of the schedule — useful right after a teleport, a camera cut, or a sudden lighting change:

{% code overflow="wrap" %}

```
RuntimeColor.instance.SampleNow();
```

{% endcode %}

Note: while `samplesPerSecond` is above 0, the sample camera component is intentionally disabled — the sampler renders it manually on the schedule. There's no need to enable it yourself.

***

### Using Your Own Assembly Definitions

The Runtime Color Sampler compiles into its own assembly, `MagicPigGames.RuntimeColorSampler`. If your scripts live in your project's default assembly (Assembly-CSharp) — which is the case unless you've created Assembly Definition files yourself — everything just works, no steps required.

If your code lives inside your own Assembly Definition (`.asmdef`), add a reference to `MagicPigGames.RuntimeColorSampler` in its **Assembly Definition References** list, otherwise you'll get errors like:

{% code overflow="wrap" %}

```
error CS0246: The type or namespace name 'RuntimeColorListener' could not be found
```

{% endcode %}

If you also use the shared utilities (the `MagicPigGames.Shared` namespace), reference `MagicPigGames.Shared` as well.

## Runtime Color Listener

### Blend Output to New Color

This will modify the output value to a specific color, blending from 0% to 100%, with the `float` `blendAmount` set from `0f` to `1f`. There are also blending options you can choose from.

```csharp
runtimeColorListener.SetBlendColor(colorValue);
runtimeColorListener.SetBlendMode(RuntimeColorUtilities.BlendMode.Replace);
runtimeColorListener.SetBlendAmount(0.75f);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://infinitypbr.gitbook.io/magic-pig-games/other/runtime-color-sampler/scripting.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
