# Magic Leap Unity SDK Namespace Migration Tool Guide

## Introduction

Welcome to the Magic Leap Unity SDK Namespace Migration Tool guide. This tool is designed to help developers seamlessly migrate Magic Leap OpenXR scripts to new namespaces, improving API discoverability and maintaining clear distinctions between Magic Leap SDK components and Unity Engine scripts.

## Downloading the Tool

1. **Visit the Repository**: Navigate to the official Magic Leap GitHub repository where the Namespace Migration Tool is hosted.
2. **Download the Package**: Download the latest version of the `magicleap-namespace-tool.unitypackage`.

## Importing the Tool into Your Unity Project

1. **Open Your Unity Project**: Launch the Unity Editor and open the project where you intend to use the Namespace Migration Tool.
2. **Import the Package**:
   - In the Unity Editor, go to `Assets > Import Package > Custom Package`.
   - Locate and select the `magicleap-namespace-tool.unitypackage` file you downloaded.
   - In the Import Unity Package window, ensure all items are selected and click `Import`.

## Using the Namespace Migration Tool

### Updating Namespaces

1. **Open the Unity Editor**: Ensure your project is open in the Unity Editor.
2. **Access the Tool**: Navigate to `Magic Leap API Updater > Migrate Namespaces`.
3. **Backup Prompt**: A prompt will appear recommending you back up your project before proceeding.
4. **Choose Update Scope**: Select to update all scripts in your `Assets` folder or choose a specific directory.
5. **Monitor Progress**: The tool will display a progress bar indicating the status of the namespace migration.

### Restoring Original Scripts

1. **Access the Restore Option**: Select the `Magic Leap API Updater > Restore Original Script Files`.
2. **Confirmation Dialog**: A dialog will inform you that the current versions of the scripts will be reverted and cannot be restored unless tracked by source control tools.
3. **Restore Scripts**: If you choose to continue, the original scripts will be restored from the backups.

### Deleting Backup Files

1. **Access the Delete Option**: Select the `Magic Leap API Updater > Delete Script Backups`.
2. **Confirmation Dialog**: A dialog will inform you that the original versions of the scripts cannot be restored unless tracked by other source control tools.
3. **Confirm Deletion**: Confirm your intention to delete the backup files.
4. **Delete Backups**: All backup files and the tracking JSON file will be deleted.

## Additional Details

- **Backup Your Project**: It is highly recommended to back up your project before using the Namespace Migration tool to avoid any unintended data loss.
- **Source Control**: Utilize source control tools (e.g., Git) to track changes and manage script versions effectively.
- **Namespace Consistency**: Ensure all scripts are updated to use the new namespaces to maintain consistency and prevent compilation errors.
- **Tool Version Compatibility**: The Namespace Migration Tool is designed to work with Magic Leap SDK v2.3.0 or higher. Ensure your SDK version meets this requirement.

If you encounter any issues or have questions, refer to the [official documentation](https://developer-docs.magicleap.cloud/docs/guides/unity-openxr/getting-started/openxr-unity-getting-started/) or seek support from the [Magic Leap Developer forum](https://forum.magicleap.cloud/).

## Example Namespace Changes

To help illustrate the changes, here is an example of how a script using the LightEstimation feature would be updated:

```diff
using UnityEngine;
using UnityEngine.XR.OpenXR;
- using UnityEngine.XR.OpenXR.Features.MagicLeapSupport;
+ using MagicLeap.OpenXR.Features.LightEstimation;

public class LightEstimationSampleCode : MonoBehaviour
{
    private MagicLeapLightEstimationFeature _lightEstimationFeature;

-    private MagicLeapLightEstimationFeature.HDRCubemapFaceResolution cubemapFaceResolution;
+    private HDRCubemapFaceResolution cubemapFaceResolution;

    void Start()
    {
        // Obtain the Light Estimation Feature.
        _lightEstimationFeature = OpenXRSettings.Instance.GetFeature<MagicLeapLightEstimationFeature>();

        // Create the light estimation.
        _lightEstimationFeature.CreateLightEstimation(cubemapFaceResolution);
    }
}
```
