Declaration files
Write a declaration file
Code Scry cannot read, such as a precompiled DLL, adds nothing to what Scry knows: a method calling it asks before it runs, and the values passed to it get no minimum, maximum or dropdown. A declaration file states facts about such code. Each entry, a key line naming a method and the facts below it, is a declaration.
To create one, go to Assets > Create > Scry > Declaration File, then edit it in your code editor. Select it to see its problems in the Inspector. A package can ship one; without Scry, it does nothing.
A key line names what the facts apply to, and the indented lines below it are its facts. # starts a comment. Parameters are C# type names; in facts, $0 or $name refers to a parameter.
method MyGame.MathUtil.Saturate(float)
returns range [0, 1]
effect pure
method MyPlugin.Audio.Play(string, float)
param $0 choices MyGame.Editor.SoundChoices
param $1 requires [0, 1]
Keys
| Key | Applies to |
|---|---|
method Type.Name(params) | One overload, or every overload without the parameters. |
get Type.Name, set Type.Name | A property's getter or setter. |
type Type | Every member of the type without a declaration of its own. |
attribute Type | Fields marked with the attribute. |
override Type.Name | Every override of a method. |
Facts
| Fact | Description |
|---|---|
effect pure | The method changes nothing, so it runs freely. |
effect undoable | The method changes only the object it is called on, so it runs as one undo step. |
effect irreversible "message" | The method does something Scry cannot undo, so it asks before it runs, naming the effect with the message. |
effect calledbyname | Something calls the method by name, as Unity calls Update, so Scry does not show it. |
notlive | Scry does not read the method again at every refresh, because each call logs or returns something new. |
messages | The call can run OnEnable and OnDisable. |
lifecycle assigned-before-awake | Fields marked with this attribute are set before Awake, as an injection framework sets them, so Scry never flags them as missing. |
returns range [lo, hi], returns magnitude [lo, hi] | The result, or its length, is within the range. |
returns clamp $p [lo, hi], returns wrap $p [lo, hi) | The result is the parameter, clamped or wrapped. |
returns min $a $b, max $a $b, oneof $a $b, copy $p | The result is one of the parameters. |
returns excludes value | The result is never the value. |
returns unit name, param $p unit name | The unit of the result or of the parameter, in plural words: seconds, meters, meters per second, meters per second squared. Units the code combines compose from it. |
param $p rejects value, requires [lo, hi], nonempty | Values the call rejects: Scry warns on them. |
param $p clamped [lo, hi], wrapped period | Values the call clamps or wraps around: Scry shows the limits at the ends of the field instead of warning. |
param $p fails | A rejected value makes the call throw or log an error, so Scry shows an error instead of a warning. |
param $p choices provider | The parameter takes one of the values a choice provider lists, shown as a dropdown. |
Choice providers
A choice provider lists the values a string parameter accepts, so the field shows a dropdown of them instead of a text field. The built-in providers are tags, layers, sorting-layers, scenes, animator-parameters, shader-properties, input-axes and methods. For your own, implement IScryChoiceProvider in an editor assembly, and name its full type in the fact:
public class SoundChoices : IScryChoiceProvider
{
public IEnumerable<string> GetChoices(ScryChoiceContext context)
{
return SoundLibrary.Names;
}
}
A package compiles its providers only when Scry is installed, through its assembly definition's Version Defines.