ScriptRef¶
Namespace:
SideXP.Core.EditorOnly
Represents a reference to a script in the project.
Constructors¶
ScriptRef(string)¶
Represents a reference to a script in the project.
Parameters
scriptPath
Properties¶
ScriptAsset¶
Loads the MonoScript that declares this script.
ScriptPath¶
The path to the script asset, relative to project's directory.
ScriptContent¶
The content of the script as plain text.
Remarks
Since we must read the script to actually extract its Type, we can store its content in the process, so we can use it in assets processor or any tool related to scripts.
Methods¶
GetScriptType()¶
Gets the declared type in a script file.
Returns
Returns the extracted type.
Remarks
Unity API has a GetClass function, but it doesn't work with structs and interfaces. This function uses both regular expressions and reflection, and so is able to get the declared type whatever its nature. This also applies to text, which logs an error that can't be handled as an exception if the asset is about to be deleted. We prefer using a custom implementation to read the script, making this function actually usable in an OnWillDelete() message.
GetScriptType(Type)¶
Gets the declared type in a script file.
Returns
Returns true if this script's type has been extracted successfully.
Remarks
Unity API has a GetClass function, but it doesn't work with structs and interfaces. This function uses both regular expressions and reflection, and so is able to get the declared type whatever its nature. This also applies to text, which logs an error that can't be handled as an exception if the asset is about to be deleted. We prefer using a custom implementation to read the script, making this function actually usable in an OnWillDelete() message.