using System.Collections; using System.Collections.Generic; using System.IO; using DG.Tweening; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Networking; using UnityEngine.UI; public class ZX8Controller : MonoBehaviour { public static ZX8Controller Instance; private void Awake() { Instance = this; } /// /// 数据文件 /// public string DataFileName = "Books.json"; /// /// 书籍字典 /// Key:书籍名称,Value:总页数 /// public Dictionary dicBooks; /// /// 图片路径 /// string ImagePath; /// /// 书籍Book组件 /// public Book bookContents; /// /// 书籍预设体 /// public GameObject preBook1; /// /// 书籍预设体 /// public GameObject preBook2; /// /// 书籍生成所在父对象 /// public Transform bookParent; /// /// 书籍标题Text /// public Text txtTitle; /// /// 关闭按钮 /// public Button btnClose; /// /// 显示选项按钮 /// public Button btnShowOp; public Sprite spShowOp1; public Sprite spShowOp2; public Animator anim; string basePath; void Start() { basePath = CommonData.DataServer + "/ZX8/"; StartCoroutine(JsonLoader.LoadJSON(basePath + "Data/" + DataFileName, OnGetBookListCompleted)); if (btnClose != null) btnClose.onClick.AddListener(OnBtnCloseClick); if (btnShowOp != null) btnShowOp.onClick.AddListener(OnBtnShowOpClick); } /// /// 获取书籍列表结束 /// public void OnGetBookListCompleted(string data) { dicBooks = JsonTools.DicFromJson(data); InitialBooks1(); #region //dicBooks = new Dictionary(); //dicBooks.Add("白鹿原", 7); //dicBooks.Add("红与黑", 7); //dicBooks.Add("狂人日记", 5); //dicBooks.Add("年轮", 4); //string data = JsonTools.DicToJson(dicBooks); //StreamWriter writer = File.CreateText(DataFileName); //writer.Write(data); //writer.Close(); #endregion } /// /// 初始化书籍列表 /// void InitialBooks1() { foreach (Transform child in bookParent) { Destroy(child.gameObject); } int i = 0; // 遍历所有的书籍 foreach (string key in dicBooks.Keys) { // 创建书籍对象,并初始化名称、位置及封面(0.jpg) GameObject obj = Instantiate(preBook1, bookParent); obj.name = key; obj.transform.position -= Vector3.up * i * 280f; StartCoroutine( ImageLoader.LoadImage( string.Format("{0}Books/{1}/{2}.jpg", basePath, key, 0), obj.transform.GetChild(0).GetComponent())); obj.transform.GetChild(0).GetComponent