Files
TaiWan/Assets/Roaming/Scripts/Show/ImageShow.cs

181 lines
4.9 KiB
C#
Raw Normal View History

2025-10-31 15:20:38 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// ͼƬչʾ<D5B9><CABE>
/// </summary>
public class ImageShow : BaseShow
{
/// <summary>
/// <20><>ʾ<EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
/// </summary>
Material matShow;
/// <summary>
/// <20><>ǰͼƬ<CDBC><C6AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>ͼģʽ<C4A3><CABD>
/// </summary>
int currentIndex;
Texture textureDefault;
void Start()
{
Renderer renderer = GetComponent<Renderer>();
if (renderer == null && !string.IsNullOrEmpty(info.ParentID))
{
GameObject obj = GameObject.Find(info.ParentID);
if (obj != null)
{
renderer = obj.GetComponent<Renderer>();
}
}
if ( renderer != null && info.PlayOnObject)
{
// playOnObject = true;
matShow = renderer.material;
// matShow = renderer.sharedMaterial;
textureDefault = matShow.mainTexture;
LoadImage();
}
if (info.Clickable)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (GetComponent<Collider>() == null)
{
gameObject.AddComponent<MeshCollider>();
}
}
currentIndex = info.Index;
// CanClickStatusChanged += ImageShow_CanClickStatusChanged;
}
private void ImageShow_CanClickStatusChanged()
{
if (info.PlayOnObject)
{
LoadImage();
}
}
string imgName = null;
/// <summary>
/// <20><><EFBFBD><EFBFBD>ͼƬ
/// </summary>
public void LoadImage()
{
if (info.IsType(DataType.Image))
{
imgName = info.ImageName;
info.CurrentURL = info.URL;
}
else // if (info.Type == DataType.MultiImage) // <20><>ͼģʽ
{
if (info.DataDetails.Length < 0)
{
Debug.Log(string.Format("ObjectID:{0}<7D><>DataDetails<6C><73>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", info.ObjectID));
return;
}
if (info.DisplayMode == DisplayMode.RandomPics) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ͼ
{
currentIndex = Random.Range(0, info.DataDetails.Length);
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ͼƬ<CDBC>ͳ<EFBFBD><CDB3><EFBFBD><EFBFBD><EFBFBD>
imgName = info.DataDetails[currentIndex];
info.ImageName = imgName;
if (info.Clickable)
{
if (currentIndex < info.UrlDetails.Length)
{
info.CurrentURL = info.UrlDetails[currentIndex];
info.VideoName = info.CurrentURL;
}
else
{
info.CurrentURL = "";
info.VideoName = info.CurrentURL;
}
if (currentIndex < info.TitleDetails.Length)
{
info.Title = info.TitleDetails[currentIndex];
}
}
if (info.DisplayMode == DisplayMode.MultiPics) // ˳<><CBB3><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ͼ
{
currentIndex++;
currentIndex = currentIndex % info.DataDetails.Length;
}
}
if (CanClick)
{
if (gameObject.activeInHierarchy)
{
StartCoroutine(
ImageLoader<Material>.LoadImage(CommonData.HighImageFullPath + imgName, matShow)
);
}
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD>ʾ<EFBFBD>ٶȺ<D9B6><C8BA>ټ<EFBFBD><D9BC><EFBFBD>ͼƬ
if (info.IsType(DataType.MultiImage) && info.AutoPlay)
{
Invoke("LoadImage", info.DisplaySpeed);
}
}
else
{
matShow.mainTexture = textureDefault;
if (matShow.IsKeywordEnabled("_EMISSION"))
{
matShow.SetTexture("_EmissionMap", textureDefault);
}
ImageLoader<Material>.RemoveImage(CommonData.HighImageFullPath + imgName);
}
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EAB5A5><EFBFBD>¼<EFBFBD>
/// </summary>
public override void OnClick()
{
if (BaseController.CanControl)
{
Invoke("ShowImageEx", 0.01f);
}
}
void ShowImageEx()
{
// <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>Ե<EFBFBD><D4B5><EFBFBD>
//if (!BaseController.IsJoyStickOnControl
// && !BaseController.IsUIClicked
// && BaseController.CanControl
// && BaseController.IsMouseOnControl
// && CanClick)
if (BaseController.CanControl && CanClick)
{
if (info.PlayOnObject)
{
if (!string.IsNullOrEmpty(info.CurrentURL))
{
// Debug.Log(info.CurrentURL);
// H5Controller.OpenUrl(url);
}
}
else if ((info.IsType(DataType.Image) && !string.IsNullOrEmpty(info.ImageName)) || info.IsType(DataType.MultiImage))
{
ImagePlayerEx.Instance.info = info;
ImagePlayerEx.Instance.ShowImage(info.Index);
}
}
}
}