Skill Web
  • Skill Web Documentation
  • 🕹️Quick Start
    • Installation
  • Start Developing
  • 💡General
    • Running the Demos
  • Menu Options
  • UI Customizations
    • uGUI
      • Skill Node
      • Connection Line
      • Web View
      • Hovercard
  • Datasets
  • 🎓Tutorials
    • Runes Demo Walkthrough
  • ✏️Editors
    • Skill Bank
  • Web Creator
  • Settings
  • Components
    • Skill Web Initializer
    • uGUI
      • Skill Node UGUI
      • Connection Line
        • Curved Connection Line
      • Web View UGUI
        • Web View Selector UGUI
      • Skill Hovercard UGUI
    • Player Web Link
  • 📄Scripting API
    • Initialization
  • Skills
    • Skill
      • Skill Dataset Attributes
    • Skill Node
  • Webs
    • Web Graph
    • Web
  • UI
    • Loading a Web
    • Web View Input Handling
    • Customize Connection Line
    • Customize Hovercard
  • Player Web Link
  • Custom Logic
  • Saving & Loading
  • Events
  • Skill Web Settings
  • Procedural Generation (Beta)
  • 🛠️Support
    • Getting Help
  • 📚Changelogs
    • Latest Releases
    • Future Plans
    • ⭐Rate Me?
Powered by GitBook
On this page
  1. UI

Customize Connection Line

Scripting customization of the connection line.

PreviousWeb View Input HandlingNextCustomize Hovercard

Last updated 26 days ago

The main connection line class is ConnectionLine. This class supports all of Skill Web's connection features, such as working with shaders (highlighting and setting active state), and it controls the line renderer to properly connect the first and last line points to the appropriate skills.

When customizing the connection line, it's recommended to create a class that inherits from it. There's already an example of this used by the demo, called CurvedConnectionLine.

Curved Connection Line (Customization Example)

Here were the steps used to create the CurvedConnectionLine class:

  1. Create a new class and inherit from ConnectionLine.

  2. Add custom variables. One for the control point (Vector3) and another for the number of line points (int).

  3. Override the UpdateLine method and add custom curve logic.

Below is the CurvedConnectionLine class for reference.

using UnityEngine;

/// <summary>
/// A connection line with support to curve like an arc.
/// </summary>
public class CurvedConnectionLine : ConnectionLine
{
    /// <summary>
    /// The curve control point.
    /// </summary>
    public Vector3 controlPoint = Vector3.zero;

    /// <summary>
    /// The number of points on the line. The more there are, the more smooth the line will look.
    /// </summary>
    [Min(2)]
    public int points = 2;

    public override void UpdateLine()
    {
        // Do nothing if there are no line points
        if (points <= 0)
        {
            return;
        }

        // Set the number of points
        lineRenderer.positionCount = points;

        // Get the first and final positions
        Vector3 p0;
        Vector3 p2;

        if (connection != null)
        {
            p0 = Input.rectTransform.anchoredPosition;
            p2 = Output.rectTransform.anchoredPosition;
        }
        else
        {
            p0 = startPosition;
            p2 = Output.rectTransform.anchoredPosition;
        }

        // Midpoint between start and end
        Vector3 mid = (p0 + p2) / 2;

        Vector3 p1 = mid + controlPoint;

        // Loop for number of points
        for (int i = 0; i < points; i++)
        {
            float t = i / (float)(points - 1);

            // Set each point with a curve formula (Quadratic Bézier formula)
            Vector3 point = Mathf.Pow(1 - t, 2) * p0 + 2 * (1 - t) * t * p1 + Mathf.Pow(t, 2) * p2;
            lineRenderer.SetPosition(i, point);
        }
    }
}
Runes