Comment on page
ConvaiNPC Custom Editor Documentation
ConvaiNPCCustom Editor within the Unity Editor environment is designed to manage and maintain states of Convai scripts, ensuring a smooth and error-free workflow, especially when changes are made to game components.
Before diving into the functionalities, ensure that you're working within the Unity Editor environment as the script specifically targets editor functionalities.
_convaiNPC: Reference to the
ConvaiNPCcomponent on which this custom editor operates.
RootDirectory: Root directory path where the saved states of Convai scripts are stored.
OnEnable(): Initializes the
OnInspectorGUI(): Overridden inspector GUI to provide an "Apply changes" button, which, when clicked, confirms the user's decision and applies the changes.
ApplyChanges(): Applies component changes based on the user's selection in the inspector.
ApplyComponent<T>(): Applies or removes a specified component based on conditions. This function also handles saving or restoring component states.
SaveScriptState(): Saves the state of all Convai scripts in the active scene.
SceneSaved(): Hooks into the Unity's
sceneSavedevent and invokes
Utility extension methods to streamline the saving and restoring processes.
SaveStateToFile<T>(): Saves the state of a specific component to a file.
RestoreStateFromFile<T>(): Restores the state of a specific component from a file.
AddComponentSafe<T>(): Safely adds a component to a GameObject.
GetSavePath(): Generates the save path for a given script's state.
- 1.Adding Components & Saving State:
- Once the
ConvaiNPCcomponent is attached to a GameObject, you'll see the customized inspector.
- Adjust the settings and components as needed.
- Click the "Apply changes" button to apply your modifications. The system will confirm your actions before proceeding.
SaveScriptStateutility will automatically save the state of all Convai scripts when the scene is saved.
- 2.Restoring Component States:
- If a component was removed and needs to be added again, upon re-adding, the system will attempt to restore its state from the saved data.
Error when adding component: If you receive an error when trying to add a component via the editor, ensure that there are no conflicts with other scripts or missing references.
State restoration fails: If the state restoration process fails for a component, check the saved file's integrity and the
Note: Always ensure to have backups before making major changes or applying bulk operations.