164 lines
4.7 KiB
C#
164 lines
4.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Thousandto.Launcher.Form
|
|
{
|
|
public class UIBackgroupPanelScript : MonoBehaviour
|
|
{
|
|
|
|
#region//常量
|
|
//最大轮换图片数量
|
|
private const int MAX_IMG_SHOW_COUNT = 3;
|
|
private const string CN_IMAGE_FILE_EXT = ".jpg";
|
|
#endregion
|
|
|
|
#region//私有数据变量
|
|
private UISutureTextureData defaultTex = new UISutureTextureData();
|
|
//组合纹理列表
|
|
private List<UISutureTextureData> _imgShowList = new List<UISutureTextureData>();
|
|
|
|
//图片所在的位置
|
|
private string _imageShowPath = "ImgShow/imgshow_";
|
|
|
|
#endregion
|
|
|
|
#region //UI控件
|
|
private UISutureTexture[] _uiTexrues;
|
|
private Transform _trans;
|
|
#endregion
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
OnInit();
|
|
}
|
|
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
OnFirstShow(transform);
|
|
StartCoroutine(OnCycleShow());
|
|
}
|
|
|
|
public void OnDestroy()
|
|
{
|
|
|
|
for (int i = 0; i < _imgShowList.Count; ++i)
|
|
{
|
|
_imgShowList[i].UnLoad();
|
|
}
|
|
|
|
_imgShowList.Clear();
|
|
}
|
|
|
|
|
|
private void OnInit()
|
|
{
|
|
var lan = string.IsNullOrEmpty(UnityEngine.Gonbest.MagicCube.FLanguage.Default) ? "CH" : UnityEngine.Gonbest.MagicCube.FLanguage.Default;
|
|
var pl = "Default";
|
|
if (Application.platform == RuntimePlatform.IPhonePlayer)
|
|
{
|
|
pl = "IOS";
|
|
}
|
|
else if (Application.platform == RuntimePlatform.WebGLPlayer)
|
|
{
|
|
pl = "WEB";
|
|
}
|
|
else if (Application.platform == RuntimePlatform.Android)
|
|
{
|
|
pl = "Android";
|
|
}
|
|
_imageShowPath = string.Format("ImgShow/{0}/{1}/imgshow_", lan, pl);
|
|
defaultTex.IsFromStreamFile = true;
|
|
defaultTex.FileExt = CN_IMAGE_FILE_EXT;
|
|
//加载默认
|
|
defaultTex.Load("Default/Texture/UI/tex_launcher", null);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 第一次显示时调用
|
|
/// </summary>
|
|
/// <param name="tran"></param>
|
|
private void OnFirstShow(Transform trans)
|
|
{
|
|
_trans = trans.Find("ImageList");
|
|
_uiTexrues = _trans.GetComponentsInChildren<UISutureTexture>(true);
|
|
for (int i = 0; i < _uiTexrues.Length; i++)
|
|
{
|
|
_uiTexrues[i].SetTexture(defaultTex);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//循环展示
|
|
public IEnumerator OnCycleShow()
|
|
{
|
|
yield return null;
|
|
//加载所有的纹理
|
|
for (int i = 1; i <= MAX_IMG_SHOW_COUNT; ++i)
|
|
{
|
|
var tex2D = new UISutureTextureData();
|
|
tex2D.IsFromStreamFile = true;
|
|
tex2D.FileExt = CN_IMAGE_FILE_EXT;
|
|
tex2D.Load(_imageShowPath + i, x =>
|
|
{
|
|
if (tex2D.IsValid)
|
|
{
|
|
_imgShowList.Add(tex2D);
|
|
}
|
|
});
|
|
yield return null;
|
|
}
|
|
|
|
//把UITexture的默认纹理也添加到imgshow中
|
|
if (defaultTex.IsValid)
|
|
{
|
|
_imgShowList.Add(defaultTex);
|
|
}
|
|
|
|
yield return null;
|
|
if (_uiTexrues.Length > 1 && _imgShowList.Count > 0)
|
|
{
|
|
int idx = 0;
|
|
int cnt = _imgShowList.Count;
|
|
bool showFirst = true;
|
|
while (true)
|
|
{
|
|
idx = GetIndex(idx, cnt);
|
|
if (!showFirst)
|
|
{
|
|
yield return null;
|
|
_uiTexrues[1].SetDepth(-6);
|
|
_uiTexrues[0].SetDepth(-5);
|
|
yield return null;
|
|
_uiTexrues[1].SetTexture(_imgShowList[idx]);
|
|
yield return null;
|
|
}
|
|
else
|
|
{
|
|
yield return null;
|
|
_uiTexrues[1].SetDepth(-5);
|
|
_uiTexrues[0].SetDepth(-6);
|
|
yield return null;
|
|
_uiTexrues[0].SetTexture(_imgShowList[idx]);
|
|
yield return null;
|
|
}
|
|
yield return new WaitForSeconds(2.5f);
|
|
showFirst = !showFirst;
|
|
idx++;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
//获得索引
|
|
private int GetIndex(int idx, int max)
|
|
{
|
|
return idx % max;
|
|
}
|
|
}
|
|
} |