/// <summary> /// Select the image and process the request /// </summary> /// <param name="campaignName">name of the campaign</param> private void PickImage(string campaignName) { NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { Debug.Log("Image path: " + path); if (path != null) { // Create Texture from selected image Texture2D tex = NativeGallery.LoadImageAtPath(path, 4096); if (tex == null) { Debug.Log("Couldn't load texture from " + path); return; } tex.Apply(); var v = new Texture2D(2, 2); v.LoadImage(tex.EncodeToPNG(), false); v.Apply(); ///map.sprite = Sprite.Create(v, new Rect(0.0f, 0.0f, v.width, v.height), new Vector2(0.5f, 0.5f), 100.0f); SharedImageData sid = new SharedImageData(); sid.bytes = v.EncodeToPNG(); sid.info = null; string finalPath = SerializationManager.CreatePath(campaignName + "/NewMap.map"); SerializationManager.SaveObject(finalPath, sid); } }, "Select a PNG image", "image/png", 4096); Debug.Log("Permission result: " + permission); }
/// <summary> /// Load a page, called by a campaign file /// </summary> /// <param name="file">File to load a page for</param> public void SwitchPage(CampaignFile file) { DeletePage(); Debug.Log("Switching to page: " + file.GetFileName()); string fullPath = file.GetCampaign().GetCampaignName() + "/" + file.GetFileName() + "." + file.GetExtension(); fullPath = SerializationManager.CreatePath(fullPath); //Get the file extension to determine what file type to display switch (file.GetExtension()) { case "sbd": { pinManager.SetActive(false); currrentPage = Instantiate(prefabs[0], viewport.transform); StatBlockUIData uiData = (StatBlockUIData)SerializationManager.LoadObject(fullPath); currrentPage.GetComponent <StatBlockForm>().BuildPage(uiData); currrentPage.GetComponent <StatBlockForm>().fullPath = fullPath; currrentPage.GetComponent <StatBlockForm>().campaign = file.GetCampaign().GetCampaignName(); break; } case "map": { pinManager.SetActive(true); currrentPage = Instantiate(prefabs[1], viewport.transform); SharedImageData uiData = (SharedImageData)SerializationManager.LoadObject(fullPath); currrentPage.GetComponent <MapForm>().campaign = file.GetCampaign().GetCampaignName(); currrentPage.GetComponent <MapForm>().BuildPage(uiData); break; } default: { Debug.Log(file.GetExtension() + " is not a proper extension!"); return; } } scrollRect.enabled = true; scrollRect.content = currrentPage.GetComponent <RectTransform>(); SetActiveCampaignView(false); }
/// <summary> /// Build a page based on the set of give data /// </summary> /// <param name="data"></param> public override void BuildPage(PageData data) { SharedImageData uiData = (SharedImageData)data; Texture2D v = new Texture2D(2, 2); v.LoadImage(uiData.bytes); v.Apply(); GetComponent <Image>().sprite = Sprite.Create(v, new Rect(0.0f, 0.0f, v.width, v.height), new Vector2(0.5f, 0.5f), 100.0f); GetComponent <RectTransform>().sizeDelta = new Vector2(v.width, v.height); //Add pins to the map if (uiData.info == null) { return; } foreach (PinData p in uiData.info.pins) { GameObject tmp = Instantiate(pin, transform); tmp.transform.position = p.position; tmp.GetComponent <Image>().color = p.color; } }