# Script Generation

You can generate scripts to access members such as methods and properties.

Just select the member you want to access from the list and it will be created.
You can quickly implement it without having to write each script one by one.

## Condition

The conditions for members to have access are as follows.

- Must be a type defined in the Assembly Definition File or pre-compiled managed DLL
- Must be a public member of a public type
- Must be other than a generic type or method
- `LogicToolkit.IgnoreGeneratorAttribute` is not applied to the type or member

Default assemblies for scripts such as Assembly-CSharp are not included because they cannot be referenced from assemblies used to generate scripts.

## Supported member access

The supported member access is as follows.

### Get field

Create a script to get the field's value.

Menu notation

`Field name [Get]`

Component created

The component created changes depending on the field type.

Type of field | Component created | Description
--- | --- | ---
bool type | EvaluateComponent | Create a script that returns a value as the evaluation result.
Miscellaneous | ActionComponent | Create a script to get the value and output it from `OutputDataPort`.

In the case of delegate type or `UnityEvent` type, fields cannot be obtained and the script will wait for the event.

### Set field

Create a script to set the field's value.

Menu notation

`Field name [Set]`

Component created

ActionComponent

### Tween field

Create a script that gradually interpolates the value of a field until it reaches a specified value.
Only tweenable types can be generated.

Menu notation

`Field name [Tween]`

Component created

TaskComponent

### Get property

Create a script to get the property's value.

Menu notation

`Property name [Get]`

Component created

The component created varies depending on the property type.

Property type | Component created | Description
--- | --- | ---
bool type | EvaluateComponent | Create a script that returns a value as the evaluation result.
Miscellaneous | ActionComponent | Create a component that retrieves a value and outputs it from the `OutputDataPort`.

In the case of delegate type or `UnityEvent` type, properties cannot be obtained and it becomes an event waiting script.

### Set property

Create a script to set the property's value.

Menu notation

`Property name [Set]`

Component created

ActionComponent

### Tween property

Create a script that gradually interpolates the value of a property until it reaches a specified value. Only tweenable types can be generated.

Menu notation

`Property name [Tween]`

Component created

TaskComponent

### Waiting for the event

Create a script that waits for an event to be called.
Outputs the argument value received when the event is called from `OutputDataPort`.
Also, it does not support delegate types that require a return value.

Menu notation

`Member name`

Component created

EventComponent

### Invoke method

Create a script that invokes the method.

Menu notation

`Method name(arguments)`

Component created

The component created depends on the return type.

Return Type | Component Created | Description
--- | --- | ---
bool type | EvaluateComponent | Create a script that returns the return value as the evaluation result.
Miscellaneous | ActionComponent | Create a script that invokes the method.

If the method argument is out or ref, the result of the argument will also be output from `OutputDataPort` after execution.

### Invoke and await for awaitable methods

Create a script that invokes an awaitable method and awaits.

A method is awaitable if the return value is an awaitable type such as `System.Threading.Tasks.Task` (including custom types and extension methods that support waiting) or `UnityEngine.AsyncOperation`.
Please note that you can also use a normal method call script that does not wait even if the method is awaitable.

Menu notation

`Method name(arguments) [Await]`

Component created

TaskComponent

About the result value

For example, if you use `Task<bool>`, a bool type output port will be generated and the returned bool value will be output to that port.

If you use AsyncResult as the result value, the success or failure you set will be used as the execution result of the TaskComponent. If you use AsyncResult, you can set the value to be output in addition to the success or failure.

## How to create

You can create a script to access members in the following ways:

### Node/Component selection menu

- Open the graph view node creation menu and component selection menu
- Select the Members tab.
- Search by name of the member you want to access.
- Select the members you want to access.
- (If using the node creation menu, select the type of node to create.)

If you have already generated a script to access the selected member, use the existing script.
If it has not been generated yet, generation processing and compilation will be performed, and after completion, nodes will be created, etc.

Already generated scripts are also displayed in the Scripts tab.

### Logic Script Generator window

You can create multiple scripts in advance in the Logic Script Generator window.

- Select Logic Toolkit > Logic Script Generator from the menu to open the Logic Script Generator window.
- Click the “+” button on the left pane.
- Check the members you want to add from the tree.
- Click the “Add” button in the add menu.
- Return to the Logic Script Generator window and click the “Apply” button at the bottom of the left pane.

For details, see Logic Script Generator Window.

## Important point

Access information for members is managed using type names, member names, etc. If you change or delete members of a generated script later, a compilation error will occur. Open the “Logic Script Generator window” and modify or delete the relevant script.

If you change the type name, the migration will be done automatically by applying MovedFromAttribute.