Migration from older to latest SDK

GameArter SDK is being developed to be backward compatible. For switching to latest SDK version, there is usually no or very small work you need to do.

This section inform about things you need to do from migration of certain SDK version to the latest GameArter SDK for Unity version. In first step, select what SDK version you currently have in the game and then go step by step over all the next version to the latest version. You can check SDK version you have in the project in the header of Garter.cs script or by running he game. Then the version is printed to console ain the moment of SDK initialization.

If anything unclear regarding any step, let us know on GameArter Slack and we will improve the guide.

Migration from SDK ver 1.21 and below to ver 1.30

Migration from all SDK version below 1.21 to version 1.21 is especially about reengineering of processes related to separated GarterCallbacks.cs class. In version 1.21, this class was replaced by adding delegates method for which there ic currently need to listen.

Open your GarterCallbacks.cs class (related to the SDK mode you use)

This class was designed as a bridge forwarding calls from the SDK to you own functions. Since SDK 1.21, these functions are not called from the SDK anymore. Instead of it, there is need to install following listeners:

copy
	

	public class DataManagerExample : MonoBehaviour { 

		void Awake(){
			// All listeners for external events occured in the game.
			// Here you can set what event will initialize what function.
			Garter.I.AddExternalCbListener< GarterWWW >(Garter.ExternalListener.SdkInitialized, DataInitialized);
			Garter.I.AddExternalCbListener< string >(Garter.ExternalListener.DataSyncRequired, PostData);
			Garter.I.AddExternalCbListener< decimal >(Garter.ExternalListener.CurrencyUpdate, CurrencyUpdate);
			Garter.I.AddExternalCbListener< string >(Garter.ExternalListener.EventExternalUpdate, EventUpdateViaShop);
			Garter.I.AddExternalCbListener< string >(Garter.ExternalListener.ExternalShopButtonPressed, ShopButtonPressed);
			Garter.I.AddExternalCbListener< string >(Garter.ExternalListener.ExternalSettingsButtonPressed, SettingsButtonPressed);
			Garter.I.AddExternalCbListener< string[] >(Garter.ExternalListener.ReceivedBadges, BadgeReceived);
			Garter.I.AddExternalCbListener< string >(Garter.ExternalListener.PossibleGameExit, PossibleGameExit);
			Garter.I.AddExternalCbListener< string >(Garter.ExternalListener.RewarededAdState, RewardedAdCallback);
		}
	}
	
	

In short, by these listeners you define what information should go to which functions. The simliest way to migrate is let your GarterCallbacks.cs script still available in the project, only extend the class about : MonoBehaviour System and to the top of the class add the awake function displayed above with rightly connected event → function schema.

Migration from SDK ver 1.30 to ver 2.0

SDK ver 2.0 brings new management of storgade data mechanism. Till version 2.0, all data were returned with SDK initialization, to the function associated with "Garter.ExternalListener.SdkInitialized" delegate. This was changed. Beside this, there is also a change in a function format for data echange with GameArter server. Following guide will help you adjust your current scripts to be compatible with SDK ver 2.0.

  • 1

    Change attribute data type of "Garter.ExternalListener.SdkInitialized" delegate.

    Solution: Change data type "GarterWWW www" of function connected with Garter.ExternalListener.SdkInitialized listener from GarterWWW www to string sdkError.

    copy
    	
    
    	public class DataManagerExample : MonoBehaviour { 
    
    		void Awake(){
    			// Old listener format
    			Garter.I.AddExternalCbListener< GarterWWW >(Garter.ExternalListener.SdkInitialized, DataInitialized); // → DataInitialized
    			// New listener format
    			Garter.I.AddExternalCbListener< string >(Garter.ExternalListener.SdkInitialized, DataInitialized); // → DataInitialized
    		}
    		// Before
    		void DataInitialized(GarterWWW){}
    		// Now
    		void DataInitialized(string sdkError){}
    	}
    	
    	
  • 2

    Posting data (saved data) compatibility

    Due to change of data attribute from GarterWWW www to DataInitialized(string sdkError), you will receive an error. You can mention, that sdkError == www.error and you miss data (www.text) currently. For getting www.text, make a get request about data with key "default".
    copy
    	
    public class DataManagerExample : MonoBehaviour { 
    
    		void GetData(){
    			string previousDataInWwwText = Garter.I.GetData< string >("default");
    		}
    	}
    	
    	

    Key default is very important for you. By using this key, you can work same with data as before.

    In a case of posting data, update only your old post fromat Garter.I.PostData(dataInJsonStringFormat) to Garter.I.PostData< string >(dataInJsonStringFormat). New callback format was changed from GarterWWW www to (error, response)

    copy
    	
    
    	public class DataManagerExample : MonoBehaviour { 
    
    		void PostData(){
    			Garter.I.PostData< string >("default", previousDataInWwwText, (error,response) => PostDataCallback(error,response));
    		}
    
    		void PostDataCallback(string error, string response){
    			if (!string.IsNullOrEmpty(error)) {  
    				Debug.LogWarning (www.error);
    			} else { 
    				Debug.Log (response); // → ok
    			}
    		}
    	}
    	
    	
  • 3

    Remove listener for "Garter.ExternalListener.DataSyncRequired" event.

    Forced all data synchronization is not necessary anymore, thus Garter.ExternalListener.DataSyncRequired listener was removed. However, for the best user experience, there is still recommended to Post data on escaping the GameArter exchange. Only instead of on Garter.ExternalListener.DataSyncRequired, post the data on Garter.ExternalListener.EventExternalUpdate and Garter.ExternalListener.CurrencyUpdate, if you think a user could escape the game after a purchase without saving data managed by you.

Migration from SDK ver 2.0 to ver 2.4

SDK ver 2.4 brings switch from Unity's WWW object (obsolete in Unity 2018) to Unity's new UnityWebRequest.

  • 1

    RewardedAdState listener was removed

    RewardedAdState in listeners was replaced by new way of getting rewarded ad state in a form of callback. To fix the issue, simply remove these listeners from your project.

    Since SDK ver 2.4, you can get state of rewarded ad via callback function:

    copy
    	
    
    	public class DataManagerExample : MonoBehaviour { 
    		Garter.I.RewardedAd ((state) => {
    			if(state == "loaded"){
    				// MUTE GAME
    			} else if(state == "completed"){
    				// UNMUTE GAME
    			} else {
    				// ...
    			}
    		});
    	}
    	
    	
  • 2

    Removed key texture in GarterWWW class. For downloading textures, use DownloadDataFile() function instead.

    Getting .texture key from GarterWWW is not possible anymore since SDK ver 2.4. Getting textures is further possible via DownloadDataFile function.

    copy
    
    public class DataManagerExample : MonoBehaviour { 
    	DownloadDataFile(url, FileType.Texture, result => SetTextureFunction(result));
    }