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
  • Player Level
  • Custom Upgrade/Downgrade Logic
  • Skill Points Binding

Custom Logic

How to implement custom logic.

Player Level

Skills support player level requirements—preventing upgrading if the required level is not met. If you'd like to use custom logic to get the player level, use the SkillNode.playerLevelGetter field.

By default, the SkillWeb.playerLevel field is used. The example below sets a custom one.

public class PlayerLevelGetterExample : MonoBehaviour
{
    public int myPlayerLevel;

    private void Awake()
    {
        SkillNode.playerLevelGetter = () =>
        {
            return myPlayerLevel;
        };
    }
}

Custom Upgrade/Downgrade Logic

You can add on to the upgrade/downgrade prevention logic to add your own upgrade/downgrade requirements. You can implement your own logic by using the SkillNode.canUpgrade and SkillNode.canDowngrade fields. By default, both simply return true.

/// <summary>
/// Sets a custom upgrade method. This uses an example custom dataset.
/// </summary>
public void SetCustomUpgradeMethod()
{
    SkillNode.canUpgrade = skillNode =>
    {
        // Get the custom dataset
        var myDataset = skillNode.dataset as MySkillDataset;

        // Allow upgrading only if the skill is cool
        return myDataset.isCool;
    };
}

/// <summary>
/// Sets a custom downgrade method. This uses an example custom dataset.
/// </summary>
public void SetCustomDowngradeMethod()
{
    SkillNode.canDowngrade = skillNode =>
    {
        // Get the custom dataset
        var myDataset = skillNode.dataset as MySkillDataset;

        // Allow downgrading only if the skill is cool
        return myDataset.isCool;
    };
}

Skill Points Binding

By default, every Web simply uses the SkillWeb.skillPoints field as the reference of the player's current skill points. You can bind your own numeric skill points field for each web. The supported numeric types are int, float and double.

public class SkillPointsBinder : MonoBehaviour
{
    public float mySkillPoints;

    private void Awake()
    {
        // Get a web
        var myWebGraph = SkillWeb.GetWebGraph("My Web Graph");
        var myWeb = new Web(myWebGraph);

        // Bind a value
        myWeb.Bind(() => mySkillPoints, // Set skill points getter
            skillNode => (skillNode.dataset as MySkillDataset).cost, // Set skill cost getter (this example uses a custom dataset)
            x => mySkillPoints = x); // Set skill points setter  
    }
}
PreviousPlayer Web LinkNextSaving & Loading

Last updated 13 days ago