using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; using TMPro; using UnityEngine.EventSystems; using UnityEditor; using UnityEngine.Networking; using System.IO; public class MainCanvasManager : PanelBasic { public static MainCanvasManager Instance; /// /// 退出场景 /// public Button back_button; /// /// 查看api /// public Button api_button; /// /// 目标 /// public Button objective_button; /// /// 小窗模式 /// public Button mini_mode_button; /// /// 菜单按钮 /// public Button menu_button; /// /// 星火大模型按钮 /// public Button spark_model_button; /// /// 组件名 /// public TextMeshProUGUI part_name_text; /// /// 场景名称 /// public TextMeshProUGUI scene_name_text; /// /// 模式名称 /// public TextMeshProUGUI pattern_name_text; /// /// 用户信息容器 /// public Image user_content; /// /// 用户头像 /// public Image user_avatar; /// /// 用户名 /// public TextMeshProUGUI user_name_text; public static RectTransform MainCanvas; #region Panels /// /// 任务步骤面板 /// public static TaskPanel task_panel { get; set; } /// /// 任务详情面板 /// public static TaskDetailPanel task_detail_panel { get; set; } /// /// 控制台面板 /// public static ConsolePanel console_panel { get; set; } /// /// 确认面板 /// public static ConfirmPanel confirm_panel { get; set; } /// /// Api面板 /// public static ApiPanel api_panel { get; set; } /// /// Api详情面板 /// public static ApiDetailPanel api_detail_panel { get; set; } /// /// 目标 /// public static ObjectivePanel objective_panel { get; set; } /// /// 媒体查看 /// public static MediaViwerPanel media_viwer_panel { get; set; } /// /// 菜单面板 /// public static MenuPanel menu_panel { get; set; } /// /// 媒体预览 /// public static MediaPreviewPanel media_preview_panel { get; set; } /// /// 星火大模型 /// public static SparkModelPanel spark_model_panel { get; set; } /// /// 摄像头画面面板 /// public static WebcamControllerPanel webcam_panel { get; set; } #endregion /// /// 面板列表 /// public PanelBasic[] panel_list; public delegate void ResetScene(); /// /// 重置场景委托 /// public static ResetScene on_reset_scene; /// /// ide设置按钮 /// public Button IDEsettingbtn; protected override void Awake() { base.Awake(); Instance = this; panel_list = GetComponentsInChildren(true); Array.ForEach(panel_list, _panel => _panel.Init_Awake()); //初始化ide配置面板 transform.Find("ide设置面板").GetComponent().Init(); api_panel.Init(api_detail_panel); } // Start is called before the first frame update void Start() { back_button.onClick.AddListener(OnBack); 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)) { if (!menu_panel.isCapture) menu_panel.StartVideoRecord(); else menu_panel.StopVideoRecord(); } else if (Input.GetKeyDown(KeyCode.M))//浏览媒体 { media_viwer_panel.OnPopup(); } else if (Input.GetKeyDown(KeyCode.I))//导入媒体 { menu_panel.OnImportMedia(); } else if (Input.GetKeyDown(KeyCode.R))//重置场景 { menu_panel.OnResetScene(); } 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)) { } else if (Input.GetKey(KeyCode.S)) { } else if (Input.GetKeyDown(KeyCode.D)) { } } #endregion } /// /// 设置下载进度条 /// /// /// public void Set_DownLoad_Process(ConsoleItem item, UnityWebRequest request) { Debug.Log("设置下载进度"); currentConsoleItem_download = item; currentRequest_download = request; } /// /// 移除下载进度条 /// public void Remove_DownLoad_Process() { Debug.Log("移除下载进度"); currentConsoleItem_download = null; currentRequest_download = null; } /// /// 设置上传进度条 /// /// /// public void Set_UpLoad_Process(ConsoleItem item, UnityWebRequest request) { Debug.Log("设置上传进度"); currentConsoleItem_upload = item; currentRequest_upload = request; } /// /// 移除上传进度条 /// public void Remove_UpLoad_Process() { Debug.Log("移除上传进度"); currentConsoleItem_upload = null; currentRequest_upload = null; } /// /// 截图 /// /// 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() { } /// /// 返回登录场景 /// public void OnBack() { if (menu_panel.isCapture) menu_panel.StopVideoRecord(); SceneManager.LoadScene("LoginScene"); } /// /// 开关API面板 /// public void OnApi() { api_panel.OnSwitch(); } /// /// 开关目标面板 /// public void OnObjective() { objective_panel.OnActive(); } /// /// 切换迷你模式 /// public void OnMiniMode() { //切换分辨率 WindowManager.Instance.SwitchResolution(WindowManager.ScreenResolution.MINI_SCREEN); } private void OnMenu() { menu_panel.OnSwitch(); } private void OnSparkModel() { spark_model_panel.OnSwitch(); } }