123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450 |
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- using System;
- /// <summary>
- /// 加载动画
- /// </summary>
- public class UI_LoadingWindow : MonoBehaviour
- {
- /// <summary>
- /// 窗体单例
- /// </summary>
- public static UI_LoadingWindow pInit = null;
- /// <summary>
- /// 根节点
- /// </summary>
- private GameObject mRoot = null;
- /// <summary>
- /// 加载场景的图片
- /// </summary>
- private GameObject mLoadScene = null;
- /// <summary>
- /// 加载场景的动圈
- /// </summary>
- private GameObject mLoadPanel = null;
- /// <summary>
- /// loading 圈圈Transform
- /// </summary>
- public Transform mCircularTran = null;
- /// <summary>
- /// loading 圈圈Transform
- /// </summary>
- public Transform mCircularTran2 = null;
- /// <summary>
- /// 进度条
- /// </summary>
- private GameObject mProgressObject = null;
- /// <summary>
- /// 进度条
- /// </summary>
- private Image mProgressSlider = null;
- /// <summary>
- /// 当前正在显示的背景
- /// </summary>
- private Image mCurtBg = null;
- /// <summary>
- /// 底部蓝光背景
- /// </summary>
- private Image mButtomImage = null;
- /// <summary>
- /// 当前正在显示的背景
- /// </summary>
- private GameObject mCurtBgObj = null;
- /// <summary>
- /// 当前进度条跟随点
- /// </summary>
- private GameObject mProgressSliderDot = null;
- /// <summary>
- /// 当前进度条进度文字
- /// </summary>
- private Text mProgressText = null;
- /// <summary>
- /// 场景模式
- /// </summary>
- private bool sceneMode = false;
- /// <summary>
- /// 界面
- /// </summary>
- private bool uiMode = false;
- /// <summary>
- /// 渐隐时间
- /// </summary>
- private float mFadeTime = 1;
- /// <summary>
- /// 起始位置
- /// </summary>
- private float mStart = -850;
- /// <summary>
- /// 终点位置
- /// </summary>
- private float mEnt = 870;
- /// <summary>
- /// 速度
- /// </summary>
- private float mSpeed = 0.1f;
- /// <summary>
- /// 目标进度
- /// </summary>
- private float prog = 0;
- /// <summary>
- /// 当前进度
- /// </summary>
- private float curt = 0;
- private int LoadingWinSmallTipsIndex = 0;
- /// <summary>
- /// 临时用的tips数组
- /// </summary>
- readonly string[] smalltips = new string[] { "小贴士:夜神月触发极限闪避后,大幅降低所有怪物的攻击与移动速度",
- "小贴士:言灵师品阶提升,可以提高各基本属性的成长值",
- "小贴士:更换更为精良的武器,可以提升言灵师的战斗力",
- "小贴士:战斗中灵活使用言灵师的闪避技,躲避敌人攻击",
- "小贴士:卡琳娜的必杀技可以为所有队员回复一定生命值",
- "小贴士:言灵分为左、右、中三派,分别代表攻击、防御和攻守兼备",
- };
- private string mTipContent = "加载场景";
- /// <summary>
- /// 显示tips的变量
- /// </summary>
- private float elips = 0f;
- /// <summary>
- ///
- /// </summary>
- private Text mTipsText = null;
- /// <summary>
- ///
- /// </summary>
- private bool isInitFont = false;
- /// <summary>
- /// 获取单键
- /// </summary>
- /// <returns>单键实例</returns>
- public static UI_LoadingWindow Instance()
- {
- return pInit;
- }
- /// <summary>
- /// 初始化
- /// </summary>
- private void Awake()
- {
- pInit = this;
- // 初始化
- mRoot = transform.Find("Root").gameObject;
- mLoadScene = transform.Find("Root/LoadScene").gameObject;
- mLoadPanel = transform.Find("Root/LoadPanel").gameObject;
- mProgressObject = transform.Find("Root/LoadScene/ProgressSlider").gameObject;
- mProgressSliderDot = transform.Find("Root/LoadScene/ProgressSlider/ProgressText").gameObject;
- mProgressSliderDot.transform.localPosition = new Vector3(mStart, 86, 0);
- mCircularTran = transform.Find("Root/LoadPanel/cricle");
- mCircularTran2 = transform.Find("Root/LoadPanel/cricle (1)");
- mLoadScene.SetActive(false);
- mLoadPanel.SetActive(false);
- elips = 2.5f;
- DontDestroyOnLoad(gameObject);
- }
- /// <summary>
- /// 设置 UI 的字体
- /// </summary>
- /// <param name="uiObj"> UI对象 </param>
- public void SetFont(GameObject uiObj)
- {
- if (null == uiObj)
- {
- Debug.LogError("PanelHelper 设置字体,UI 为空,中断");
- return;
- }
- // 获取所有的 Text
- Text[] allText = uiObj.GetComponentsInChildren<Text>(true);
- // 设置字体
- for (int i = 0; i < allText.Length; i++)
- {
- allText[i].font = FontManager.Instance().CurFont;
- allText[i].fontStyle = FontStyle.Normal;
- }
- }
- /// <summary>
- /// 更新百分比
- /// </summary>
- /// <param name="progress"></param>
- /// <param name="speedCorrect">速度修正</param>
- public void SetProgress(int progress, string content = "")
- {
- if (!isInitFont)
- {
- SetFont(this.gameObject);
- }
- if (sceneMode)
- {
- this.prog = progress * 1.0f / 100;
- }
- }
- /// <summary>
- /// 叠加百分比
- /// </summary>
- /// <param name="progress"></param>
- /// <param name="speedCorrect">速度修正</param>
- public void SetAddProgress(int progress)
- {
- if (!isInitFont)
- {
- SetFont(this.gameObject);
- }
- if (sceneMode)
- {
- float newPrg = this.prog + progress * 1.0f / 100;
- if (newPrg >= 1)
- {
- this.prog = 1;
- }
- else
- {
- this.prog = newPrg;
- }
- }
- }
- /// <summary>
- /// 自动持续时间
- /// </summary>
- /// <param name="_continueTime"></param>
- public void SetAutoProgress(float _continueTime, Action ac)
- {
- Debug.LogError(Time.realtimeSinceStartup);
- if (_continueTime <= 0)
- {
- this.isAuto = false;
- this.curt = 1;
- this.prog = 1;
- }
- else
- {
- this.isAutoOverAction = ac;
- this.isAuto = true;
- this.curt = 0;
- this.prog = 1;
- this.mSpeed = 1 / (_continueTime / Time.deltaTime);
- }
- }
- private Action isAutoOverAction;
- private bool isAuto = false;
- /// <summary>
- /// 更新
- /// </summary>
- private void Update()
- {
- if (this.isAuto)
- {
- this.curt += this.mSpeed;
- Debug.Log(this.curt);
- if (this.curt >= 0.95)
- {
- this.curt = 1;
- this.isAuto = false;
- if (this.isAutoOverAction != null)
- {
- this.isAutoOverAction.Invoke();
- }
- }
- }
- // 场景模式(带Loading图)
- if (sceneMode)
- {
- this.curt = Mathf.Lerp(this.curt, this.prog, prog < curt || prog >= 1 ? 1 : mSpeed);
- mProgressSlider.fillAmount = this.curt;
- mProgressText.text = (int)(this.curt * 100) + "%";
- mProgressSliderDot.transform.localPosition = new Vector3(Mathf.Lerp(mStart, mEnt, this.curt), 86, 0);
- //mTipsText.text = this.mTipContent;
- elips += Time.deltaTime;
- if (elips > 2.5f)
- {
- // 每隔1秒更新tips
- elips = 0f;
- LoadingWinSmallTipsIndex++;
- if (LoadingWinSmallTipsIndex >= smalltips.Length)
- {
- LoadingWinSmallTipsIndex = 0;
- }
- mTipsText.text = smalltips[LoadingWinSmallTipsIndex];
- SetAddProgress(2);
- }
- }
- // UI模式(带小加载圈)
- if (uiMode)
- {
- mCircularTran.Rotate(-Vector3.forward * Time.deltaTime * 360);
- mCircularTran2.Rotate(Vector3.forward * Time.deltaTime * 360);
- }
- }
- /// <summary>
- /// 显示
- /// </summary>
- /// <param name="_type">0=透明背景动画(场景) 1=无背景转圈(窗体) 2=背景动画(战斗)</param>
- public void Show(int _type = 2)
- {
- switch (_type)
- {
- case 0:
- break;
- case 1:
- uiMode = true;
- this.mLoadPanel.SetActive(true);
- break;
- case 2:
- sceneMode = true;
- this.mProgressObject.SetActive(true);
- // 显示背景
- int mBgIndex = UnityEngine.Random.Range(0, 3);
- this.mCurtBgObj = transform.Find("Root/LoadScene/BgLst/Image" + mBgIndex).gameObject;
- this.mCurtBgObj.SetActive(true);
- this.mCurtBgObj.GetComponent<Image>().CrossFadeAlpha(1, mFadeTime, true);
- this.mLoadScene.SetActive(true);
- this.InitProgress();
- if (this.mTipsText == null)
- {
- this.mTipsText = transform.Find("Root/LoadScene/TextTip").gameObject.GetComponent<Text>();
- this.mTipsText.text = "0%";
- }
- this.mButtomImage = transform.Find("Root/LoadScene/ButtomImage").gameObject.GetComponent<Image>();
- this.mButtomImage.CrossFadeAlpha(1, mFadeTime, true);
- //mTipsText.text = smalltips[LocalSettings.LoadingWinSmallTipsIndex];
- break;
- }
- if (!isInitFont)
- {
- SetFont(this.gameObject);
- }
- }
- /// <summary>
- ///
- /// </summary>
- private void InitProgress()
- {
- if (this.mProgressSlider == null)
- {
- this.mProgressSlider = transform.Find("Root/LoadScene/ProgressSlider/ImageProgress").gameObject.GetComponent<Image>();
- }
- mProgressSlider.fillAmount = 0;
- if (this.mProgressText == null)
- {
- this.mProgressText = transform.Find("Root/LoadScene/ProgressSlider/ProgressText/Text").gameObject.GetComponent<Text>();
- }
- this.mProgressText.text = "0%";
- }
- /// <summary>
- /// 隐藏
- /// </summary>
- public void Hide(int type = 2)
- {
- switch (type)
- {
- case 1:
- uiMode = false;
- this.mLoadPanel.SetActive(false);
- break;
- case 2:
- if (this.mProgressSlider != null)
- {
- sceneMode = false;
- this.mLoadScene.SetActive(false);
- this.curt = 0;
- this.prog = 0;
- this.mProgressSlider.fillAmount = 0;
- this.mProgressText.text = "0%";
- this.mProgressSliderDot.transform.localPosition = new Vector3(mStart, 86, 0);
- this.mProgressObject.SetActive(false);
- this.mButtomImage.CrossFadeAlpha(0, mFadeTime, true);
- if (this.mCurtBgObj != null)
- {
- this.mCurtBgObj.GetComponent<Image>().CrossFadeAlpha(0, mFadeTime, true);
- }
- this.mTipsText.text = "0%";
- Invoke("ClosePanel", mFadeTime);
- }
- break;
- case 3:
- if (this.mProgressSlider != null)
- {
- this.curt = 0;
- this.prog = 0;
- this.mProgressSlider.fillAmount = 0;
- this.mProgressText.text = "0%";
- this.mProgressSliderDot.transform.localPosition = new Vector3(mStart, 86, 0);
- this.mProgressObject.SetActive(false);
- this.mButtomImage.CrossFadeAlpha(0, mFadeTime, true);
- if (this.mCurtBgObj != null)
- {
- this.mCurtBgObj.GetComponent<Image>().CrossFadeAlpha(0, mFadeTime, true);
- }
- this.mTipsText.text = "0%";
- Invoke("ClosePanel", 0.2f);
- }
- break;
- }
- }
- /// <summary>
- ///
- /// </summary>
- void ClosePanel()
- {
- this.mCurtBgObj.gameObject.SetActive(false);
- }
- }
|