Scripting

v1.0

The demo scene has a demo game controller, which calls many of these methods, if you'd like to see them in action.

Setting Values

Set the UI Color

The UI Color is set on the Portrait UI component for all portraits. Each of these will call the similar method on the portraitUI class.

There is an optional bool instant argument, default false. When true, the color will be set instantly, otherwise it will be transitioned to, based on the transition values in the Portrait UI.

There is also an optional bool onlySetFirstItem argument, also default false. When this is true, only the first Image in the list of border UI elements will be set.

You can also pass in a specific index to set the value for only one in game portrait.

If Portraits Realtime Color is enabled, that may be controlling the border color, in which case any values you Set here will be ignored.

// Set the border color for all avatars
PortraitAvatars.instance.SetBorderColor(colorValue);

// Instantly set the border color for a specific avatar, including all UI elements
// onlySetFirstItem is false
// instant is true
PortraitAvatars.instance.SetBorderColor(colorValue, inGameAvatarIndex, false, true);

Set Background Color (3D Avatars)

The Background Color is set on the Avatar Camera for 3D avatars. Each of these will ultimately call the similar method on the avatarCamera component attached to the Portrait3D class on your in game portrait.

There is an optional bool instant argument, default false. When true, the color will be set instantly, otherwise it will be transitioned to, based on the transition values in the Avatar Camera.

You can also pass in a specific index to set the value for only one in game portrait.

// Set the background color for all 3D avatars
PortraitAvatars.instance.SetBackgroundColor(colorValue);

// Instantly set the background color for a specific 3D avatar
PortraitAvatars.instance.SetBackgroundColor(colorValue, inGameAvatarIndex, true);

Set Light Color (3D Avatars)

The Light color is set on the Portrait 3D for 3D avatars. Each of these will ultimately call the similar method on the portrait3D component.

There is an optional bool instant argument, default false. When true, the color will be set instantly, otherwise it will be transitioned to, based on the transition values in the portrait3D.

There is also an optional bool onlySetFirstItem argument, also default false. When this is true, only the first Light in the list of lights will be set.

You can also pass in a specific index to set the value for only one in game portrait.

// Set the light color for all 3D avatar lights
PortraitAvatars.instance.SetLightColor(colorValue);

// Instantly set the color for a specific 3D avatar
PortraitAvatars.instance.SetLightColor(colorValue, inGameAvatarIndex, false, true);

Set Light Intensity (3D Avatars)

The Light intensity is set on the Portrait 3D for 3D avatars. Each of these will ultimately call the similar method on the portrait3D component.

There is an optional bool instant argument, default false. When true, the color will be set instantly, otherwise it will be transitioned to, based on the transition values in the portrait3D.

There is also an optional bool onlySetFirstItem argument, also default false. When this is true, only the first Light in the list of lights will be set.

You can also pass in a specific index to set the value for only one in game portrait.

// Set the light intensity for all 3D avatar lights
PortraitAvatars.instance.SetLightIntensity(1.2f);

// Instantly set the intensity for a specific 3D avatar
PortraitAvatars.instance.SetLightIntensity(0.8f, inGameAvatarIndex, false, true);

Caching Values

When a new portrait is created, it will use the cached color values when the "cache" toggles are true in the Inspector. These methods are called whenever you Set a value, but you can also call them directly outside of the Set methods.

PortraitAvatars.instance.CacheBackgroundColor(colorValue);
PortraitAvatars.instance.CacheLightColor(colorValue);
PortraitAvatars.instance.CacheLightIntensity(0.5f);
PortraitAvatars.instance.CacheBorderColor(colorValue);

Last updated