Esempio n. 1
0
 void OnGetAssetListDone(bool error, Spaces.Core.RestAPI.RestGetAssetListResponseData data)
 {
     if (error)
     {
         Debug.LogError("[Get Asset List] Completed with errors");
     }
     else
     {
         Debug.Log("[Get Asset List] Completed successfully with " + data.assets.Count + " items.");
     }
 }
 public void OnAssetListResponse(bool error, Spaces.Core.RestAPI.RestGetAssetListResponseData resposne)
 {
     if (error)
     {
         Debug.LogError("There was an error getting the Asset List.");
     }
     else
     {
         Debug.Log("Finished getting the Asset List.");
         OnAssetListPopulated.Invoke();
     }
 }
Esempio n. 3
0
        public void GetAssetListReply(bool error, string reply)
        {
            if (error)
            {
                doneCallback(true, null);
            }
            else
            {
                try
                {
                    TinyJSON.Variant test;
                    var GetListReponse = TinyJSON.Decoder.Decode(reply) as TinyJSON.ProxyObject;

                    var allAssets = GetListReponse.TryGetValue("AllAssets", out test) ? test as TinyJSON.ProxyObject : new TinyJSON.ProxyObject();
                    var array     = allAssets.TryGetValue("all", out test) ? test as TinyJSON.ProxyArray : new TinyJSON.ProxyArray();

                    List <RestGetAssetListResponseData.AssetInfo> assetListInfo = new List <RestGetAssetListResponseData.AssetInfo>();

                    for (int i = 0; i < array.Count; i++)
                    {
                        var assetID   = ((TinyJSON.ProxyObject)array[i]).TryGetValue("id", out test) ? test : string.Empty;
                        var assetName = ((TinyJSON.ProxyObject)array[i]).TryGetValue("name", out test) ? test : string.Empty;
                        var assetType = ((TinyJSON.ProxyObject)array[i]).TryGetValue("asset_type", out test) ? test : string.Empty;
                        //var assetPreview = ((TinyJSON.ProxyObject)array[i]).TryGetValue("url", out test) ? test : string.Empty;

                        assetListInfo.Add(new RestGetAssetListResponseData.AssetInfo()
                        {
                            id = assetID, name = assetName, type = assetType
                        });
                    }

                    assetListInfo.Sort((a1, a2) => a1.name.CompareTo(a2.name) == 0 ? a1.id.CompareTo(a2.id) : a1.name.CompareTo(a2.name));

                    assetListInfo.ForEach(info => assets.Add(new Asset(info.id, info.name, info.type)));

                    var assetsList = new RestGetAssetListResponseData()
                    {
                        assets = assets
                    };

                    doneCallback(false, assetsList);
                }
                catch (System.Exception ex)
                {
                    Debug.Log("Tried but " + ex);
                }
            }
        }