Example #1
0
    public void ObjectParse(object parse)
    {
        CatalogueItem_Audio item = parse as CatalogueItem_Audio;

        this.tile  = item;
        lable.text = item.friendlyName;
        assetID    = item.itemID;
        favourite  = item.favourite;
        if (item.thumnailData != null)
        {
            Texture2D tex = new Texture2D(2, 2);
            tex.LoadImage(item.thumnailData);
            Sprite mySprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f);
            thumbnail.sprite = mySprite;
        }
    }
 public void ObjectParse(CatalogueItem_Audio audioParse, CatalogueItemThumnail_Audio thumbnail)
 {
     this.itemAudio = audioParse;
     if (itemAudio.itemID != 0)
     {
         //Asset Exists
         itemThumbnail          = thumbnail;
         assetFriendlyName.text = itemAudio.friendlyName;
         if (!string.IsNullOrEmpty(itemAudio.audioPath))
         {
             LoadAudioFile(Application.persistentDataPath + itemAudio.audioPath);
         }
         tagsInputField.text    = string.Join("#", itemAudio.tags);
         categoryDropDown.value = itemAudio.itemTypeCategory;
         favouritesToggle.isOn  = itemAudio.favourite;
         loadAssetButton.GetComponentInChildren <Text>().text = "";
         loadAssetButton.enabled = false;
     }
 }
    public async void SaveAssetAsyn()
    {
        if (string.IsNullOrEmpty(assetFriendlyName.text))
        {
            MessageBox.Show("Error", "Asset Name Is Missing", () => { });
            return;
        }
        if (itemAudio.itemID == 0)
        {
            if (string.IsNullOrEmpty(tempAudioFilePath))
            {
                MessageBox.Show("Error", "No Audio File Selected", () => { });
                return;
            }
        }

        this.GetComponent <Button>().interactable = false;
        LoadingPanelUI loadingPanelUI = GetComponentInChildren <LoadingPanelUI>(true);

        loadingPanelUI.gameObject.SetActive(true);
        loadingPanelUI.ChangeText("Please Wait", "Uploading");

        const string catalogueItemFileName  = "CatalogueItem.asscat";
        const string itemThumnailPrefabName = "AssetThumnail_Audio";

        if (itemAudio.itemID == 0) //New Asset
        {
            catalogueManager._CreatedAssetCount++;

            CatalogueItemDetail itemDetail = new CatalogueItemDetail
            {
                ItemType = CatalogueItemDetail.ItemTypes.Audio,
                ItemID   = catalogueManager._CreatedAssetCount,
                CatalogueItemDirectory = "/Assets/Audio/" + catalogueManager._CreatedAssetCount.ToString("D5") + "/",
                DateModified           = DateTime.Now.ToString(),
                FriendlyName           = assetFriendlyName.text,
                ItemTypeCategory       = categoryDropDown.value,
            };

            string localAssetPath = "/" + catalogueManager._DatabaseUID + itemDetail.CatalogueItemDirectory + "/";
            string localAudioPath = localAssetPath + "/" + Path.GetFileName(tempAudioFilePath);
            cmd_File.DeleteFolder(Application.persistentDataPath + localAssetPath, false);
            Directory.CreateDirectory(Application.persistentDataPath + localAssetPath);

            File.Copy(tempAudioFilePath, Application.persistentDataPath + localAudioPath, true);

            itemAudio = new CatalogueItem_Audio
            {
                friendlyName     = assetFriendlyName.text,
                itemID           = catalogueManager._CreatedAssetCount,
                modifiedDate     = DateTime.Now.ToString(),
                audioPath        = localAudioPath,
                thumnailData     = waveformCurrentTexture.sprite.texture.EncodeToPNG(),
                tags             = tagsInputField.text.Split('#'),
                itemTypeCategory = categoryDropDown.value,
                favourite        = favouritesToggle.isOn,
            };
            cmd_File.SerializeObject(Application.persistentDataPath + localAssetPath, catalogueItemFileName, itemAudio);
            catalogueManager._CatalogueItemDetails.Add(itemDetail);
            catalogueManager.ResyncCatalogueDatabaseAsync();

            using (DropboxClient dbx = new DropboxClient(AvoEx.AesEncryptor.DecryptString(PlayerPrefs.GetString("Token"))))
            {
                await cmd_Dropbox.UploadFileAsync(dbx, tempAudioFilePath, itemDetail.CatalogueItemDirectory, Path.GetFileName(tempAudioFilePath));

                await cmd_Dropbox.UploadObjAsync(dbx, itemAudio, itemDetail.CatalogueItemDirectory, catalogueItemFileName);

                Debug.Log("LOG:" + DateTime.Now.ToString() + " - " + itemAudio.friendlyName + " Created");
                MessageBox.Show("Boom Shaka Laka", "Asset Now Added", () =>
                {
                    GetComponent <PopupItemController>().HideDialog(0);
                });
            }

            GameObject go = Instantiate(Resources.Load(itemThumnailPrefabName) as GameObject, GameObject.FindWithTag("ThumbnailGrid").transform);
            go.SendMessage("ObjectParse", itemAudio);
        }
        else //Update Asset
        {
            foreach (CatalogueItemDetail itemDetail in catalogueManager._CatalogueItemDetails)
            {
                if (itemDetail.ItemID == itemAudio.itemID)
                {
                    itemDetail.DateModified    = DateTime.Now.ToString();
                    itemAudio.modifiedDate     = DateTime.Now.ToString();
                    itemDetail.FriendlyName    = assetFriendlyName.text;
                    itemAudio.friendlyName     = assetFriendlyName.text;
                    itemAudio.tags             = tagsInputField.text.Split('#');
                    itemAudio.favourite        = favouritesToggle.isOn;
                    itemAudio.itemTypeCategory = categoryDropDown.value;
                    itemThumbnail.lable.text   = assetFriendlyName.text;
                    itemThumbnail.ObjectParse(itemAudio);
                    catalogueManager.ResyncCatalogueDatabaseAsync();
                    using (DropboxClient dropboxClient = new DropboxClient(AvoEx.AesEncryptor.DecryptString(PlayerPrefs.GetString("Token"))))
                    {
                        await cmd_Dropbox.UploadObjAsync(dropboxClient, itemAudio, itemDetail.CatalogueItemDirectory, catalogueItemFileName);

                        Debug.Log("LOG:" + DateTime.Now.ToString() + " - " + itemAudio.friendlyName + " Updated");
                        MessageBox.Show("Boom Shaka Laka", "Asset Now Updated", () =>
                        {
                            GetComponent <PopupItemController>().HideDialog(0);
                        });
                    }
                    string localPath = Application.persistentDataPath + "/" + catalogueManager._DatabaseUID + itemDetail.CatalogueItemDirectory + "/";
                    cmd_File.SerializeObject(localPath, catalogueItemFileName, itemAudio);
                    return;
                }
            }
        }
        loadingPanelUI.gameObject.SetActive(false);
        this.GetComponent <Button>().interactable = true;
    }