|
|
Chinar 教程效果:
1
Show One by one —— 一个个显示图片
通过协程,一个一个加载并显示图片
Resources 中创建一个预设物 Image ,用来动态加载实例化
using System.Collections;using UnityEngine;using UnityEngine.UI;////// 逐个加载图片/// public class ChinarLoadImage : MonoBehaviour{ public GameObject PanelGrid; //父物体组 void Start() { StartCoroutine(BurnGranule()); //第1种方式,开协程 //InvokeRepeating("BurnImage", 0, 0.2f); //第2种方式,想要结束用CancelInvoke(); } ////// 1:供 InvokeRepeating 调用执行 /// private void BurnImage() { GameObject go = Instantiate(Resources.Load("Image")); go.transform.SetParent(PanelGrid.transform); } /// /// 2:用协程逐个生成Image图片 /// ///IEnumerator BurnGranule() { while (true) { GameObject go = Instantiate(Resources.Load ("Image")); go.transform.SetParent(PanelGrid.transform); yield return new WaitForSeconds(0.1f); if (PanelGrid.transform.childCount > 40) //跳出循环条件 { break; } } }}
2
TextOne by one —— 一个个显示文字
将需要显示的文字转为字符,然后一个个的取出,并通过协成完成显示
using System.Collections;using UnityEngine;using UnityEngine.UI;////// 一个个显示文字/// public class ChinarLoadingText : MonoBehaviour{ public Text text; //故事面板文字栏 private string textTemp; //故事面板具体文字 private char[] cc; void Start() { StartOne(); } private void StartOne() { text.text = ""; textTemp = "Chinar 坚持将简单的生活方式,带给世人!\n"; //需要显示的文字 cc = textTemp.ToCharArray(); //将string类型里的每一个字转化成char集合 StartCoroutine(TextOne()); } IEnumerator TextOne() { bool isGo = true; while (isGo) { for (int i = 0; i < cc.Length; i++) { yield return new WaitForEndOfFrame(); text.text += cc[i]; } } }}
支持
May Be —— 搞开发,总有一天要做的事!
|
本博客为非营利性个人原创,除部分有明确署名的作品外,所刊登的所有作品的著作权均为本人所拥有,本人保留所有法定权利。违者必究 对于需要复制、转载、链接和传播博客文章或内容的,请及时和本博主进行联系,留言,Email: ichinar@icloud.com 对于经本博主明确授权和许可使用文章及内容的,使用时请注明文章或内容出处并注明网址