Creating Shared Variables

New Shared Variables can be created if you don’t want to use any of the built in types. To create a Shared Variable, subclass the SharedVariable type and implement the following methods. The keyword OBJECT_TYPE should be replaced with the type of Shared Variable that you want to create.

[System.Serializable]
public class SharedOBJECT_TYPE : SharedVariable<OBJECT_TYPE>
{
   public static implicit operator SharedOBJECT_TYPE(OBJECT_TYPE value) { return new SharedOBJECT_TYPE { Value = value }; }
}

It is important that the “Value” property exists. The variable inspector will show an error if the new Shared Variable is created incorrectly. Shared Variables can contain any type of object that your task can contain, including primitives, arrays, lists, custom objects, etc.

As an example, the following script will allow a custom class to be shared:

    [System.Serializable]
    public class CustomClass
    {
        public int myInt;
        public Object myObject;
    }

    [System.Serializable]
    public class SharedCustomClass : SharedVariable<CustomClass>
    {
        public static implicit operator SharedCustomClass(CustomClass value) { return new SharedCustomClass { Value = value }; }
    }