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