Kerbal Space Program  1.12.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
Classes | Public Types | Public Member Functions | Protected Member Functions | Properties | List of all members
SoftMasking.SoftMask Class Reference

SoftMask is a component that can be added to UI elements for masking the children. It works like a standard Unity's Mask but supports alpha. More...

Inheritance diagram for SoftMasking.SoftMask:
SoftMasking.ISoftMask

Public Types

enum  BorderMode { BorderMode.Simple, BorderMode.Sliced, BorderMode.Tiled }
 How Sprite's borders should be processed. It is a reduced set of Image.Type values. More...
 
enum  Errors {
  Errors.NoError = 0, Errors.UnsupportedShaders = 1 << 0, Errors.NestedMasks = 1 << 1, Errors.TightPackedSprite = 1 << 2,
  Errors.AlphaSplitSprite = 1 << 3, Errors.UnsupportedImageType = 1 << 4, Errors.UnreadableTexture = 1 << 5
}
 Errors encountered during SoftMask diagnostics. Mostly intended to use in Unity Editor. More...
 
enum  MaskSource { MaskSource.Graphic, MaskSource.Sprite, MaskSource.Texture }
 Source of the mask's image. More...
 

Public Member Functions

bool IsRaycastLocationValid (Vector2 sp, Camera cam)
 
Errors PollErrors ()
 Checks for errors and returns them as flags. It is used in the editor to determine which warnings should be displayed. More...
 
 SoftMask ()
 

Protected Member Functions

virtual void LateUpdate ()
 
override void OnCanvasHierarchyChanged ()
 
override void OnDestroy ()
 
override void OnDidApplyAnimationProperties ()
 
override void OnDisable ()
 
override void OnEnable ()
 
override void OnRectTransformDimensionsChange ()
 
override void OnTransformParentChanged ()
 
override void Start ()
 

Properties

Color channelWeights [get, set]
 Specifies weights of the color channels of the mask. The color sampled from the mask texture is multiplied by this value, after what all components are summed up together. That is, the final mask value is calculated as: color = pixel-from-mask * channelWeights value = color.r + color.g + color.b + color.a The value is a number by which the resulting pixel's alpha is multiplied. As you can see, the result value isn't normalized, so, you should account it while defining custom values for this property. Static class MaskChannel contains some useful predefined values. You can use they as example of how mask calculation works. The default value is MaskChannel.alpha. More...
 
Shader defaultETC1Shader [get, set]
 Specifies a Shader that should be used as a replacement of the Unity's default UI shader with ETC1 (alpha-split) support. If you use ETC1 textures in UI and add SoftMask in play-time by AddComponent(), you should set this property manually. More...
 
Shader defaultShader [get, set]
 Specifies a Shader that should be used as a replacement of the Unity's default UI shader. If you add SoftMask in play-time by AddComponent(), you should set this property manually. More...
 
bool invertMask [get, set]
 If set, mask values inside the mask rectangle will be inverted. In this case mask's zero value (taking channelWeights into account) will be treated as one and vice versa. The mask rectangle is the RectTransform of the GameObject this component is attached to or separateMask if it's not null. The default value is false. More...
 
bool invertOutsides [get, set]
 If set, mask values outside the mask rectangle will be inverted. By default, everything outside the mask rectangle has zero mask value. When this property is set, the mask outsides will have value one, which means that everything outside the mask will be visible. The mask rectangle is the RectTransform of the GameObject this component is attached to or separateMask if it's not null. The default value is false. More...
 
bool isMaskingEnabled [get]
 Returns true if masking is currently active. More...
 
bool isUsingRaycastFiltering [get]
 Returns true if Soft Mask does raycast filtering, that is if the masked areas are transparent to input. More...
 
float raycastThreshold [get, set]
 Specifies the minimum mask value that the point should have for an input event to pass. If the value sampled from the mask is greater or equal this value, the input event is considered 'hit'. The mask value is compared with raycastThreshold after channelWeights applied. The default value is 0, which means that any pixel belonging to RectTransform is considered in input events. If you specify the value greater than 0, the mask's texture should be readable. Accepts values in range [0..1]. More...
 
RectTransform separateMask [get, set]
 Specifies a RectTransform that defines the bounds of the mask. Use of a separate RectTransform allows to move or resize mask bounds not affecting children. When null, the RectTransform of the current object is used. Default value is null. More...
 
MaskSource source [get, set]
 Determines from where the mask image should be taken. More...
 
Sprite sprite [get, set]
 Specifies a Sprite that should be used as the mask image. This property takes effect only when the source is MaskSource.Sprite. More...
 
BorderMode spriteBorderMode [get, set]
 Specifies the draw mode of sprite borders. This property takes effect only when the source is MaskSource.Sprite. More...
 
Texture2D texture [get, set]
 Specifies a Texture2D that should be used as the mask image. This property takes effect only when the source is MaskSource.Texture. More...
 
Rect textureUVRect [get, set]
 Specifies a normalized UV-space rectangle defining the image part that should be used as the mask image. This property takes effect only when the source is MaskSource.Texture. A value is set in normalized coordinates. The default value is (0, 0, 1, 1), which means that the whole texture is used. More...
 
- Properties inherited from SoftMasking.ISoftMask
bool isAlive [get]
 
bool isMaskingEnabled [get]
 

Detailed Description

SoftMask is a component that can be added to UI elements for masking the children. It works like a standard Unity's Mask but supports alpha.

Member Enumeration Documentation

How Sprite's borders should be processed. It is a reduced set of Image.Type values.

Enumerator
Simple 

Sprite should be drawn as a whole, ignoring any borders set. It works the same way as Unity's Image.Type.Simple.

Sliced 

Sprite borders should be stretched when the drawn image is larger that the source. It works the same way as Unity's Image.Type.Sliced.

Tiled 

The same as Sliced, but border fragments will be repeated instead of stretched. It works the same way as Unity's Image.Type.Tiled.

Errors encountered during SoftMask diagnostics. Mostly intended to use in Unity Editor.

Enumerator
NoError 
UnsupportedShaders 
NestedMasks 
TightPackedSprite 
AlphaSplitSprite 
UnsupportedImageType 
UnreadableTexture 

Source of the mask's image.

Enumerator
Graphic 

The mask image should be taken from the Graphic component of the containing GameObject. Only Image and RawImage components are supported. If there is no appropriate Graphic on the GameObject, a solid rectangle of the RectTransform dimensions will be used.

Sprite 

The mask image should be taken from an explicitly specified Sprite. When this mode is used, spriteBorderMode can also be set to determine how to process Sprite's borders. If the sprite isn't set, a solid rectangle of the RectTransform dimensions will be used. This mode is analogous to using an Image with according sprite and type set.

Texture 

The mask image should be taken from an explicitly specified Texture2D. When this mode is used, textureUVRect can also be set to determine what part of the texture should be used. If the texture isn't set, a solid rectangle of the RectTransform dimensions will be used. This mode is analogous to using a RawImage with according texture and uvRect set.

Constructor & Destructor Documentation

SoftMasking.SoftMask.SoftMask ( )
inline

Member Function Documentation

bool SoftMasking.SoftMask.IsRaycastLocationValid ( Vector2  sp,
Camera  cam 
)
inline
virtual void SoftMasking.SoftMask.LateUpdate ( )
inlineprotectedvirtual
override void SoftMasking.SoftMask.OnCanvasHierarchyChanged ( )
inlineprotected
override void SoftMasking.SoftMask.OnDestroy ( )
inlineprotected
override void SoftMasking.SoftMask.OnDidApplyAnimationProperties ( )
inlineprotected
override void SoftMasking.SoftMask.OnDisable ( )
inlineprotected
override void SoftMasking.SoftMask.OnEnable ( )
inlineprotected
override void SoftMasking.SoftMask.OnRectTransformDimensionsChange ( )
inlineprotected
override void SoftMasking.SoftMask.OnTransformParentChanged ( )
inlineprotected
Errors SoftMasking.SoftMask.PollErrors ( )
inline

Checks for errors and returns them as flags. It is used in the editor to determine which warnings should be displayed.

override void SoftMasking.SoftMask.Start ( )
inlineprotected

Property Documentation

Color SoftMasking.SoftMask.channelWeights
getset

Specifies weights of the color channels of the mask. The color sampled from the mask texture is multiplied by this value, after what all components are summed up together. That is, the final mask value is calculated as: color = pixel-from-mask * channelWeights value = color.r + color.g + color.b + color.a The value is a number by which the resulting pixel's alpha is multiplied. As you can see, the result value isn't normalized, so, you should account it while defining custom values for this property. Static class MaskChannel contains some useful predefined values. You can use they as example of how mask calculation works. The default value is MaskChannel.alpha.

Shader SoftMasking.SoftMask.defaultETC1Shader
getset

Specifies a Shader that should be used as a replacement of the Unity's default UI shader with ETC1 (alpha-split) support. If you use ETC1 textures in UI and add SoftMask in play-time by AddComponent(), you should set this property manually.

Shader SoftMasking.SoftMask.defaultShader
getset

Specifies a Shader that should be used as a replacement of the Unity's default UI shader. If you add SoftMask in play-time by AddComponent(), you should set this property manually.

bool SoftMasking.SoftMask.invertMask
getset

If set, mask values inside the mask rectangle will be inverted. In this case mask's zero value (taking channelWeights into account) will be treated as one and vice versa. The mask rectangle is the RectTransform of the GameObject this component is attached to or separateMask if it's not null. The default value is false.

See also
invertOutsides
bool SoftMasking.SoftMask.invertOutsides
getset

If set, mask values outside the mask rectangle will be inverted. By default, everything outside the mask rectangle has zero mask value. When this property is set, the mask outsides will have value one, which means that everything outside the mask will be visible. The mask rectangle is the RectTransform of the GameObject this component is attached to or separateMask if it's not null. The default value is false.

See also
invertMask
bool SoftMasking.SoftMask.isMaskingEnabled
get

Returns true if masking is currently active.

bool SoftMasking.SoftMask.isUsingRaycastFiltering
get

Returns true if Soft Mask does raycast filtering, that is if the masked areas are transparent to input.

float SoftMasking.SoftMask.raycastThreshold
getset

Specifies the minimum mask value that the point should have for an input event to pass. If the value sampled from the mask is greater or equal this value, the input event is considered 'hit'. The mask value is compared with raycastThreshold after channelWeights applied. The default value is 0, which means that any pixel belonging to RectTransform is considered in input events. If you specify the value greater than 0, the mask's texture should be readable. Accepts values in range [0..1].

RectTransform SoftMasking.SoftMask.separateMask
getset

Specifies a RectTransform that defines the bounds of the mask. Use of a separate RectTransform allows to move or resize mask bounds not affecting children. When null, the RectTransform of the current object is used. Default value is null.

MaskSource SoftMasking.SoftMask.source
getset

Determines from where the mask image should be taken.

Sprite SoftMasking.SoftMask.sprite
getset

Specifies a Sprite that should be used as the mask image. This property takes effect only when the source is MaskSource.Sprite.

BorderMode SoftMasking.SoftMask.spriteBorderMode
getset

Specifies the draw mode of sprite borders. This property takes effect only when the source is MaskSource.Sprite.

Texture2D SoftMasking.SoftMask.texture
getset

Specifies a Texture2D that should be used as the mask image. This property takes effect only when the source is MaskSource.Texture.

Rect SoftMasking.SoftMask.textureUVRect
getset

Specifies a normalized UV-space rectangle defining the image part that should be used as the mask image. This property takes effect only when the source is MaskSource.Texture. A value is set in normalized coordinates. The default value is (0, 0, 1, 1), which means that the whole texture is used.


The documentation for this class was generated from the following file: