226 lines
6.2 KiB
C#
226 lines
6.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using static InterfaceManager;
|
|
using DG.Tweening;
|
|
using UnityEngine.Video;
|
|
|
|
public class TaskDetailPanel : PanelBasic
|
|
{
|
|
/// <summary>
|
|
/// 步骤
|
|
/// </summary>
|
|
public TextMeshProUGUI tittle_text;
|
|
/// <summary>
|
|
/// 描述文本
|
|
/// </summary>
|
|
public TextMeshProUGUI description_text;
|
|
|
|
/// <summary>
|
|
/// 关闭按钮
|
|
/// </summary>
|
|
public Button close_button;
|
|
/// <summary>
|
|
/// 我已完成按钮
|
|
/// </summary>
|
|
public Button im_done_button;
|
|
/// <summary>
|
|
/// 媒体容器
|
|
/// </summary>
|
|
public RectTransform media_content;
|
|
/// <summary>
|
|
/// 媒体预制体
|
|
/// </summary>
|
|
public MediaItem image_media_prefab;
|
|
/// <summary>
|
|
/// 上一个媒体按钮
|
|
/// </summary>
|
|
public Button media_last_button;
|
|
/// <summary>
|
|
/// 下一个媒体按钮
|
|
/// </summary>
|
|
public Button media_next_button;
|
|
/// <summary>
|
|
/// 已实例化媒体Item列表
|
|
/// </summary>
|
|
public List<MediaItem> image_media_pool = new List<MediaItem>();
|
|
/// <summary>
|
|
/// 使用中的Item列表
|
|
/// </summary>
|
|
private List<MediaItem> using_media_list = new List<MediaItem>();
|
|
/// <summary>
|
|
/// 最大数量
|
|
/// </summary>
|
|
public int max_media_count => using_media_list.Count;
|
|
/// <summary>
|
|
/// 当前媒体浏览滑动位置
|
|
/// </summary>
|
|
public int current_media_index;
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
}
|
|
|
|
//public Image
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
close_button.onClick.AddListener(OnClose);
|
|
media_last_button.onClick.AddListener(OnLastMedia);
|
|
media_next_button.onClick.AddListener(OnNextMedia);
|
|
}
|
|
private TaskStep last_task_item_data;
|
|
public void Init(TaskStep _task_detail_data)
|
|
{
|
|
//判断是否和上次打开时为同一条数据
|
|
bool is_same_step = last_task_item_data == null ? false : last_task_item_data.id == _task_detail_data.id;
|
|
last_task_item_data = _task_detail_data;
|
|
if (is_same_step)
|
|
{
|
|
//同一个不作处理
|
|
//using_media_list.ForEach(x=>x.gameObject.SetActive(true));
|
|
}
|
|
else
|
|
{
|
|
Recycle();
|
|
//对接讯飞得改动
|
|
tittle_text.text = "步骤 "+(int.Parse(_task_detail_data.sort)+1).ToString() ;
|
|
//原来的
|
|
//tittle_text.text = "步骤 " + _task_detail_data.sort;
|
|
// tittle_text.text = "步骤 " ;//_task_detail_data.task_step//;
|
|
//展示步骤提示
|
|
description_text.text = _task_detail_data.tipContent;
|
|
|
|
//是否显示上一个下一个按钮
|
|
media_last_button.gameObject.SetActive(_task_detail_data.taskStepTipFileList.Count >= 2);
|
|
media_next_button.gameObject.SetActive(_task_detail_data.taskStepTipFileList.Count >= 2);
|
|
|
|
|
|
|
|
for (int i = 0; i < _task_detail_data.taskStepTipFileList.Count; i++)
|
|
{
|
|
if (!string.IsNullOrEmpty(_task_detail_data.taskStepTipFileList[i].fileUrl))
|
|
{
|
|
|
|
if (_task_detail_data.taskStepTipFileList[i].type==1)
|
|
{
|
|
//图片
|
|
GetImage(_task_detail_data.taskStepTipFileList[i].fileUrl);
|
|
}
|
|
else if(_task_detail_data.taskStepTipFileList[i].type == 2)
|
|
{
|
|
//视频
|
|
GetVideo(_task_detail_data.taskStepTipFileList[i].fileUrl);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 面板关闭事件
|
|
/// </summary>
|
|
public void OnClose()
|
|
{
|
|
OnNagetive();
|
|
|
|
//图片状态恢复
|
|
media_content.anchoredPosition = Vector2.zero;
|
|
current_media_index = 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取步骤图片
|
|
/// </summary>
|
|
/// <param name="_url"></param>
|
|
public void GetImage(string _url)
|
|
{
|
|
if (image_media_prefab == null) image_media_prefab = Resources.Load<MediaItem>("Prefabs/UIItem/MediaItem");
|
|
StartCoroutine(GetSprite(_url, (_sprite) =>
|
|
{
|
|
var _item = Get();
|
|
_item.InitImage(_sprite);
|
|
using_media_list.Add(_item);
|
|
}));
|
|
}
|
|
/// <summary>
|
|
/// 获取步骤视频
|
|
/// </summary>
|
|
/// <param name="_url"></param>
|
|
public void GetVideo(string _url)
|
|
{
|
|
if (image_media_prefab == null) image_media_prefab = Resources.Load<MediaItem>("Prefabs/UIItem/MediaItem");
|
|
var _item = Get();
|
|
using_media_list.Add(_item);
|
|
_item.InitVideo(_url);
|
|
|
|
}
|
|
|
|
public RenderTexture GetRenderTexture(int _width, int _height, int _depth = 16)
|
|
{
|
|
RenderTexture rt = new RenderTexture(_width, _height, _depth, RenderTextureFormat.ARGB32);
|
|
rt.Create();
|
|
return rt;
|
|
}
|
|
/// <summary>
|
|
/// 上一个媒体
|
|
/// </summary>
|
|
public void OnLastMedia()
|
|
{
|
|
if (current_media_index > 0)
|
|
current_media_index--;
|
|
|
|
media_content.DOAnchorPos(new Vector2(-current_media_index * (media_content.rect.width + 5), 0), 0.25f);
|
|
}
|
|
/// <summary>
|
|
/// 下一个媒体
|
|
/// </summary>
|
|
public void OnNextMedia()
|
|
{
|
|
if (current_media_index < max_media_count - 1)
|
|
current_media_index++;
|
|
|
|
media_content.DOAnchorPos(new Vector2(-current_media_index * (media_content.rect.width + 5), 0), 0.25f);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public MediaItem Get()
|
|
{
|
|
MediaItem _item;
|
|
if (image_media_pool.Count > 0)
|
|
{
|
|
_item = image_media_pool[0];
|
|
image_media_pool.Remove(_item);
|
|
_item.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
_item = Instantiate(image_media_prefab, media_content);
|
|
}
|
|
return _item;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 回收
|
|
/// </summary>
|
|
public void Recycle()
|
|
{
|
|
var _count = using_media_list.Count;
|
|
for (int i = _count - 1; i >= 0; i--)
|
|
{
|
|
var _item = using_media_list[i];
|
|
_item.gameObject.SetActive(false);
|
|
using_media_list.Remove(_item);
|
|
image_media_pool.Add(_item);
|
|
}
|
|
}
|
|
}
|