User identity is did by SDK on background. Protection from data manipulaton is solved by SDK.

Asset Management using Class GarterAssetsManagement.

1. Initialization of GameArter Asset management:

copy


public class SomeClass : MonoBehaviour { // Example script for working with data
	GarterAssetsManagement AM = new GarterAssetsManagement();
}

Available requests:

1. Posting new asset

Allow to post new asset on server.

Using GarterAssetsManagement.PostOpt type for setting post options

    GarterAssetsManagement.PostOpt keys:
  • .assetId | id of asset. If it is new assset created from 0, set to 0. If the asset was created on basis of previous asset, set assetId of original asset.
  • .name | name of the asset
  • .img | image of the assets
  • .metaData | additional specification according to which there is possible to filtrate. It can be e.g. game mode for which the asset is available.
  • .data | data file of the asset
  • .accessability | accessability of the asset
    • .PUBLIC | everyone can see the asset and use it (e.g. use map for creating public room).
    • .PRIVATE | onlz creator see the asset and can use it (e.g. use map for creating public room).
  • .cloneable | Permission to clone the assset to own inventory
    • .NO | no permission to clone the asset
    • .YES | anybody can clone the asset to own inventory
Example:
copy


public class SomeClass : MonoBehaviour { // Example script for working with data
	private void CreateAndPostNewAsset(){
		GarterAssetsManagement.PostOpt po = new GarterAssetsManagement.PostOpt ();
		po.assetId = 0; // is extension of asset (0= totally new asset) 
		po.name = "My map"; // set map name
		po.img = null; // set map img (no image)
		po.metaData = "zombie"; // for option of additional filtration
		po.data = "asset in string format"; // data
		po.accessability = GarterAssetsManagement.Accessability.PUBLIC;
		AM.Post (po, CallbackFunctionForAssets); // Post asset on server, return callback to CallbackFunctionForAssets
	}
}

Callback format:
copy


public class SomeClass : MonoBehaviour {
	private void CallbackFunctionForAssets(){
		if (string.IsNullOrEmpty (www.error)) { // ok
			GarterAssetsManagement.AssetsCbFormat responseData = Garter.I.FromJson< GarterAssetsManagement.AssetsCbFormat > (www.text);
			uint assetId = responseData.assetId; // assetId of inserted asset
		} else {
			Debug.LogError (www.error);
			// data manipulation or server error. Asset was not saved.
		}
	}
}

2. Getting list of available assets

Allow get list of assets on basis of selected preferences.

Using GarterAssetsManagement.GetOpt type for setting get options

    GarterAssetsManagement.GetOpt keys:
  • .GetRequest | sets type of required response. set .LIST.
  • .accessability | accessability of requested assets
    • .ALL | Get all assets a user has access to.
    • .PUBLIC | Get only assets with state public.
    • .PRIVATE | Get only assets with state private.
  • .metaData | additional specification according to which there is possible to filtrate. If is not empty, only assets with set metaData will be returned.
  • .orderBy | order selection of results
    • .RATING
    • .RATING_DESC
    • .CREATED
    • .CREATED_DESC
    • .DOWNLOADS
    • .DOWNLOADS_DESC
  • .limit | maximum number of results to return
Example:
copy


public class SomeClass : MonoBehaviour {
	private void GetListOfAssets(){
		GarterAssetsManagement.GetOpt po = new GarterAssetsManagement.GetOpt ();
		po.dataType = GarterAssetsManagement.GetReq.LIST; // list of maps
		po.accessability = GarterAssetsManagement.Accessability.ALL; // all assets a user can use
		po.metaData = "zombie"; // load only assets with metadata zombie
		po.orderBy = GarterAssetsManagement.OrderBy.RATING_DESC; // list of best
		po.limit = 30; // load list with maximum number of 30 results
		AM.Get (po, CallbackFunctionForAssets);
	}
}

Callback format:
copy


public class SomeClass : MonoBehaviour { // Example script for working with data
	private void CallbackFunctionForAssets(){
		if (string.IsNullOrEmpty (www.error)) { // ok
			GarterAssetsManagement.AssetsCbFormat responseData = Garter.I.FromJson< GarterAssetsManagement.AssetsCbFormat > (www.text);
			List< GarterAssetsManagement.AssetListMember > listOfAssets = responseData.list;
			if (listOfAssets != null) {
				Debug.Log ("--- List of assets ---");
				for (int i = 0; i < listOfAssets.Count; i++) {
					Debug.Log ("assetId: " + listOfAssets [i].assetId);
					Debug.Log ("asset name: " + listOfAssets [i].name);
					Debug.Log ("asset votes: " + listOfAssets [i].votes);
					Debug.Log ("asset rating: " + listOfAssets [i].rating);
					Debug.Log ("asset downloads: " + listOfAssets [i].downloads);
					Debug.Log ("asset cloneable: " + listOfAssets [i].cloneable);
					Debug.Log ("asset created: " + listOfAssets [i].created);
				}
			}
		} else {
			Debug.LogError (www.error);
			// data manipulation or server error. Asset was not saved.
		}
	}
}

3. Getting certain asset

Allow get certain asset on basis of its assetId.

Using GarterAssetsManagement.GetOpt type for setting get options

    GarterAssetsManagement.GetOpt keys:
  • .GetRequest | sets type of required response. set .FILE.
  • .assetId | set certain assetId
Example:
copy


public class SomeClass : MonoBehaviour {
	private void GeAssetToLoad(){
		GarterAssetsManagement.GetOpt po = new GarterAssetsManagement.GetOpt ();
		po.dataType = GarterAssetsManagement.GetReq.FILE; // get 1 asset
		po.assetId = 1; // dwnload data of assetId 1
		AM.Get (po, CallbackFunctionForAssets);
	}
}

Callback format:
copy


public class SomeClass : MonoBehaviour { // Example script for working with data
	private void CallbackFunctionForAssets(){
		if (string.IsNullOrEmpty (www.error)) { // ok
			GarterAssetsManagement.AssetsCbFormat responseData = Garter.I.FromJson< GarterAssetsManagement.AssetsCbFormat > (www.text);
			uint assetId = responseData.assetId;
			GarterAssetsManagement.Cloneable clonePermission = responseData.cloneable;
			string assetData = responseData.data;
		} else {
			Debug.LogError (www.error);
			// Server error or user has no permission to get the asset.
		}
	}
}

4. Updating certain asset

Allow get update attribute of certain asset.

Using GarterAssetsManagement.UpdateOpt type for setting update options

    GarterAssetsManagement.UpdateOpt keys:
  • .assetId | set id of asset which has to be updated.
  • .UpdateType | set what attribue has be updated
    • .FILE
    • .NAME
    • .ACCESSABILITY
    • .CLONEABILITY
  • .data | new name / accessability state / cloneability state | file. Use .ToString() for accesability and cloneability
  • .img | new asset image. (Available for .FILE updateType only.
Example:
copy


public class SomeClass : MonoBehaviour {
	private void UpdateName(){
		GarterAssetsManagement.UpdateOpt po = new GarterAssetsManagement.UpdateOpt ();
		po.assetId = 1;
		po.updateType = GarterAssetsManagement.UpdateType.NAME; // what is need to update.
		po.data = "New Asset name";
		AM.Update (po, CallbackFunctionForAssets);
	}

	private void UpdateFile(){
		GarterAssetsManagement.UpdateOpt po = new GarterAssetsManagement.UpdateOpt ();
		po.assetId = 1;
		po.updateType = GarterAssetsManagement.UpdateType.FILE; // what is need to update.
		po.data = "New file";
		AM.Update (po, CallbackFunctionForAssets);
	}

	private void UpdateAccessability(){
		GarterAssetsManagement.UpdateOpt po = new GarterAssetsManagement.UpdateOpt ();
		po.assetId = 1;
		po.updateType = GarterAssetsManagement.UpdateType.ACCESSIBILITY; // what is need to update.
		po.data = GarterAssetsManagement.Accessability.PUBLIC.ToString();;
		AM.Update (po, CallbackFunctionForAssets);
	}

	private void UpdateCloneability(){
		GarterAssetsManagement.UpdateOpt po = new GarterAssetsManagement.UpdateOpt ();
		po.assetId = 1;
		po.updateType = GarterAssetsManagement.UpdateType.CLONEABILITY; // what is need to update.
		po.data = GarterAssetsManagement.CLONEABILITY.YES.ToString();;
		AM.Update (po, CallbackFunctionForAssets);
	}
}

Callback format:
copy


public class SomeClass : MonoBehaviour { // Example script for working with data
	private void CallbackFunctionForAssets(){
		if (string.IsNullOrEmpty (www.error)) { // ok
			GarterAssetsManagement.AssetsCbFormat responseData = Garter.I.FromJson< GarterAssetsManagement.AssetsCbFormat > (www.text);
			uint assetId = responseData.assetId; // assetId of updated asset
		} else {
			Debug.LogError (www.error);
			// data manipulation or server error. Asset was not updated
		}
	}
}

5. Duplicate asset

Duplicates asset of certain id to the user's inventory

Using GarterAssetsManagement.DuplicateOpt type for setting update options

    GarterAssetsManagement.DuplicateOpt keys:
  • .assetId | set assetId of duplicated asset
Example:
copy


public class SomeClass : MonoBehaviour {
	private void GeAssetToLoad(){
		GarterAssetsManagement.DuplicateOpt po = new GarterAssetsManagement.DuplicateOpt ();
		po.assetId = 1;
		AM.Duplicate (po, CallbackFunctionForAssets);
	}
}

Callback format:
copy


public class SomeClass : MonoBehaviour { // Example script for working with data
	private void CallbackFunctionForAssets(){
		if (string.IsNullOrEmpty (www.error)) { // ok
			GarterAssetsManagement.AssetsCbFormat responseData = Garter.I.FromJson< GarterAssetsManagement.AssetsCbFormat > (www.text);
			uint assetId = responseData.assetId; // assetId of updated asset
		} else {
			Debug.LogError (www.error);
			// data manipulation or server error. Asset was not updated
		}
	}
}

6. Delete asset

Removes asset of certain id from the user's inventory

Using GarterAssetsManagement.DeleteOpt type for setting update options

    GarterAssetsManagement.DeleteOpt keys:
  • .assetId | set assetId to be deleted from user's inventory
Example:
copy


public class SomeClass : MonoBehaviour {
	private void GeAssetToLoad(){
		GarterAssetsManagement.DeleteOpt po = new GarterAssetsManagement.DeleteOpt ();
		po.assetId = 1;
		AM.Delete (po, CallbackFunctionForAssets);
	}
}

Callback format:
copy


public class SomeClass : MonoBehaviour { // Example script for working with data
	private void CallbackFunctionForAssets(){
		if (string.IsNullOrEmpty (www.error)) { // ok
			GarterAssetsManagement.AssetsCbFormat responseData = Garter.I.FromJson< GarterAssetsManagement.AssetsCbFormat > (www.text);
			uint assetId = responseData.assetId; // assetId of deleted asset
		} else {
			Debug.LogError (www.error);
			// data manipulation or server error. Asset was not updated
		}
	}
}

7. Rate asset

Rate asset of certain id

Using GarterAssetsManagement.RateOpt type for setting update options

    GarterAssetsManagement.DeleteOpt keys:
  • .assetId | set assetId to be deleted from user's inventory
  • .value | rating value 0 - 100%
Example:
copy


public class SomeClass : MonoBehaviour {
	private void GeAssetToLoad(){
		GarterAssetsManagement.RateOpt po = new GarterAssetsManagement.RateOpt ();
		po.assetId = 1;
		po.value = 100; // 0- 100% | li like/dislikes -  100% / 0%
		AM.Rate (po, CallbackFunctionForAssets);
	}
}

Callback format:
copy


public class SomeClass : MonoBehaviour { // Example script for working with data
	private void CallbackFunctionForAssets(){
		if (string.IsNullOrEmpty (www.error)) { // ok
			GarterAssetsManagement.AssetsCbFormat responseData = Garter.I.FromJson< GarterAssetsManagement.AssetsCbFormat > (www.text);
			uint assetId = responseData.assetId; // assetId of rated asset
		} else {
			Debug.LogError (www.error);
			// data manipulation or server error. Asset was not rated
		}
	}
}