X Tutup

Scripting Support (C#)

advanced scripting

Highlight Plus 2D · Scripting Support (C#)

The HighlightPlus2D namespace provides a 2D-focused highlighting system for sprites and UI elements. Add using HighlightPlus2D; at the top of your scripts.

HighlightEffect2D

MonoBehaviour — The main component that controls all highlight effects on 2D sprites. Attach to any GameObject with a SpriteRenderer or Image component.

Highlight Control

bool highlighted get/set

Enables or disables the highlight effect. Setting this triggers fade animations if fadeInDuration/fadeOutDuration are configured.

bool ignore

When true, the object will not be highlighted by automatic systems (HighlightManager2D/HighlightTrigger2D).

float fadeInDuration

Duration in seconds for the highlight fade-in animation.

float fadeOutDuration

Duration in seconds for the highlight fade-out animation.

bool previewInEditor

When true, the highlight effect is visible in the Scene view during edit mode.

void SetHighlighted(bool state)

Programmatically sets the highlight state. Equivalent to setting the highlighted property.

Target & Geometry

TargetOptions effectGroup

Determines which renderers are included (Children, OnlyThisObject, RootToChildren, etc.).

LayerMask effectGroupLayer

Layer mask filter applied when effectGroup uses layer-based targeting.

Transform target

Optional explicit target transform for the effect.

bool occluder

When true, this object acts as an occluder for see-through effects on other objects.

bool polygonPacking

Enables tight polygon packing for more accurate sprite outlines that follow the sprite shape.

bool preserveMesh

Preserves the original mesh shape when computing the highlight mesh.

void SetTarget(Transform transform)

Sets a new target transform and re-initializes the effect on the new hierarchy.

Rendering Options

int renderingLayer

Sorting layer used for rendering the highlight effect.

bool alwaysOnTop

When true, the effect renders on top of all other sprites regardless of sorting order.

float alphaCutOff

Alpha cutoff threshold. Pixels with alpha below this value are excluded from the highlight effect.

bool pixelSnap

Enables pixel snapping for pixel-art games to prevent sub-pixel rendering artifacts.

bool autoSize

Automatically calculates the effect size based on the sprite bounds.

Vector2 center

Custom center offset for the effect when autoSize is disabled.

Vector2 scale

Custom scale for the effect when autoSize is disabled.

float aspectRatio

Aspect ratio override for the effect bounds.

Vector2 pivotPos

Pivot position offset for the effect.

float zoomScale

Scale multiplier applied to the sprite when highlighted, creating a zoom/grow effect.

Outline

float outline

Outline intensity. 0 disables the outline, 1 is fully visible.

Color outlineColor

Outline color.

float outlineWidth

Width of the outline effect.

QualityLevel outlineQuality

Quality of the outline rendering (Low, Medium, High).

bool outlineSmooth

Enables anti-aliased smoothing on the outline edges.

bool outlineExclusive

When true, only the outline renders without the glow or other effects, creating a clean outline-only look.

Outer Glow

float glow

Outer glow intensity. 0 disables the glow.

float glowWidth

Width of the outer glow effect.

QualityLevel glowQuality

Quality of the glow rendering.

GlowPassData[] glowPasses

Array of glow pass configurations with individual offset, width, and color per pass.

float glowAnimationSpeed

Animation speed of the glow pulsing effect.

bool glowSmooth

Enables smoothing on the glow edges.

bool glowDithering

Applies dithering to reduce banding artifacts in the glow.

void SetGlowColor(Color color)

Sets the glow color for all glow passes at once.

Overlay

float overlay

Overlay intensity. 0 disables the overlay effect.

Color overlayColor

Color of the overlay effect.

float overlayAnimationSpeed

Speed of the overlay pulsing animation.

float overlayMinIntensity

Minimum intensity during overlay animation cycles.

float overlayBlending

Controls the blending strength of the overlay with the underlying sprite.

int overlayRenderQueue

Custom render queue value for the overlay material.

Shadow

float shadowIntensity

Intensity of the drop shadow effect. 0 disables shadows.

Color shadowColor

Color of the drop shadow.

Vector2 shadowOffset

Offset of the shadow in X and Y directions.

bool shadow3D

Enables 3D perspective shadow mode for an isometric/3D look.

bool shadowDithering

Applies dithering to the shadow edge for softer appearance.

See-Through

SeeThroughMode seeThrough

See-through rendering mode (Never, WhenHighlighted, AlwaysWhenOccluded).

float seeThroughIntensity

Intensity of the see-through silhouette.

Color seeThroughTintColor

Tint color of the see-through silhouette.

float seeThroughTintAlpha

Alpha transparency of the see-through tint.

float seeThroughNoise

Amount of noise/scanline effect applied to the see-through silhouette.

Hit FX

void HitFX(Color color, float fadeOutDuration, float initialIntensity = 1f)

Triggers a hit flash effect. The color tints the sprite, fading out over fadeOutDuration seconds starting at initialIntensity (0-1).

Events

event OnObjectHighlightStart(GameObject obj, ref bool cancelHighlight)

Fired when the object begins highlighting. Set cancelHighlight to true to prevent the highlight.

event OnObjectHighlightEnd(GameObject obj)

Fired when the highlight is removed from the object.

Utility Methods

void Refresh()

Re-initializes the effect. Call after changing the sprite or target hierarchy.

void UpdateMaterialProperties()

Updates all internal material properties. Call after changing effect settings via script.

HighlightManager2D

MonoBehaviour — Automatic highlight management for 2D scenes. Add to a scene to enable pointer-based highlighting for all objects with HighlightEffect2D components. Uses 2D raycasting to detect sprites under the cursor.

Properties

static instance HighlightManager2D — read-only

Singleton reference to the HighlightManager2D in the scene.

HighlightOnEvent highlightEvent

Controls when highlighting occurs (OnOverAndClick, OnlyOnOver, OnlyOnClick).

float highlightDuration

Maximum duration of the highlight in seconds. 0 means unlimited (stays highlighted while hovered).

LayerMask layerMask

Layer mask for 2D raycast detection. Only sprites on these layers can be highlighted.

Camera raycastCamera

Camera used for raycasting. Defaults to Camera.main if not set.

RayCastSource raycastSource

Input source for raycasting (MousePosition, ScreenCenter).

Events

event OnObjectHighlightStart(GameObject obj, ref bool cancelHighlight)

Fired when the pointer enters a sprite. Set cancelHighlight to true to prevent highlighting.

event OnObjectHighlightEnd(GameObject obj)

Fired when the pointer leaves a highlighted sprite.

Methods

static GetCamera Camera ()

Returns the active camera used for raycasting.

HighlightTrigger2D

MonoBehaviour — Per-object trigger component for 2D highlight interaction. Unlike HighlightManager2D (scene-wide), HighlightTrigger2D provides per-sprite control over input detection.

Properties

HighlightOnEvent highlightEvent

Controls when highlighting occurs (OnOverAndClick, OnlyOnOver, OnlyOnClick).

float highlightDuration

Maximum duration of the highlight in seconds. 0 means unlimited.

TriggerMode triggerMode

Detection method for the trigger (Collider2DEvents, Raycast).

Camera raycastCamera

Camera used for raycasting. Defaults to Camera.main.

RayCastSource raycastSource

Input source for raycasting (MousePosition, ScreenCenter).

Code Examples

Basic Sprite Highlighting

using UnityEngine;
using HighlightPlus2D;

public class SpriteHighlight : MonoBehaviour
{
    void Start()
    {
        HighlightEffect2D effect = gameObject.AddComponent<HighlightEffect2D>();

        // Outline
        effect.outline = 1f;
        effect.outlineColor = Color.cyan;
        effect.outlineWidth = 0.8f;

        // Outer glow
        effect.glow = 1.5f;
        effect.glowWidth = 0.6f;

        // Overlay
        effect.overlay = 0.5f;
        effect.overlayColor = Color.yellow;
        effect.overlayAnimationSpeed = 2f;

        effect.UpdateMaterialProperties();
        effect.highlighted = true;
    }
}

Hit Flash on Damage

using UnityEngine;
using HighlightPlus2D;

public class SpriteDamageFlash : MonoBehaviour
{
    HighlightEffect2D effect;

    void Awake()
    {
        effect = GetComponent<HighlightEffect2D>();
    }

    public void TakeDamage()
    {
        // White flash that fades over 0.3 seconds
        effect.HitFX(Color.white, 0.3f, 1f);
    }
}

Event-Based Interaction

using UnityEngine;
using HighlightPlus2D;

public class SpriteInteraction : MonoBehaviour
{
    void Start()
    {
        HighlightEffect2D effect = GetComponent<HighlightEffect2D>();
        effect.OnObjectHighlightStart += OnHighlight;
        effect.OnObjectHighlightEnd += OnUnhighlight;
    }

    void OnHighlight(GameObject obj, ref bool cancel)
    {
        Debug.Log($"Hovering: {obj.name}");
        // Set cancel = true to prevent highlighting
    }

    void OnUnhighlight(GameObject obj)
    {
        Debug.Log($"Left: {obj.name}");
    }
}
Was this page helpful?
X Tutup