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 { /// /// 步骤 /// public TextMeshProUGUI tittle_text; /// /// 描述文本 /// public TextMeshProUGUI description_text; /// /// 关闭按钮 /// public Button close_button; /// /// 我已完成按钮 /// public Button im_done_button; /// /// 媒体容器 /// public RectTransform media_content; /// /// 媒体预制体 /// public MediaItem image_media_prefab; /// /// 上一个媒体按钮 /// public Button media_last_button; /// /// 下一个媒体按钮 /// public Button media_next_button; /// /// 已实例化媒体Item列表 /// public List image_media_pool = new List(); /// /// 使用中的Item列表 /// private List using_media_list = new List(); /// /// 最大数量 /// public int max_media_count => using_media_list.Count; /// /// 当前媒体浏览滑动位置 /// 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); } } } } } /// /// 面板关闭事件 /// public void OnClose() { OnNagetive(); //图片状态恢复 media_content.anchoredPosition = Vector2.zero; current_media_index = 0; } /// /// 获取步骤图片 /// /// public void GetImage(string _url) { if (image_media_prefab == null) image_media_prefab = Resources.Load("Prefabs/UIItem/MediaItem"); StartCoroutine(GetSprite(_url, (_sprite) => { var _item = Get(); _item.InitImage(_sprite); using_media_list.Add(_item); })); } /// /// 获取步骤视频 /// /// public void GetVideo(string _url) { if (image_media_prefab == null) image_media_prefab = Resources.Load("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; } /// /// 上一个媒体 /// 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); } /// /// 下一个媒体 /// 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); } /// /// 获取 /// /// 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; } /// /// 回收 /// 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); } } }