diff --git a/Assets/Scripts/Bootstrap.cs b/Assets/Scripts/Bootstrap.cs index 8d9f005..aa381ef 100644 --- a/Assets/Scripts/Bootstrap.cs +++ b/Assets/Scripts/Bootstrap.cs @@ -17,37 +17,37 @@ public class Bootstrap : SingletonMono base.Awake(); uiManager = new UIManager(); eventCenter = new EventCenter(); - scenesManager = new ScenesManager(); + scenesManager = new ScenesManager(this); pptFolderName = Application.streamingAssetsPath + "/PPT"; - LoadPPTTest.PPTFiles(pptFolderName); - ppts = LoadPPTTest.PPTName(); DontDestroyOnLoad(gameObject); } private void Start() { - eventCenter.EventTrigger(Enum_EventType.UpdateProgress, 0.1f); - scenesManager.LoadSceneAsyn(this, "MenuScene", () => + uiManager.ShowPanel(this, E_UI_Layer.System, (panel) => { - uiManager.ShowPanel(this, E_UI_Layer.Bot, (panel) => + eventCenter.EventTrigger(Enum_EventType.UpdateProgress, 0.1f); + scenesManager.LoadSceneAsyn("MenuScene", () => { - uiManager.ShowPanel(this, E_UI_Layer.Top, (panel) => + uiManager.ShowPanel(this, E_UI_Layer.Bot, (panel) => { - Debug.Log("UI_SelectModePanel"); + //LoadPPTTest.PPTFiles(pptFolderName); + uiManager.ShowPanel(this, E_UI_Layer.Top, (panel) => + { + ppts = LoadPPTTest.PPTName(); + Debug.Log("UI_SelectModePanel"); + }); }); + eventCenter.EventTrigger(Enum_EventType.UpdateProgress, 2f); }); - eventCenter.EventTrigger(Enum_EventType.UpdateProgress, 0.9f); - }); - //uiManager.ShowPanel(this, E_UI_Layer.System, (panel) => - //{ - - //}); + + }); } // Update is called once per frame void Update() { - + } } diff --git a/Assets/Scripts/Project/ProjectBase/ScenesManager.cs b/Assets/Scripts/Project/ProjectBase/ScenesManager.cs index be5d06b..0ba588b 100644 --- a/Assets/Scripts/Project/ProjectBase/ScenesManager.cs +++ b/Assets/Scripts/Project/ProjectBase/ScenesManager.cs @@ -6,7 +6,11 @@ using UnityEngine.SceneManagement; public class ScenesManager { - public ScenesManager() { } + private MonoBehaviour _target; + public ScenesManager(MonoBehaviour target) + { + _target = target; + } /// /// 同步加载场景 /// @@ -25,11 +29,9 @@ public class ScenesManager /// 场景名称 /// 委托 /// 加载场景方式 - public void LoadSceneAsyn(MonoBehaviour taget, string sceneName, UnityAction action = null, - LoadSceneMode loadSceneMode = LoadSceneMode.Single) + public void LoadSceneAsyn(string sceneName, UnityAction action = null) { - Debug.Log("LoadSceneAsyn"); - taget.StartCoroutine(ReallyLoadScene(sceneName, action)); + _target.StartCoroutine(ReallyLoadScene(sceneName, action)); } /// @@ -43,8 +45,7 @@ public class ScenesManager LoadSceneMode loadSceneMode = LoadSceneMode.Single) { AsyncOperation ao = SceneManager.LoadSceneAsync(sceneName, loadSceneMode); + yield return ao; action?.Invoke(); - yield return ao.isDone; - } } \ No newline at end of file diff --git a/Assets/Scripts/Test/LoadPPTTest.cs b/Assets/Scripts/Test/LoadPPTTest.cs index 3326ad9..bd36edc 100644 --- a/Assets/Scripts/Test/LoadPPTTest.cs +++ b/Assets/Scripts/Test/LoadPPTTest.cs @@ -14,6 +14,7 @@ using UnityEngine.UI; public static class LoadPPTTest { + /// /// /// @@ -29,34 +30,27 @@ public static class LoadPPTTest /// public static List LoadPPTItems(string pptName) { - string pptPath = GetPPTPathByName(pptName); return GetTexture2DsByName(pptName, pptPath); //target.StartCoroutine(LoadAllPPTFiles(pptPath)); } + public static string[] PPTName() { ///切割pptsPath return pptsPath; } + private static List GetTexture2DsByName(string pptName, string pptPath) - { - if (!texturesDic.ContainsKey(pptName)) + { + foreach (var item in texturesDic.Keys) { - texturesDic.Add(pptName, LoadAllPPTFiles(pptPath)); - return LoadAllPPTFiles(pptPath); + if (item.Equals(pptName)) + return texturesDic[item]; } - else - { - foreach (var item in texturesDic.Keys) - { - if (item.Equals(pptName)) - return texturesDic[item]; - } - } return null; } /// @@ -78,42 +72,75 @@ public static class LoadPPTTest /// 获取文件夹下所有.pptx文件 /// /// - public static void PPTFiles(string folderPath) + public static async void PPTFiles(string folderPath) { string fullPPTFolderPath = Path.Combine(Application.streamingAssetsPath, folderPath); pptsPath = Directory.GetFiles(fullPPTFolderPath, "*.pptx"); + for (int i = 0; i < pptsPath.Length; i++) + { + string pptName = PathName(pptsPath[i]); + await LoadAllPPTFiles(pptName, pptsPath[i]); + } } - public static List LoadAllPPTFiles(string folderPath) + + public static async UniTask LoadAllPPTFiles(string pptName, string folderPath) { List texture2Ds = new List(); - Presentation presentation = new Aspose.Slides.Presentation(folderPath); - + Presentation presentation = new Presentation(folderPath); // 遍历文档(只做示例使用自己根据需求拓展) for (int i = 0; i < presentation.Slides.Count; i++) { ISlide slide = presentation.Slides[i]; var bitmap = slide.GetThumbnail(1f, 1f); - // 声明内存流,将图片转换为内存流,再由流转换为byte数组,然后用texture2d加载byte数组 using (MemoryStream ms = new MemoryStream()) { bitmap.Save(ms, ImageFormat.Jpeg); byte[] buff = new byte[ms.Length]; ms.Seek(0, SeekOrigin.Begin); - ms.Read(buff, 0, (int)ms.Length); - + await ms.ReadAsync(buff, 0, (int)ms.Length); // 注意这个image的命名空间为system.drawing不是unity.ui,这个图片的目的是提供图片的宽高 System.Drawing.Image sizeImage = System.Drawing.Image.FromStream(ms); - Texture2D texture2D = new Texture2D(sizeImage.Width, sizeImage.Height); texture2D.LoadImage(buff); texture2Ds.Add(texture2D); } } + texturesDic.Add(pptName, texture2Ds); Debug.Log("所有PPT加载完成!"); - return texture2Ds; } + + //public static List LoadAllPPTFiles(string folderPath) + //{ + // List texture2Ds = new List(); + // Presentation presentation = new Presentation(folderPath); + + // // 遍历文档(只做示例使用自己根据需求拓展) + // for (int i = 0; i < presentation.Slides.Count; i++) + // { + // ISlide slide = presentation.Slides[i]; + // var bitmap = slide.GetThumbnail(1f, 1f); + + // // 声明内存流,将图片转换为内存流,再由流转换为byte数组,然后用texture2d加载byte数组 + // using (MemoryStream ms = new MemoryStream()) + // { + // bitmap.Save(ms, ImageFormat.Jpeg); + // byte[] buff = new byte[ms.Length]; + // ms.Seek(0, SeekOrigin.Begin); + // ms.Read(buff, 0, (int)ms.Length); + + // // 注意这个image的命名空间为system.drawing不是unity.ui,这个图片的目的是提供图片的宽高 + // System.Drawing.Image sizeImage = System.Drawing.Image.FromStream(ms); + + // Texture2D texture2D = new Texture2D(sizeImage.Width, sizeImage.Height); + // texture2D.LoadImage(buff); + // texture2Ds.Add(texture2D); + // } + // } + // Debug.Log("所有PPT加载完成!"); + // return texture2Ds; + //} // 逐个加载每个PPT文件 /// @@ -137,7 +164,7 @@ public static class LoadPPTTest /// /// 从文件名中提取开头的数字(如 "1-第一章" -> 返回 1) /// - public static int ExtractLeadingNumber(string fileName) + public static int ExtractLeadingNumber(string fileName) { if (string.IsNullOrEmpty(fileName)) return 0; diff --git a/Assets/Scripts/TestScene1Manager.cs b/Assets/Scripts/TestScene1Manager.cs index 5b01d0e..14f7534 100644 --- a/Assets/Scripts/TestScene1Manager.cs +++ b/Assets/Scripts/TestScene1Manager.cs @@ -19,7 +19,7 @@ public class TestScene1Manager : MonoBehaviour Bootstrap.Instance.uiManager.ShowPanel(this, E_UI_Layer.System, (panel) => { Bootstrap.Instance.eventCenter.EventTrigger(Enum_EventType.UpdateProgress, 0.1f); - Bootstrap.Instance.scenesManager.LoadSceneAsyn(this, "TestScene", () => + Bootstrap.Instance.scenesManager.LoadSceneAsyn("TestScene", () => { Debug.Log("سɹ"); Bootstrap.Instance.eventCenter.EventTrigger(Enum_EventType.UpdateProgress, 0.9f); diff --git a/Assets/Scripts/TestSceneManager.cs b/Assets/Scripts/TestSceneManager.cs index b03a327..6da7493 100644 --- a/Assets/Scripts/TestSceneManager.cs +++ b/Assets/Scripts/TestSceneManager.cs @@ -20,7 +20,7 @@ public class TestSceneManager : MonoBehaviour Bootstrap.Instance.uiManager.ShowPanel(this, E_UI_Layer.System, (panel) => { Bootstrap.Instance.eventCenter.EventTrigger(Enum_EventType.UpdateProgress, 0.1f); - Bootstrap.Instance.scenesManager.LoadSceneAsyn(this, "TestScene1", () => + Bootstrap.Instance.scenesManager.LoadSceneAsyn("TestScene1", () => { Debug.Log("سɹ"); Bootstrap.Instance.eventCenter.EventTrigger(Enum_EventType.UpdateProgress, 0.9f); diff --git a/Assets/Scripts/UI/UIPanel/UI_ExamPanel.cs b/Assets/Scripts/UI/UIPanel/UI_ExamPanel.cs index 022d14d..7c11f6c 100644 --- a/Assets/Scripts/UI/UIPanel/UI_ExamPanel.cs +++ b/Assets/Scripts/UI/UIPanel/UI_ExamPanel.cs @@ -170,7 +170,7 @@ public class UI_ExamPanel : BasePanel switch (btnName) { case "retrun_Btn": - Bootstrap.Instance.scenesManager.LoadSceneAsyn(this, "MenuScene", () => + Bootstrap.Instance.scenesManager.LoadSceneAsyn( "MenuScene", () => { Bootstrap.Instance.uiManager.ShowPanel(this, E_UI_Layer.Top, (panel) => { diff --git a/Assets/Scripts/UI/UIPanel/UI_LoadingPanel.cs b/Assets/Scripts/UI/UIPanel/UI_LoadingPanel.cs index 8f3f934..5712105 100644 --- a/Assets/Scripts/UI/UIPanel/UI_LoadingPanel.cs +++ b/Assets/Scripts/UI/UIPanel/UI_LoadingPanel.cs @@ -1,6 +1,5 @@ using System.Collections; using System.Collections.Generic; -using TMPro; using UnityEngine; using UnityEngine.UI; @@ -9,82 +8,52 @@ public class UI_LoadingPanel : BasePanel public Slider loadSlider; private float currentProgress = 0; - public float targetProgress; + public float speed; public bool isLoading = false; - public TextMeshProUGUI Slider_Text; - - public Sprite[] frames; // ÿһ֡SpriteͼƬ - public float frameRate = 30f; // ÿ벥ŵ֡ - private Image image; protected override void Awake() { base.Awake(); loadSlider = GetControl("loadSlider"); - Slider_Text = GetControl("%"); - - image = GetControl("middleImage"); - if (image == null) - { - Debug.LogError("Image component not found!"); - } - - StartCoroutine(Animate()); } public override void ShowMe() { base.ShowMe(); - loadSlider.value = 0; - Slider_Text.text = "0%"; - Debug.Log("UI_LoadingPanel ShowMe"); Bootstrap.Instance.eventCenter.AddEventListener(Enum_EventType.UpdateProgress, UpdateProgress); - + } public override void HideMe() { base.HideMe(); - Debug.Log("UI_LoadingPanel HideMe"); + loadSlider.value = 0; + currentProgress = 0; + speed = 0; Bootstrap.Instance.eventCenter.RemoveEventListener(Enum_EventType.UpdateProgress, UpdateProgress); - + } private void Update() { if (isLoading) { - if (currentProgress < targetProgress) + if (currentProgress < 0.98f) { - currentProgress += Time.deltaTime; - if (currentProgress >= targetProgress) - currentProgress = targetProgress; + currentProgress += Time.deltaTime * speed; loadSlider.value = currentProgress; - // Slidervalue0~1תΪٷֱȣ0%~100% - float percent = loadSlider.value * 100f; - Slider_Text.text = Mathf.RoundToInt(percent) + "%"; } else { isLoading = false; - Bootstrap.Instance.uiManager.HidePanel(); + HideMe(); } } } - private void UpdateProgress(float progress) + private void UpdateProgress(float speed) { isLoading = true; - targetProgress += progress; - } - private IEnumerator Animate() - { - for (int i = 0; i < frames.Length; i++) - { - image.sprite = frames[i]; - yield return new WaitForSeconds(1f / frameRate); - } - // ѭŵĴ룬ضֹͣ - StartCoroutine(Animate()); // ѭ + this.speed = speed; } } diff --git a/Assets/Scripts/UI/UIPanel/UI_SelectModePanel.cs b/Assets/Scripts/UI/UIPanel/UI_SelectModePanel.cs index e24fda1..20d386a 100644 --- a/Assets/Scripts/UI/UIPanel/UI_SelectModePanel.cs +++ b/Assets/Scripts/UI/UIPanel/UI_SelectModePanel.cs @@ -27,7 +27,7 @@ public class UI_SelectModePanel : BasePanel Bootstrap.Instance.uiManager.HidePanel(); Bootstrap.Instance.uiManager.HidePanel(); }); - + }); //Bootstrap.Instance.uiManager.HidePanel(); break; @@ -36,7 +36,7 @@ public class UI_SelectModePanel : BasePanel Bootstrap.Instance.eventCenter.EventTrigger(Enum_EventType.UpdateProgress, 0.1f); Bootstrap.Instance.uiManager.ShowPanel(this, E_UI_Layer.System, (panel) => { - Bootstrap.Instance.scenesManager.LoadSceneAsyn(this, "ۿ", () => + Bootstrap.Instance.scenesManager.LoadSceneAsyn("ۿ", () => { Bootstrap.Instance.uiManager.ShowPanel(this, E_UI_Layer.Bot, (panel) => { @@ -57,7 +57,7 @@ public class UI_SelectModePanel : BasePanel Bootstrap.Instance.eventCenter.EventTrigger(Enum_EventType.UpdateProgress, 0.1f); Bootstrap.Instance.uiManager.ShowPanel(this, E_UI_Layer.System, (panel) => { - Bootstrap.Instance.scenesManager.LoadSceneAsyn(this, "LiveScene", () => + Bootstrap.Instance.scenesManager.LoadSceneAsyn("LiveScene", () => { Bootstrap.Instance.uiManager.ShowPanel(this, E_UI_Layer.Bot, (panel) => { @@ -73,7 +73,7 @@ public class UI_SelectModePanel : BasePanel }); //Bootstrap.Instance.uiManager.HidePanel(); - + break; } } diff --git a/Assets/Scripts/UI/UIPanel/UI_StepsPanel.cs b/Assets/Scripts/UI/UIPanel/UI_StepsPanel.cs index b3ae43d..f63277f 100644 --- a/Assets/Scripts/UI/UIPanel/UI_StepsPanel.cs +++ b/Assets/Scripts/UI/UIPanel/UI_StepsPanel.cs @@ -75,7 +75,7 @@ public class UI_StepsPanel : BasePanel switch (btnName) { case "retrun_Btn": - Bootstrap.Instance.scenesManager.LoadSceneAsyn(this, "MenuScene", () => + Bootstrap.Instance.scenesManager.LoadSceneAsyn( "MenuScene", () => { Bootstrap.Instance.uiManager.ShowPanel(this, E_UI_Layer.Top, (panel) => { diff --git a/Assets/Scripts/UI/UIPanel/UI_TipsForPracticePanel.cs b/Assets/Scripts/UI/UIPanel/UI_TipsForPracticePanel.cs index d2c78d5..bcb0aaf 100644 --- a/Assets/Scripts/UI/UIPanel/UI_TipsForPracticePanel.cs +++ b/Assets/Scripts/UI/UIPanel/UI_TipsForPracticePanel.cs @@ -49,6 +49,8 @@ public class UI_TipsForPracticePanel : BasePanel public override void ShowMe() { base.ShowMe(); + string pptBtnName = Left_content.GetChild(0).GetComponent().PPTName_Btn.gameObject.name; + OnClick(pptBtnName); } public override void HideMe() { diff --git a/UserSettings/EditorUserSettings.asset b/UserSettings/EditorUserSettings.asset index da370ff..40790ce 100644 --- a/UserSettings/EditorUserSettings.asset +++ b/UserSettings/EditorUserSettings.asset @@ -6,28 +6,28 @@ EditorUserSettings: serializedVersion: 4 m_ConfigSettings: RecentlyUsedSceneGuid-0: - value: 5452075006075b5f540c5c77497706444f4e4d2b2d7e27677d2b4b30b5b8316d - flags: 0 - RecentlyUsedSceneGuid-1: value: 5006505e5c0c0a5e0e0b5a2746220b44174e1d292d7b74617c2b196be0b66168 flags: 0 - RecentlyUsedSceneGuid-2: + RecentlyUsedSceneGuid-1: value: 5754060550000c5e59580a2348270d44434e1b782a7b7633747e1e30e4b5616b flags: 0 - RecentlyUsedSceneGuid-3: + RecentlyUsedSceneGuid-2: value: 0609045307065a5d5a0d0874407b5944124f1e72787b2465287e1f36b0b8316f flags: 0 - RecentlyUsedSceneGuid-4: + RecentlyUsedSceneGuid-3: value: 55085253045108025c56097646265e44124f4f7b7e7a76312c2f4960e6b1363d flags: 0 - RecentlyUsedSceneGuid-5: + RecentlyUsedSceneGuid-4: value: 0004025352565f0d0c0d5827167b09444f4f1c282a7877677b704536b6b36c6d flags: 0 + RecentlyUsedSceneGuid-5: + value: 5400065054540b095f0b5c7511255b4447151e787a2b253628794c37e7b6676e + flags: 0 RecentlyUsedSceneGuid-6: - value: 5a5757560101590a5d0c0e24427b5d44434e4c7a7b7a23677f2b4565b7b5353a + value: 5452075006075b5f540c5c77497706444f4e4d2b2d7e27677d2b4b30b5b8316d flags: 0 RecentlyUsedSceneGuid-7: - value: 5400065054540b095f0b5c7511255b4447151e787a2b253628794c37e7b6676e + value: 5a5757560101590a5d0c0e24427b5d44434e4c7a7b7a23677f2b4565b7b5353a flags: 0 vcSharedLogLevel: value: 0d5e400f0650