Unity Book-Page Curl Pro(其一用法)
1.点击最右边红框,前两个红框里面的内容会自动增加,下面有给新增加的Page自动添加图片功能
2.右下角的地方觉得按钮是否执行
using BOOKPRO; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI; public class AddPic : MonoBehaviour { // Start is called before the first frame update private BookPro bookPro; private int paperLeght; private Image frontImage; private Image backIamge; // private Paper paper; void Start() { bookPro = transform.GetComponent<BookPro>(); paperLeght = bookPro.papers.Length; StartCoroutine(GetTexture()); } IEnumerator GetTexture() { while (paperLeght > 0) { string path; UnityWebRequest uwr; DownloadHandlerTexture downloadTexture; backIamge = bookPro.papers[paperLeght - 1].Back.GetComponent<Image>(); frontImage = bookPro.papers[paperLeght - 1].Front.GetComponent<Image>(); path = Application.dataPath + "/堂阜脱囚/" + "0" + ((paperLeght-1)*2) + ".png"; print(path); uwr = UnityWebRequest.Get(path); downloadTexture = new DownloadHandlerTexture(true); uwr.downloadHandler = downloadTexture; yield return uwr.SendWebRequest(); if (uwr.isNetworkError || uwr.isHttpError) { print(uwr.error); } else { Texture2D t = downloadTexture.texture; frontImage.sprite = Sprite.Create(t, new Rect(0, 0, t.width, t.height), Vector2.one); } path = Application.dataPath + "/堂阜脱囚/" + "0" + (paperLeght * 2-1) + ".png"; backIamge = bookPro.papers[paperLeght - 1].Back.GetComponent<Image>(); frontImage = bookPro.papers[paperLeght - 1].Front.GetComponent<Image>(); uwr = UnityWebRequest.Get(path); downloadTexture = new DownloadHandlerTexture(true); uwr.downloadHandler = downloadTexture; yield return uwr.SendWebRequest(); if (uwr.isNetworkError || uwr.isHttpError) { print(uwr.error); } else { Texture2D t = downloadTexture.texture; backIamge.sprite = Sprite.Create(t, new Rect(0, 0, t.width, t.height), Vector2.one); } paperLeght--; } } }
posted on 2022-04-02 15:21 zqiang0803 阅读(624) 评论(0) 编辑 收藏 举报