1.初始化页面到第一页
book.CurrentPaper=0;
2.BookPro动态添加页面
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayContent : MonoBehaviour
{
//TextSetting textSetting;//
//RoleName roleName;
//ReadTxt txt = new ReadTxt();
//Text story;
//string path;
//public int pageLine = 13;
/// <summary>
/// 页面列表
/// </summary>
public List<Text> tList = new List<Text>();
BookPro book;//book插件
//InputField inputPage;//目标页码输入框
//Button turn;//跳转按钮
private void Awake()
{
book = transform.Find("BookPro").GetComponent<BookPro>();
//inputPage = transform.Find("InputPages").GetComponent<InputField>();
//turn = transform.Find("Turn").GetComponent<Button>();
//turn.onClick.AddListener(TurnPageCB);
//textSetting = new TextSetting();
//roleName = (RoleName)System.Enum.Parse(typeof(RoleName), RoleBase.instance.Name);
//story = transform.Find("BookPro/Page1/Content").GetComponent<Text>();//文本组件
//ChangeRoleStory();
AddPages();//添加页面
//textSetting.AutoFillNextText(tList, txt.Read(path));//更新页面文本
}
// Start is called before the first frame update
void Start()
{
//Net.MsgEvent += Net_MsgEvent;
}
GameObject pre_page;//用于生成页面的模板
/// <summary>
/// 添加新的书页
/// </summary>
public void AddPages()
{
int allPages = 10;//总页数
int havePages = book.papers.Count * 2 - 1;//每一张纸分两页,除去第一页
int needPages = allPages - havePages;//算出还差多少页
int needpapers = Mathf.CeilToInt(needPages / 2.0f);//还差多少张纸
if (!pre_page)
pre_page = book.transform.Find("Page").gameObject;
for (int i = 0; i < needpapers; i++)//差几张纸就生成几张
{
//正面
GameObject g_front = Instantiate(pre_page, book.transform).gameObject;//实例化
g_front.name = "Page" + (i * 2 + havePages + 1).ToString();//命名(纸张*2就是页数,页数+1就是单数页)
g_front.gameObject.SetActive(true);
//g_front.transform.Find("Num").GetComponent<Text>().text = (i * 2 + havePages + 1).ToString();//页码文本
//tList.Add(g_front.transform.Find("Content").GetComponent<Text>());//添加
//背面
GameObject g_back = Instantiate(pre_page, book.transform).gameObject;//实例
g_back.name = "Page" + (i * 2 + havePages + 2).ToString();//(页数+2就是双数页)
g_back.gameObject.SetActive(true);
//g_back.transform.Find("Num").GetComponent<Text>().text = (i * 2 + havePages + 2).ToString();//页码文本
//tList.Add(g_back.transform.Find("Content").GetComponent<Text>());//添加
book.papers.Add(new Paper());//添加一张
book.papers[i + 2].Front = g_front;//前两张已经有了,从第三张开始赋值
book.papers[i + 2].Back = g_back;//前两张已经有了,从第三张开始赋值
}
//book.UpdatePages();
book.StartFlippingPaper = 0;
book.EndFlippingPaper = book.papers.Count;
}
/ <summary>
/ 跳页
/ </summary>
//void TurnPageCB()
//{
// int currentPage = book.CurrentPaper;
// int input = int.Parse(inputPage.text);
// if (input == currentPage) return;
// if (Mathf.CeilToInt(input / 2.0f) > book.papers.Count)
// {
// input = book.papers.Count*2-1;
// inputPage.text = input.ToString();
// }
// book.currentPaper = Mathf.CeilToInt(input / 2.0f);
// book.UpdatePages();
//}
}