213 lines
5.7 KiB
C#
213 lines
5.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using static InterfaceManager;
|
|
using DG.Tweening;
|
|
using System.IO;
|
|
using Newtonsoft.Json;
|
|
using static MainCanvasManager;
|
|
|
|
/// <summary>
|
|
/// 课程目标面板
|
|
/// </summary>
|
|
public class ObjectivePanel : PanelBasic
|
|
{
|
|
/// <summary>
|
|
/// 目标描述
|
|
/// </summary>
|
|
public TextMeshProUGUI objective_description_text;
|
|
/// <summary>
|
|
/// 提交要求
|
|
/// </summary>
|
|
public TextMeshProUGUI submission_requirement_text;
|
|
|
|
/// <summary>
|
|
/// 任务目标数据
|
|
/// </summary>
|
|
public class ObjectiveData
|
|
{
|
|
/// <summary>
|
|
/// 目标描述
|
|
/// </summary>
|
|
public string objective_description;
|
|
/// <summary>
|
|
/// 提交要求
|
|
/// </summary>
|
|
public string submission_requirement;
|
|
/// <summary>
|
|
/// 图片素材地址
|
|
/// </summary>
|
|
public string[] image_urls;
|
|
/// <summary>
|
|
/// 视频素材地址
|
|
/// </summary>
|
|
public string[] video_urls;
|
|
}
|
|
|
|
public ObjectiveData objective_data;
|
|
/// <summary>
|
|
/// 媒体预制体
|
|
/// </summary>
|
|
public MediaItem objective_media_prefab;
|
|
/// <summary>
|
|
/// 上一个媒体按钮
|
|
/// </summary>
|
|
public Button media_last_button;
|
|
/// <summary>
|
|
/// 下一个媒体按钮
|
|
/// </summary>
|
|
public Button media_next_button;
|
|
/// <summary>
|
|
/// 确认按钮
|
|
/// </summary>
|
|
public Button objective_confirm_button;
|
|
/// <summary>
|
|
/// 媒体容器
|
|
/// </summary>
|
|
public RectTransform objective_media_content;
|
|
/// <summary>
|
|
/// 使用中的Item列表
|
|
/// </summary>
|
|
private List<MediaItem> using_media_list = new List<MediaItem>();
|
|
/// <summary>
|
|
/// 当前媒体浏览滑动位置
|
|
/// </summary>
|
|
public int current_media_index;
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
objective_confirm_button.onClick.AddListener(OnObjectiveConfirm);
|
|
media_last_button.onClick.AddListener(OnLastMedia);
|
|
media_next_button.onClick.AddListener(OnNextMedia);
|
|
|
|
//var _url = Path.Combine(Application.streamingAssetsPath, "LocalConfig/Objective.txt");
|
|
//StartCoroutine(Get(_url, (_data) =>
|
|
//{
|
|
// objective_data = JsonConvert.DeserializeObject<ObjectiveData>(_data);
|
|
// Init(objective_data);
|
|
//}));
|
|
|
|
//初始化
|
|
ObjectiveData data = new ObjectiveData();
|
|
data.objective_description = task_panel.task_item_data.task_description;
|
|
data.submission_requirement = "等待配置";
|
|
List<string> tmpPicts=new List<string>();
|
|
List<string> tmpvideos = new List<string>();
|
|
task_panel.task_item_data.task_picturelist.ForEach(item =>
|
|
{
|
|
if(!string.IsNullOrEmpty(item.fileurl))
|
|
{
|
|
if (item.type == 1)
|
|
{
|
|
//图片
|
|
tmpPicts.Add(item.fileurl);
|
|
}
|
|
else
|
|
{
|
|
//视频
|
|
tmpvideos.Add(item.fileurl);
|
|
}
|
|
}
|
|
});
|
|
data.image_urls = tmpPicts.ToArray();
|
|
data.video_urls = tmpvideos.ToArray();
|
|
Init(data);
|
|
}
|
|
|
|
public void Init(ObjectiveData _objective_data)
|
|
{
|
|
objective_data = _objective_data;
|
|
|
|
objective_description_text.text = "\t" + objective_data.objective_description;
|
|
submission_requirement_text.text = "\t" + objective_data.submission_requirement;
|
|
|
|
for (int i = 0; i < _objective_data.image_urls.Length; i++)
|
|
{
|
|
GetImage(_objective_data.image_urls[i]);
|
|
}
|
|
|
|
for (int i = 0; i < _objective_data.video_urls.Length; i++)
|
|
{
|
|
GetVideo(_objective_data.video_urls[i]);
|
|
}
|
|
|
|
if (_objective_data.image_urls.Length + _objective_data.video_urls.Length > 1)
|
|
{
|
|
media_last_button.gameObject.SetActive(true);
|
|
media_next_button.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 面板关闭事件
|
|
/// </summary>
|
|
public void OnObjectiveConfirm()
|
|
{
|
|
OnNagetive();
|
|
|
|
//图片状态恢复
|
|
objective_media_content.anchoredPosition = Vector2.zero;
|
|
current_media_index = 0;
|
|
}
|
|
/// <summary>
|
|
/// 上一个媒体
|
|
/// </summary>
|
|
public void OnLastMedia()
|
|
{
|
|
if (current_media_index > 0)
|
|
current_media_index--;
|
|
|
|
objective_media_content.DOAnchorPos(new Vector2(-current_media_index * (objective_media_content.rect.width + 5), 0), 0.25f);
|
|
}
|
|
/// <summary>
|
|
/// 下一个媒体
|
|
/// </summary>
|
|
public void OnNextMedia()
|
|
{
|
|
if (current_media_index < using_media_list.Count - 1)
|
|
current_media_index++;
|
|
|
|
objective_media_content.DOAnchorPos(new Vector2(-current_media_index * (objective_media_content.rect.width + 5), 0), 0.25f);
|
|
}
|
|
/// <summary>
|
|
/// 获取图片
|
|
/// </summary>
|
|
/// <param name="_url"></param>
|
|
public void GetImage(string _url)
|
|
{
|
|
if (objective_media_prefab == null) objective_media_prefab = Resources.Load<MediaItem>("Prefabs/UIItem/MediaItem");
|
|
StartCoroutine(GetSprite(_url, (_sprite) =>
|
|
{
|
|
var _item = GetItem();
|
|
_item.InitImage(_sprite);
|
|
using_media_list.Add(_item);
|
|
}));
|
|
}
|
|
/// <summary>
|
|
/// 获取视频
|
|
/// </summary>
|
|
/// <param name="_url"></param>
|
|
public void GetVideo(string _url)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public MediaItem GetItem()
|
|
{
|
|
MediaItem _item = Instantiate(objective_media_prefab, objective_media_content);
|
|
return _item;
|
|
}
|
|
}
|