{{description>Master Unity spline integration with Curvy Splines API! Customize projects seamlessly using our robust & feature-rich API. Explore now!}} ====== API Introduction ====== Curvy Splines provides a robust, feature-rich [[https://api.curvyeditor.com|API]], allowing for effortless integration and customization within your projects. All editor scripts in Curvy Splines are built using its API, guaranteeing full transparency and no concealed elements. Visit the [[https://api.curvyeditor.com|API Reference]] for more information. The best way to explore Curvy Splines' API is to browse the API reference or explore available properties and methods with intellisense right from Visual Studio or MonoDevelop.
IEnumerator Start ()
{
// Wait until the generator is fully intialized before accessing it:
while (!CurvyGenerator.IsInitialized)
yield return null;
// now we're safe to use it
CurvyGenerator.SomeMethod();
}
===== Fields, done propertly =====
This is a simple field:
public float Number;
The above code has just a single benefit: it's fast to write. Besides that, it's horrible for a number of good reasons:
* no input validation
* setting values might mark your scene dirty though the value hasn't changed
* no way to react to changes, e.g. refresh something
Instead, this is the same field (with some input validation added) done the right way:
[SerializeField]
float m_Number;
public float Number
{
get { return m_Number;}
set
{
float v=Mathf.Clamp01(value);
if (m_Number!=v)
m_Number=v;
}
}
#if UNITY_EDITOR
void OnValidate()
{
Number = m_Number;
}
#endif
Heck, that's pretty much code for a simple field. So, **why** this?
When accessing the field by code the property should be used and you can be sure that input is validated. The serialized field "m_Number" is used by inspectors instead with no input validation, but OnValidate() is called by the editor afterwards, so you can just set the property again to apply input validation and subsequent actions.
Having PropertyDrawers like //[Range(0,1)]// will add input validation to inspector fields, but then you're missing validation when setting the field from code.