Skip to content

ScriptRef

Namespace: SideXP.Core.EditorOnly

public class ScriptRef

Represents a reference to a script in the project.

Constructors

ScriptRef(string)

public ScriptRef(string scriptPath)

Represents a reference to a script in the project.

Parameters

  • scriptPath

Properties

ScriptAsset

public MonoScript ScriptAsset

Loads the MonoScript that declares this script.

ScriptPath

public string ScriptPath

The path to the script asset, relative to project's directory.

ScriptContent

public string 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()

public Type 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)

public bool GetScriptType(out Type 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.