public void ObjectParse(object parse) { CatalogueItem_Font item = parse as CatalogueItem_Font; 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_Font fontParse, CatalogueItemThumnail_Font thumbnail) { this.itemFont = fontParse; if (itemFont.itemID != 0) { //Asset Exists itemThumbnail = thumbnail; assetFriendlyName.text = itemFont.friendlyName; favouritesToggle.isOn = itemFont.favourite; tagsInputField.text = string.Join("#", itemFont.tags); if (!string.IsNullOrEmpty(itemFont.fontPath)) { StartCoroutine(SetLoadFont(Application.persistentDataPath + itemFont.fontPath)); loadFontButtonText.GetComponentInChildren <Text>().text = ""; loadFontButton.enabled = false; } } }
public async void SaveAssetAsync() { if (string.IsNullOrEmpty(assetFriendlyName.text)) { MessageBox.Show("Error", "Asset Name Is Missing", () => { }); return; } if (itemFont.itemID == 0) { if (string.IsNullOrEmpty(tempFontFilePath)) { MessageBox.Show("Error", "No Font File Selected", () => { }); return; } } this.GetComponent <Button>().interactable = false; LoadingPanelUI loadingPanelUI = GetComponentInChildren <LoadingPanelUI>(true); loadingPanelUI.gameObject.SetActive(true); loadingPanelUI.ChangeText("Please Wait", "Assets Uploading"); const string catalogueItemFileName = "CatalogueItem.asscat"; const string itemThumnailPrefabName = "AssetThumnail_Font"; if (itemFont.itemID == 0) //New Asset { catalogueManager._CreatedAssetCount++; CatalogueItemDetail itemDetail = new CatalogueItemDetail { ItemType = CatalogueItemDetail.ItemTypes.Font, ItemID = catalogueManager._CreatedAssetCount, CatalogueItemDirectory = "/Assets/Fonts/" + catalogueManager._CreatedAssetCount.ToString("D5") + "/", DateModified = DateTime.Now.ToString(), FriendlyName = assetFriendlyName.text, ItemTypeCategory = 0, }; string localAssetPath = "/" + catalogueManager._DatabaseUID + itemDetail.CatalogueItemDirectory + "/"; string localFontPath = localAssetPath + "/" + Path.GetFileName(tempFontFilePath); cmd_File.DeleteFolder(Application.persistentDataPath + localAssetPath, false); Directory.CreateDirectory(Application.persistentDataPath + localAssetPath); File.Copy(tempFontFilePath, Application.persistentDataPath + localFontPath, true); itemFont = new CatalogueItem_Font { friendlyName = assetFriendlyName.text, itemID = catalogueManager._CreatedAssetCount, modifiedDate = DateTime.Now.ToString(), fontPath = localFontPath, thumnailData = RenderFontTextToBitmapArray(256, 256, new System.Drawing.Font(fontCollection.Families[0], 28), renderTextStringShort, System.Drawing.Brushes.GhostWhite), tags = tagsInputField.text.Split('#'), itemTypeCategory = 0, favourite = favouritesToggle.isOn, }; cmd_File.SerializeObject(Application.persistentDataPath + localAssetPath, catalogueItemFileName, itemFont); catalogueManager._CatalogueItemDetails.Add(itemDetail); catalogueManager.ResyncCatalogueDatabaseAsync(); using (DropboxClient dbx = new DropboxClient(AvoEx.AesEncryptor.DecryptString(PlayerPrefs.GetString("Token")))) { await cmd_Dropbox.UploadFileAsync(dbx, tempFontFilePath, itemDetail.CatalogueItemDirectory, Path.GetFileName(tempFontFilePath)); await cmd_Dropbox.UploadObjAsync(dbx, itemFont, itemDetail.CatalogueItemDirectory, catalogueItemFileName); Debug.Log("LOG:" + DateTime.Now.ToString() + " - " + itemFont.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", itemFont); } else //Update Asset { foreach (CatalogueItemDetail itemDetail in catalogueManager._CatalogueItemDetails) { if (itemDetail.ItemID == itemFont.itemID) { itemDetail.DateModified = DateTime.Now.ToString(); itemFont.modifiedDate = DateTime.Now.ToString(); itemDetail.FriendlyName = assetFriendlyName.text; itemFont.friendlyName = assetFriendlyName.text; itemFont.tags = tagsInputField.text.Split('#'); itemFont.favourite = favouritesToggle.isOn; itemFont.itemTypeCategory = 0; itemThumbnail.lable.text = assetFriendlyName.text; itemThumbnail.ObjectParse(itemFont); catalogueManager.ResyncCatalogueDatabaseAsync(); using (DropboxClient dropboxClient = new DropboxClient(AvoEx.AesEncryptor.DecryptString(PlayerPrefs.GetString("Token")))) { await cmd_Dropbox.UploadObjAsync(dropboxClient, itemFont, itemDetail.CatalogueItemDirectory, catalogueItemFileName); Debug.Log("LOG:" + DateTime.Now.ToString() + " - " + itemFont.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, itemFont); return; } } } loadingPanelUI.gameObject.SetActive(false); this.GetComponent <Button>().interactable = true; }