Linking AC and Bolt variables

This script allows Global Variables made with AC to be linked with Application and Saved variables made with Bolt.

To use it:

1. Create a new Global Variable in AC's Variables Manager, and set it's **Link** **to** field to **Custom Script.**
2. Create a new Application or Saved variable in Bolt's Variables window, and have it match the type made in AC (Float, Boolean, etc)
3. Paste the code below into a C# script named **BoltVariableLink.cs**, and attach it to a GameObject in the scene
4. In the component's Inspector, increase the **Size** field by 1, and fill in the fields that appear.  The AC Variable ID is the number that appears beside a variable's name in the Variables Manager

The variables will now be linked - so changing its value in one asset will update the value of its associated variable in the other.

BoltVariableLink.cs

```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using AC;
using Bolt;

public class BoltVariableLink : MonoBehaviour
{

 [SerializeField] BoltVarLink[] boltVarLinks;

 private void OnEnable ()
 {
 EventManager.OnDownloadVariable += OnDownload;
 EventManager.OnUploadVariable += OnUpload;
 }

 private void OnDisable ()
 {
 EventManager.OnDownloadVariable -= OnDownload;
 EventManager.OnUploadVariable -= OnUpload;
 }

 private void OnDownload (GVar variable, AC.Variables variables)
 {
 foreach (BoltVarLink boltVarLink in boltVarLinks)
 {
 boltVarLink.Download (variable);
 }
 }

 private void OnUpload (GVar variable, AC.Variables variables)
 {
 foreach (BoltVarLink boltVarLink in boltVarLinks)
 {
 boltVarLink.Upload (variable);
 }
 }

 [System.Serializable] private class BoltVarLink
 {

 [SerializeField] private string boltVariableName = "";
 [SerializeField] private BoltVariableType boltVariableType = BoltVariableType.Application;
 private enum BoltVariableType { Application, Saved };
 [SerializeField] private int acVariableID = 0;

 public void Download (GVar variable)
 {
 if (!string.IsNullOrEmpty (boltVariableName) && variable.id == acVariableID)
 {
 if (boltVariableType == BoltVariableType.Application)
 {
 switch (variable.type)
 {
 variable.IntegerValue = (int) Bolt.Variables.Application.Get (boltVariableName);
 break;

 case VariableType.Boolean:
 variable.BooleanValue = (bool) Bolt.Variables.Application.Get (boltVariableName);
 break;

 case VariableType.Float:
 variable.FloatValue = (float) Bolt.Variables.Application.Get (boltVariableName);
 break;

 case VariableType.String:
 variable.TextValue = (string) Bolt.Variables.Application.Get (boltVariableName);
 break;

 case VariableType.Vector3:
 variable.Vector3Value = (Vector3) Bolt.Variables.Application.Get (boltVariableName);
 break;

 default:
 break;
 }
 }
 else if (boltVariableType == BoltVariableType.Saved)
 {
 switch (variable.type)
 {
 variable.IntegerValue = (int) Bolt.Variables.Saved.Get (boltVariableName);
 break;

 case VariableType.Boolean:
 variable.BooleanValue = (bool) Bolt.Variables.Saved.Get (boltVariableName);
 break;

 case VariableType.Float:
 variable.FloatValue = (float) Bolt.Variables.Saved.Get (boltVariableName);
 break;

 case VariableType.String:
 variable.TextValue = (string) Bolt.Variables.Saved.Get (boltVariableName);
 break;

 case VariableType.Vector3:
 variable.Vector3Value = (Vector3) Bolt.Variables.Saved.Get (boltVariableName);
 break;

 default:
 break;
 }
 }
 }
 }

 public void Upload (GVar variable)
 {
 AC.KickStarter.stateHandler.IsPaused ();
 if (!string.IsNullOrEmpty (boltVariableName) && variable.id == acVariableID)
 {
 if (boltVariableType == BoltVariableType.Application)
 {
 switch (variable.type)
 {
 Bolt.Variables.Application.Set (boltVariableName, variable.IntegerValue);
 break;

 case VariableType.Boolean:
 Bolt.Variables.Application.Set (boltVariableName, variable.BooleanValue);
 break;

 case VariableType.Float:
 Bolt.Variables.Application.Set (boltVariableName, variable.FloatValue);
 break;

 case VariableType.String:
 Bolt.Variables.Application.Set (boltVariableName, variable.TextValue);
 break;

 case VariableType.Vector3:
 Bolt.Variables.Application.Set (boltVariableName, variable.Vector3Value);
 break;

 default:
 break;
 }
 }
 else if (boltVariableType == BoltVariableType.Saved)
 {
 switch (variable.type)
 {
 Bolt.Variables.Saved.Set (boltVariableName, variable.IntegerValue);
 break;

 case VariableType.Boolean:
 Bolt.Variables.Saved.Set (boltVariableName, variable.BooleanValue);
 break;

 case VariableType.Float:
 Bolt.Variables.Saved.Set (boltVariableName, variable.FloatValue);
 break;

 case VariableType.String:
 Bolt.Variables.Saved.Set (boltVariableName, variable.TextValue);
 break;

 case VariableType.Vector3:
 Bolt.Variables.Saved.Set (boltVariableName, variable.Vector3Value);
 break;

 default:
 break;
 }
 }
 }
 }

 }

}

```