Unity 制作翻书电子书,外部异步加载千张图片(一)

  Unity 制作翻书电子书,外部异步加载千张图片(一)

Hello!这是我的第一篇文章,希望在你阅读这篇文章之后对你能有帮助。
之前我做过两次电子书的程序,用的都是网上随便一搜就能找到的插件,很方便,参数调节都是现成的,图片拖到编辑器中基本就拿来就能用。
But这次我就抓瞎了,因为这次需要加载的图片大概有一万多张,共计十六卷,试想,这么多图片就算压缩到很小,拖到编辑器里,让程序跑起来,内存也就爆了(因为我很天真,所以我试过不行,而且书页不能压缩太小,不然字就看不清楚了)。
所以我就想了第一个方案,干脆把书本内容做成TXT文本,图片太多,内存会爆,人家用文本加载,加载时间也会极短,后期不管是文本内容替换,以及后期程序维护都是十分的方便啊!所以我就开始我的大业(相信我们用过这个unity电子书插件大家都知道,这个书页必须要用Image Or RawImage,所以我们要用文本导入,需要通过计算生成PNG文字图片,还可以自己加背景图进行合成,其实更符合我们灵活方便的功能,其实这两个功能我已经实现。But难点在于我们需要用程序对我们获取的文本进行断章断点,进行书页生成,我已经根据生成的书页首位空格文字内容的字节和计算进行断章,但是后来发现每行字节不同,可能多一个字或者少一个字,且一次性生成几十张还阔以,成百上千张就会有严重的卡顿,自己没有好的方法解决,就放弃了)生成图片如下,左侧是Text,右侧是生成的图片:
在这里插入图片描述
困难总是要解决的,所以有了第二个的方案,方法其实不好,但是解决了目前的问题,所以有时间还是需要把上面的方案好好研究一下。外部一次性加载六七百张图片,我加载的每张图片分辨率是716*1122,*JPG格式,单张160-180KB,效果出来如下,第一卷加载了670张图片,用时如下。
在这里插入图片描述
图片加载到我们书本预制体的列表中
在这里插入图片描述
效果视频如下!添加链接描述

bandicam 2020-05-26 15-28-01-648

下载源工程的连接,附带音效,有需要的欢迎大家来下载啦!
https://download.csdn.net/download/qq_39851527/12501441

  • 5
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 18
    评论
The "Unity3D Book Page Curl" is a unity package that is used to create a book with page flip effect using unity3D native UI tools. Getting Started Create your first book:  Import the unity package  Create a canvas and EventSystem objects if you don't have one (the easiest way to create them is by adding any UI object -like a button- then you can delete it).  Drag a book prefab under the Canvas element  Resize the book on your scene and reposition the anchors as required.  Select the book from hierarchy to show it in inspector.  Assign the canvas to the canvas slot in inspector  Assign the background sprite with the sprite that you want to show on the right or left side when all pages flipped to the other side.  To edit the book pages, expand the Book Pages list in inspector, change the Size to your pages count, then start drag your pages in the Element boxes in order  Set the current page to the page that you want to be shown initially in the right side of the book.  If you want to call any function when any page flipped add it to the OnFlip Event List.  If you want to resize the area that the user can drag the page from it, open the Book node in inspector to show its children, you will find two objects "RightHotSpot" and "LeftHotSpot" resize them and set their anchors as required.  RUN and enjoy the page curl effect! Create Automatic Flipping Book:  After creating your book as mentioned above add an "Auto Flip" component on it.  Choose flipping direction( if you choose left to right make sure that the current page of the book component is equal to your page count "last page index + 1").  Uncheck the interactable check in the book component.  Specify the page flipping time parameters (Page Flip Time, Time Between Pages, Delay before Start flipping, Number of Animation frames for each page flip).  Check "Auto Start Flip" if you want the book to start flipping automatically, or uncheck it and call the StartFlipping() function in your code. Control Flipping Manually: This section will explore how to create a scene like the “Example_2_Controled Flipping” scene  To be able to let the user control page flipping using some buttons, create your book, add an "Auto Flip" component on it and configured them as mentioned above.  Uncheck the “interactable” of the book and "Auto Start Flip" of the “Auto Flip” components.  Add previous and next buttons to your scene (check Example_2_Controled Flipping scene if you have any issues setting them correctly).  Add a new slot on each button OnClick list by clicking the (+) sign, assign the Book as the game object then select the “AutoFlip->FlipRightPage” for the next button and “Auto Flip->Flip Left Page” to the previous button.  If you need to flip the page from code (based on custom action) you can call the FlipLeftPage() or FlipRightPage().

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 18
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值