Alongside the Sequencer tool, trueSKY can be driven and configured via Unity scripting. The settings and properties in trueSKY for Unity are split into three varieties: Keyframe properties (temporal values for clouds and sky), Layer properites (values for clouds and sky that persist throughout a sequence) and the properties of the trueSKY object itself (configuration settings).

The trueSKY Object

To modify trueSKY object via scripting, a reference to the active object in the scene must first be obtained (there should only be one). This can be done upon initialiation; the code to do so is as follows:

simul.trueSKY trueSky=simul.trueSKY.GetTrueSky();

All editor properties of the trueSKY object are publicly accessible, so once a reference to the trueSKY object has been obtained, they can also be accessed and modified via scripting. For example, to disable depth blending:

private trueSKY tS;  
 
void Start () 
{
	tS = trueSKY.GetTrueSky (); 
	tS.DepthBlending = false;
}

Sky and Clouds Layers

Layer properties are those accessible in the sequencer by clicking on “Sky”, “3D Clouds” or “2D clouds” on the left of the timeline. These affect the entire sequence and the values will remain until the user changes them manually. This differs in nature from keyframe properties, which are active only between specified times and will be automatically modified via interpolation (for example if two adjacent keyframes have cloudiness set to 0.4 and 0.6 respectively, trueSKY will interpolate these values for times in between, increasing gradually from 0.4 to 0.6). The functions needed to Get and Set layer properties are as follows:

Sky:

3D Clouds:

2D Clouds:

Example: To increment the 3D cloud layer rain speed by 5:

private trueSKY tS;  
 
	void Start () 
	{
		tS = trueSKY.GetTrueSky (); 
		tS.SetCloudFloat("rainFallSpeedMS", tS.GetCloudFloat("rainFallSpeedMS") + 5.0f);  
	}

For information about the layer properties you can change and the name strings needed to do so, see the Cloud and Sky pages.

Sky and Cloud Keyframes

Keyframes in trueSKY can be accessed, counted, modified, created and deleted via scripting. To delete a keyframe or change its properties, the Unique Identifier (Uid) will need to be known. These can be retrieved either by index (the keyframes in the sequencer, which are zero-indexed) or by retrieving the current/interpolated keyframe (not viewable in the sequencer, as they are interpolated). Uids are unique and persistent for the session, but not across saves or restarts, so they should not be stored. Note: For any functions with a layer parameter, the layer indexes are as follows: 0 for the sky, 1 for 3D Clouds and 2 for 2D Clouds.

Sky:

3D Clouds:

2D Clouds:

Once you know the Uid of a keyframe, you can then get the values of its properties, set said values or delete the keyframe. Whether you’re accessing/modifying sky, 3D cloud or 2D cloud keyframes, these tasks are accomplished via the following functions:

Example: In the script KeyframeTesting.cs in the Simul directory, is a function that sets all the cloud keyframes to have a “cloudiness” of 0.8 when the game is run:

int numk = trueSky.GetNumCloudKeyframes();
for(int i = 0; i < numk; i++)
{
	uint uid = trueSky.GetCloudKeyframeByIndex(i);
	trueSky.SetKeyframeValue(uid, "cloudiness", 0.8);
}

For information about the keyframe properties you can change and the name strings needed to do so, see the Cloud and Sky pages.

Other Functions

Queries

TrueSKY for Unity also provides some built in functions to carry out queries at given positions. It is possible to carry out cloud queries at a given position, and cloud line queries across two positions. These will return a VolumeQueryResult and a LineQueryResult respectively. Additionally there are more simplified functions for when you want just one value, for example, the amount of rain at a given position. Where applicable, id parameters should be given any unique integer (calling another query with the same id will overwrite the former). The functions are as follows:

The contents of the structs are as follows:

VolumeQueryResult:

LineQueryResult:

Storms

The centre of a storm can be set via the SetStormCentre (float x, float y) function. This is equivalent to setting the storm centre via the map window in the sequencer (hence only two axes).

Unity <-> trueSKY Coordinate Conversions

As Unity and trueSKY treat coordinates differently (which axis is considered “up”), these functions are provided to convert between them when needed:

Further Information

Next: Troubleshooting