455 lines
14 KiB
C#
455 lines
14 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using UnityEngine.Networking;
|
|
using System.IO;
|
|
|
|
public class MainCanvasManager : PanelBasic
|
|
{
|
|
public static MainCanvasManager Instance;
|
|
/// <summary>
|
|
/// 退出场景
|
|
/// </summary>
|
|
public Button back_button;
|
|
///<summary>
|
|
/// 提交实验退出场景
|
|
/// </summary>
|
|
public Button _back_button;
|
|
/// <summary>
|
|
/// 查看api
|
|
/// </summary>
|
|
public Button api_button;
|
|
/// <summary>
|
|
/// 目标
|
|
/// </summary>
|
|
public Button objective_button;
|
|
/// <summary>
|
|
/// 小窗模式
|
|
/// </summary>
|
|
public Button mini_mode_button;
|
|
/// <summary>
|
|
/// 菜单按钮
|
|
/// </summary>
|
|
public Button menu_button;
|
|
/// <summary>
|
|
/// 星火大模型按钮
|
|
/// </summary>
|
|
public Button spark_model_button;
|
|
/// <summary>
|
|
/// 组件名
|
|
/// </summary>
|
|
public TextMeshProUGUI part_name_text;
|
|
/// <summary>
|
|
/// 场景名称
|
|
/// </summary>
|
|
public TextMeshProUGUI scene_name_text;
|
|
/// <summary>
|
|
/// 模式名称
|
|
/// </summary>
|
|
public TextMeshProUGUI pattern_name_text;
|
|
/// <summary>
|
|
/// 用户信息容器
|
|
/// </summary>
|
|
public Image user_content;
|
|
/// <summary>
|
|
/// 用户头像
|
|
/// </summary>
|
|
public Image user_avatar;
|
|
/// <summary>
|
|
/// 用户名
|
|
/// </summary>
|
|
public TextMeshProUGUI user_name_text;
|
|
public static RectTransform MainCanvas;
|
|
#region Panels
|
|
/// <summary>
|
|
/// 任务步骤面板
|
|
/// </summary>
|
|
public static TaskPanel task_panel { get; set; }
|
|
/// <summary>
|
|
/// 任务详情面板
|
|
/// </summary>
|
|
public static TaskDetailPanel task_detail_panel { get; set; }
|
|
/// <summary>
|
|
/// 控制台面板
|
|
/// </summary>
|
|
public static ConsolePanel console_panel { get; set; }
|
|
/// <summary>
|
|
/// 确认面板
|
|
/// </summary>
|
|
public static ConfirmPanel confirm_panel { get; set; }
|
|
/// <summary>
|
|
/// Api面板
|
|
/// </summary>
|
|
public static ApiPanel api_panel { get; set; }
|
|
/// <summary>
|
|
/// Api详情面板
|
|
/// </summary>
|
|
public static ApiDetailPanel api_detail_panel { get; set; }
|
|
/// <summary>
|
|
/// 目标
|
|
/// </summary>
|
|
public static ObjectivePanel objective_panel { get; set; }
|
|
/// <summary>
|
|
/// 媒体查看
|
|
/// </summary>
|
|
public static MediaViwerPanel media_viwer_panel { get; set; }
|
|
/// <summary>
|
|
/// 菜单面板
|
|
/// </summary>
|
|
public static MenuPanel menu_panel { get; set; }
|
|
/// <summary>
|
|
/// 媒体预览
|
|
/// </summary>
|
|
public static MediaPreviewPanel media_preview_panel { get; set; }
|
|
/// <summary>
|
|
/// 星火大模型
|
|
/// </summary>
|
|
public static SparkModelPanel spark_model_panel { get; set; }
|
|
/// <summary>
|
|
/// 摄像头画面面板
|
|
/// </summary>
|
|
public static WebcamControllerPanel webcam_panel { get; set; }
|
|
#endregion
|
|
/// <summary>
|
|
/// 面板列表
|
|
/// </summary>
|
|
public PanelBasic[] panel_list;
|
|
public delegate void ResetScene();
|
|
/// <summary>
|
|
/// 重置场景委托
|
|
/// </summary>
|
|
public static ResetScene on_reset_scene;
|
|
/// <summary>
|
|
/// ide设置按钮
|
|
/// </summary>
|
|
public Button IDEsettingbtn;
|
|
/// <summary>
|
|
/// buttonFunction脚本
|
|
/// </summary>
|
|
public buttonFunctionAdd button_Function;
|
|
/// <summary>
|
|
/// 返回主菜单功能
|
|
/// </summary>
|
|
public Button 返回主菜单;
|
|
/// <summary>
|
|
/// 返回主菜单取消功能
|
|
/// </summary>
|
|
public Button 返回主菜单取消功能;
|
|
/// <summary>
|
|
/// Ide设置脚本
|
|
/// </summary>
|
|
public IDEsettingPanel ide;
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
Instance = this;
|
|
panel_list = GetComponentsInChildren<PanelBasic>(true);
|
|
Array.ForEach(panel_list, _panel => _panel.Init_Awake());
|
|
//初始化ide配置面板
|
|
transform.Find("ide设置面板").GetComponent<IDEsettingPanel>().Init();
|
|
api_panel.Init(api_detail_panel);
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
返回主菜单取消功能.onClick.AddListener(()=>
|
|
{
|
|
返回主菜单取消功能.transform.parent.gameObject.SetActive(false);
|
|
});
|
|
返回主菜单.onClick.AddListener(OnBack);
|
|
back_button.onClick.AddListener(quit);
|
|
api_button.onClick.AddListener(OnApi);
|
|
objective_button.onClick.AddListener(OnObjective);
|
|
mini_mode_button.onClick.AddListener(OnMiniMode);
|
|
menu_button.onClick.AddListener(OnMenu);
|
|
spark_model_button.onClick.AddListener(OnSparkModel);
|
|
IDEsettingbtn.onClick.AddListener(()=>
|
|
{
|
|
//打开ide配置面板
|
|
transform.Find("ide设置面板").gameObject.SetActive(true);
|
|
});
|
|
webcam_panel.open_camera_msg += (_msg, _type) => { ConsolePanel.ConsoleOutput(_msg, _type); };
|
|
|
|
//显示ui面板
|
|
switch (GameManager.current_main_menu_type)
|
|
{
|
|
case MainMenuType.课程任务:
|
|
//根据类型:练习、作业、考核等分类(如有)进行详细控制
|
|
break;
|
|
case MainMenuType.案例中心:
|
|
//需要根据具体案例展示对应内容
|
|
task_panel.gameObject.SetActive(false);
|
|
break;
|
|
case MainMenuType.自由编程:
|
|
objective_button.gameObject.SetActive(false);
|
|
task_panel.gameObject.SetActive(false);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
//显示人员信息框
|
|
if (GameManager.Instance == null || !GameManager.is_login)
|
|
{
|
|
user_content.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
user_name_text.text = CallForTest.instance.user.nickName;
|
|
if (!string.IsNullOrEmpty(CallForTest.instance.user.avatar))
|
|
{
|
|
StartCoroutine(InterfaceManager.GetSprite(CallForTest.instance.user.avatar,(_sprite)=>
|
|
{
|
|
user_avatar.sprite = _sprite;
|
|
}));
|
|
}
|
|
}
|
|
|
|
//左上角数据展示
|
|
part_name_text.text = GameManager.part_name;
|
|
//场景名称
|
|
//if (GameManager.scene_name == "深圳市民中心")
|
|
//{
|
|
// scene_name_text.text = "广场1";
|
|
//}
|
|
//else if (GameManager.scene_name == "西丽湖校区")
|
|
//{
|
|
// scene_name_text.text = "广场2";
|
|
//}
|
|
//else
|
|
{
|
|
scene_name_text.text = GameManager.scene_name;
|
|
}
|
|
|
|
pattern_name_text.text = GameManager.parttern_name;
|
|
}
|
|
|
|
private ConsoleItem currentConsoleItem_download;
|
|
private UnityWebRequest currentRequest_download;
|
|
private ConsoleItem currentConsoleItem_upload;
|
|
private UnityWebRequest currentRequest_upload;
|
|
private void Update()
|
|
{
|
|
//下载进度
|
|
if (currentRequest_download != null && currentConsoleItem_download != null)
|
|
{
|
|
currentConsoleItem_download.text_mesh_pro.text = "下载中:"+(currentRequest_download.downloadProgress*100).ToString() + "%";
|
|
}
|
|
|
|
//上传进度
|
|
if (currentRequest_upload != null && currentConsoleItem_upload != null)
|
|
{
|
|
currentConsoleItem_upload.text_mesh_pro.text = "上传中:" + (currentRequest_upload.uploadProgress * 100).ToString() + "%";
|
|
}
|
|
|
|
#region Shortcut keys
|
|
|
|
if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)))
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.F)&&(!Input.GetKey(KeyCode.LeftShift) &&!Input.GetKey(KeyCode.RightShift)))
|
|
{
|
|
|
|
if (!menu_panel.isCapture)
|
|
{
|
|
menu_panel.StartVideoRecord();
|
|
menu_panel.UI_录.SetActive(true);
|
|
menu_panel.UI_主.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
menu_panel.StopVideoRecord();
|
|
menu_panel.UI_录.SetActive(false);
|
|
menu_panel.UI_主.SetActive(true);
|
|
}
|
|
}
|
|
else if (Input.GetKeyDown(KeyCode.M))//浏览媒体
|
|
{
|
|
media_viwer_panel.OnPopup();
|
|
}
|
|
else if (Input.GetKeyDown(KeyCode.I))//导入媒体
|
|
{
|
|
menu_panel.OnImportMedia();
|
|
}
|
|
else if (Input.GetKeyDown(KeyCode.T))//重置场景
|
|
{
|
|
button_Function.ChangePicture(2);
|
|
button_Function.seset_();
|
|
button_Function.Function_打开重置菜单();
|
|
}
|
|
else if ((Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt)) && Input.GetKeyDown(KeyCode.S))
|
|
{
|
|
}
|
|
else if ((Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) && Input.GetKeyDown(KeyCode.F))
|
|
{
|
|
//功能只会在课程任务模式下触发
|
|
if (GameManager.current_main_menu_type == MainMenuType.课程任务 &&WebSocketServerManager.Instance.number == 0)
|
|
{
|
|
button_Function.ChangePicture(7);
|
|
button_Function.seset_();
|
|
button_Function.Function_确认提交云端代码菜单();
|
|
}
|
|
}
|
|
else if (Input.GetKeyDown(KeyCode.S))
|
|
{
|
|
//功能只会在课程任务模式下触发
|
|
if (GameManager.current_main_menu_type == MainMenuType.课程任务 && WebSocketServerManager.Instance.number == 0)
|
|
{
|
|
//添加打开暂存菜单的功能
|
|
button_Function.ChangePicture(4);
|
|
button_Function.seset_();
|
|
button_Function.Function_确认暂存代码到云端菜单();
|
|
}
|
|
}
|
|
else if (Input.GetKeyDown(KeyCode.D))
|
|
{
|
|
//功能只会在课程任务模式下触发
|
|
if (GameManager.current_main_menu_type == MainMenuType.课程任务 && WebSocketServerManager.Instance.number == 0)
|
|
{
|
|
//添加打开读取菜单的功能
|
|
button_Function.ChangePicture(5);
|
|
button_Function.seset_();
|
|
button_Function.Function_确认读取云端代码菜单();
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置下载进度条
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="request"></param>
|
|
public void Set_DownLoad_Process(ConsoleItem item, UnityWebRequest request)
|
|
{
|
|
Debug.Log("设置下载进度");
|
|
currentConsoleItem_download = item;
|
|
currentRequest_download = request;
|
|
}
|
|
/// <summary>
|
|
/// 移除下载进度条
|
|
/// </summary>
|
|
public void Remove_DownLoad_Process()
|
|
{
|
|
Debug.Log("移除下载进度");
|
|
currentConsoleItem_download = null;
|
|
currentRequest_download = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置上传进度条
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="request"></param>
|
|
public void Set_UpLoad_Process(ConsoleItem item, UnityWebRequest request)
|
|
{
|
|
Debug.Log("设置上传进度");
|
|
currentConsoleItem_upload = item;
|
|
currentRequest_upload = request;
|
|
}
|
|
/// <summary>
|
|
/// 移除上传进度条
|
|
/// </summary>
|
|
public void Remove_UpLoad_Process()
|
|
{
|
|
Debug.Log("移除上传进度");
|
|
currentConsoleItem_upload = null;
|
|
currentRequest_upload = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 截图
|
|
/// </summary>
|
|
/// <param name="filePath"></param>
|
|
public void ScreemShot(string filePath)
|
|
{
|
|
if (GameManager.current_main_menu_type == MainMenuType.课程任务)
|
|
{
|
|
string name=Path.GetFileName(filePath);
|
|
if (name != "任务.png")
|
|
{
|
|
//检查是否有该步骤
|
|
var tmp=task_panel.task_item_data.task_steplist.Find(a => "步骤_" + a.stepName+".png"== name);
|
|
if(tmp==null)
|
|
{
|
|
|
|
ConsolePanel.ConsoleOutput("不存在此步骤:"+ name.Replace(".png",""), "error");
|
|
return;
|
|
}
|
|
}
|
|
|
|
ConsolePanel.ConsoleOutput(Path.GetFileName(filePath), "log");
|
|
ScreenCapture.CaptureScreenshot(filePath);
|
|
}
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
|
|
}
|
|
/// <summary>
|
|
/// 返回登录场景
|
|
/// </summary>
|
|
public void OnBack()
|
|
{
|
|
ide.kill();
|
|
if (menu_panel.isCapture)
|
|
menu_panel.StopVideoRecord();
|
|
SceneManager.LoadScene("LoginScene");
|
|
}
|
|
/// <summary>
|
|
/// 退出场景
|
|
/// </summary>
|
|
public void quit()
|
|
{
|
|
if (menu_panel.isCapture)
|
|
menu_panel.StopVideoRecord();
|
|
Application.Quit();
|
|
}
|
|
/// <summary>
|
|
/// 开关API面板
|
|
/// </summary>
|
|
public void OnApi()
|
|
{
|
|
api_panel.OnSwitch();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开关目标面板
|
|
/// </summary>
|
|
public void OnObjective()
|
|
{
|
|
objective_panel.OnActive();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 切换迷你模式
|
|
/// </summary>
|
|
public void OnMiniMode()
|
|
{
|
|
//切换分辨率
|
|
WindowManager.Instance.SwitchResolution(WindowManager.ScreenResolution.MINI_SCREEN);
|
|
}
|
|
|
|
//切换窗口模式
|
|
public void OnMax()
|
|
{
|
|
WindowManager.Instance.SwitchResolution(WindowManager.ScreenResolution.MAX_SCREEN);
|
|
//切换回大窗口后取消置顶状态
|
|
WindowManager.Instance.Topping(false);
|
|
}
|
|
|
|
private void OnMenu()
|
|
{
|
|
menu_panel.OnSwitch();
|
|
}
|
|
|
|
private void OnSparkModel()
|
|
{
|
|
spark_model_panel.OnSwitch();
|
|
}
|
|
}
|