Adventure Creator Wikia
(Updated to latest AC)
Tag: Visual edit
(Fixed setting bolt saved variables)
Tag: Visual edit
 
Line 8: Line 8:
 
The variables will now be linked - so changing its value in one asset will update the value of its associated variable in the other.
 
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
+
BoltVariableLink.cs<syntaxhighlight lang="csharp">
using System.Collections;<br>
+
using System.Collections;
using System.Collections.Generic;<br>
+
using System.Collections.Generic;
using UnityEngine;<br>
+
using UnityEngine;
using AC;<br>
+
using AC;
using Bolt;<br>
+
using Bolt;
  +
<br>
 
public class BoltVariableLink : MonoBehaviour<br>
+
public class BoltVariableLink : MonoBehaviour
  +
{
{<br>
 
  +
<br>
 
[SerializeField] BoltVarLink[] boltVarLinks;<br>
+
[SerializeField] BoltVarLink[] boltVarLinks;
  +
<br>
 
  +
private void OnEnable ()
<br>
 
  +
{
private void OnEnable ()<br>
 
  +
EventManager.OnDownloadVariable += OnDownload;
{<br>
 
EventManager.OnDownloadVariable += OnDownload;<br>
+
EventManager.OnUploadVariable += OnUpload;
  +
}
EventManager.OnUploadVariable += OnUpload;<br>
 
  +
}<br>
 
  +
private void OnDisable ()
<br>
 
  +
{
<br>
 
  +
EventManager.OnDownloadVariable -= OnDownload;
private void OnDisable ()<br>
 
  +
EventManager.OnUploadVariable -= OnUpload;
{<br>
 
  +
}
EventManager.OnDownloadVariable -= OnDownload;<br>
 
  +
EventManager.OnUploadVariable -= OnUpload;<br>
 
  +
private void OnDownload (GVar variable, AC.Variables variables)
}<br>
 
  +
{
<br>
 
  +
foreach (BoltVarLink boltVarLink in boltVarLinks)
<br>
 
  +
{
private void OnDownload (GVar variable, AC.Variables variables)<br>
 
  +
boltVarLink.Download (variable);
{<br>
 
  +
}
foreach (BoltVarLink boltVarLink in boltVarLinks)<br>
 
  +
}
{<br>
 
  +
boltVarLink.Download (variable);<br>
 
  +
private void OnUpload (GVar variable, AC.Variables variables)
}<br>
 
  +
{
}<br>
 
  +
foreach (BoltVarLink boltVarLink in boltVarLinks)
<br>
 
  +
{
<br>
 
  +
boltVarLink.Upload (variable);
private void OnUpload (GVar variable, AC.Variables variables)<br>
 
  +
}
{<br>
 
  +
}
foreach (BoltVarLink boltVarLink in boltVarLinks)<br>
 
  +
{<br>
 
  +
boltVarLink.Upload (variable);<br>
 
  +
[System.Serializable] private class BoltVarLink
}<br>
 
  +
{
}<br>
 
  +
<br>
 
  +
[SerializeField] private string boltVariableName = "";
<br>
 
  +
[SerializeField] private BoltVariableType boltVariableType = BoltVariableType.Application;
[System.Serializable] private class BoltVarLink<br>
 
  +
private enum BoltVariableType { Application, Saved };
{<br>
 
  +
[SerializeField] private int acVariableID = 0;
<br>
 
  +
[SerializeField] private string boltVariableName = "";<br>
 
  +
public void Download (GVar variable)
[SerializeField] private BoltVariableType boltVariableType = BoltVariableType.Application;<br>
 
  +
{
private enum BoltVariableType { Application, Saved };<br>
 
  +
if (!string.IsNullOrEmpty (boltVariableName) && variable.id == acVariableID)
[SerializeField] private int acVariableID = 0;<br>
 
  +
{
<br>
 
  +
if (boltVariableType == BoltVariableType.Application)
<br>
 
  +
{
public void Download (GVar variable)<br>
 
  +
switch (variable.type)
{<br>
 
  +
{
if (!string.IsNullOrEmpty (boltVariableName) && variable.id == acVariableID)<br>
 
  +
case VariableType.Integer:
{<br>
 
  +
case VariableType.PopUp:
if (boltVariableType == BoltVariableType.Application)<br>
 
  +
variable.IntegerValue = (int) Bolt.Variables.Application.Get (boltVariableName);
{<br>
 
  +
break;
switch (variable.type)<br>
 
  +
{<br>
 
case VariableType.Integer:<br>
+
case VariableType.Boolean:
  +
variable.BooleanValue = (bool) Bolt.Variables.Application.Get (boltVariableName);
case VariableType.PopUp:<br>
 
  +
break;
variable.IntegerValue = (int) Bolt.Variables.Application.Get (boltVariableName);<br>
 
  +
break;<br>
 
  +
case VariableType.Float:
<br>
 
  +
variable.FloatValue = (float) Bolt.Variables.Application.Get (boltVariableName);
case VariableType.Boolean:<br>
 
  +
break;
variable.BooleanValue = (bool) Bolt.Variables.Application.Get (boltVariableName);<br>
 
  +
break;<br>
 
  +
case VariableType.String:
 
  +
variable.TextValue = (string) Bolt.Variables.Application.Get (boltVariableName);
<br>
 
  +
break;
case VariableType.Float:<br>
 
  +
variable.FloatValue = (float) Bolt.Variables.Application.Get (boltVariableName);<br>
 
  +
case VariableType.Vector3:
break;<br>
 
  +
variable.Vector3Value = (Vector3) Bolt.Variables.Application.Get (boltVariableName);
<br>
 
  +
break;
case VariableType.String:<br>
 
  +
variable.TextValue = (string) Bolt.Variables.Application.Get (boltVariableName);<br>
 
break;<br>
+
default:
  +
break;
<br>
 
  +
}
case VariableType.Vector3:<br>
 
  +
}
variable.Vector3Value = (Vector3) Bolt.Variables.Application.Get (boltVariableName);<br>
 
  +
else if (boltVariableType == BoltVariableType.Saved)
break;<br>
 
}<br>
+
{
  +
switch (variable.type)
}<br>
 
  +
{
else if (boltVariableType == BoltVariableType.Saved)<br>
 
  +
case VariableType.Integer:
{<br>
 
  +
case VariableType.PopUp:
switch (variable.type)<br>
 
  +
variable.IntegerValue = (int) Bolt.Variables.Saved.Get (boltVariableName);
{<br>
 
  +
break;
case VariableType.Integer:<br>
 
  +
case VariableType.PopUp:<br>
 
  +
case VariableType.Boolean:
variable.IntegerValue = (int) Bolt.Variables.Saved.Get (boltVariableName);<br>
 
  +
variable.BooleanValue = (bool) Bolt.Variables.Saved.Get (boltVariableName);
break;<br>
 
  +
break;
<br>
 
  +
case VariableType.Boolean:<br>
 
  +
case VariableType.Float:
variable.BooleanValue = (bool) Bolt.Variables.Saved.Get (boltVariableName);<br>
 
  +
variable.FloatValue = (float) Bolt.Variables.Saved.Get (boltVariableName);
break;<br>
 
+
break;
  +
<br>
 
case VariableType.Float:<br>
+
case VariableType.String:
variable.FloatValue = (float) Bolt.Variables.Saved.Get (boltVariableName);<br>
+
variable.TextValue = (string) Bolt.Variables.Saved.Get (boltVariableName);
break;<br>
+
break;
  +
<br>
 
case VariableType.String:<br>
+
case VariableType.Vector3:
variable.TextValue = (string) Bolt.Variables.Saved.Get (boltVariableName);<br>
+
variable.Vector3Value = (Vector3) Bolt.Variables.Saved.Get (boltVariableName);
break;<br>
+
break;
  +
<br>
 
  +
default:
case VariableType.Vector3:<br>
 
  +
break;
variable.Vector3Value = (Vector3) Bolt.Variables.Saved.Get (boltVariableName);<br>
 
break;<br>
+
}
}<br>
+
}
}<br>
+
}
}<br>
+
}
  +
}<br>
 
  +
public void Upload (GVar variable)
<br>
 
  +
{
<br>
 
  +
AC.KickStarter.stateHandler.IsPaused ();
public void Upload (GVar variable)<br>
 
  +
if (!string.IsNullOrEmpty (boltVariableName) && variable.id == acVariableID)
{<br>
 
  +
{
if (!string.IsNullOrEmpty (boltVariableName) && variable.id == acVariableID)<br>
 
  +
if (boltVariableType == BoltVariableType.Application)
{<br>
 
  +
{
if (boltVariableType == BoltVariableType.Application)<br>
 
  +
switch (variable.type)
{<br>
 
  +
{
switch (variable.type)<br>
 
  +
case VariableType.Integer:
{<br>
 
case VariableType.Integer:<br>
+
case VariableType.PopUp:
  +
Bolt.Variables.Application.Set (boltVariableName, variable.IntegerValue);
case VariableType.PopUp:<br>
 
  +
break;
Bolt.Variables.Application.Set (boltVariableName, variable.IntegerValue);<br>
 
  +
break;<br>
 
  +
case VariableType.Boolean:
<br>
 
  +
Bolt.Variables.Application.Set (boltVariableName, variable.BooleanValue);
case VariableType.Boolean:<br>
 
  +
break;
Bolt.Variables.Application.Set (boltVariableName, variable.BooleanValue);<br>
 
  +
break;<br>
 
  +
case VariableType.Float:
<br>
 
  +
Bolt.Variables.Application.Set (boltVariableName, variable.FloatValue);
case VariableType.Float:<br>
 
  +
break;
Bolt.Variables.Application.Set (boltVariableName, variable.FloatValue);<br>
 
  +
break;<br>
 
  +
case VariableType.String:
<br>
 
  +
Bolt.Variables.Application.Set (boltVariableName, variable.TextValue);
case VariableType.String:<br>
 
  +
break;
Bolt.Variables.Application.Set (boltVariableName, variable.TextValue);<br>
 
  +
break;<br>
 
  +
case VariableType.Vector3:
<br>
 
  +
Bolt.Variables.Application.Set (boltVariableName, variable.Vector3Value);
case VariableType.Vector3:<br>
 
  +
break;
Bolt.Variables.Application.Set (boltVariableName, variable.Vector3Value);<br>
 
  +
break;<br>
 
}<br>
+
default:
}<br>
+
break;
  +
}
else if (boltVariableType == BoltVariableType.Saved)<br>
 
{<br>
+
}
  +
else if (boltVariableType == BoltVariableType.Saved)
switch (variable.type)<br>
 
{<br>
+
{
  +
switch (variable.type)
case VariableType.Integer:<br>
 
  +
{
case VariableType.PopUp:<br>
 
  +
case VariableType.Integer:
variable.IntegerValue = (int) Bolt.Variables.Saved.Get (boltVariableName);<br>
 
  +
case VariableType.PopUp:
break;<br>
 
  +
Bolt.Variables.Saved.Set (boltVariableName, variable.IntegerValue);
<br>
 
  +
break;
case VariableType.Boolean:<br>
 
  +
variable.BooleanValue = (bool) Bolt.Variables.Saved.Get (boltVariableName);<br>
 
  +
case VariableType.Boolean:
break;<br>
 
  +
Bolt.Variables.Saved.Set (boltVariableName, variable.BooleanValue);
 
  +
break;
<br>
 
  +
case VariableType.Float:<br>
 
  +
case VariableType.Float:
variable.FloatValue = (float) Bolt.Variables.Saved.Get (boltVariableName);<br>
 
  +
Bolt.Variables.Saved.Set (boltVariableName, variable.FloatValue);
break;<br>
 
  +
break;
<br>
 
  +
case VariableType.String:<br>
 
  +
case VariableType.String:
variable.TextValue = (string) Bolt.Variables.Saved.Get (boltVariableName);<br>
 
  +
Bolt.Variables.Saved.Set (boltVariableName, variable.TextValue);
break;<br>
 
  +
break;
<br>
 
  +
case VariableType.Vector3:<br>
 
  +
case VariableType.Vector3:
variable.Vector3Value = (Vector3) Bolt.Variables.Saved.Get (boltVariableName);<br>
 
  +
Bolt.Variables.Saved.Set (boltVariableName, variable.Vector3Value);
break;<br>
 
}<br>
+
break;
  +
}<br>
 
  +
default:
}<br>
 
  +
break;
}<br>
 
  +
}
<br>
 
}<br>
+
}
  +
}
<br>
 
}
+
}
  +
  +
}
  +
  +
}
  +
</syntaxhighlight>
 
[[Category:Integrations]]
 
[[Category:Integrations]]

Latest revision as of 08:02, 3 July 2021

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)
					{
						case VariableType.Integer:
						case VariableType.PopUp:
							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)
					{
						case VariableType.Integer:
						case VariableType.PopUp:
							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)
					{
						case VariableType.Integer:
						case VariableType.PopUp:
							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)
					{
						case VariableType.Integer:
						case VariableType.PopUp:
							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;
					}
				}
			}
		}

	}

}