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
}
}
Last updated