修改加载PPT逻辑
This commit is contained in:
parent
c9f5e2e308
commit
6b0384849a
|
@ -17,32 +17,32 @@ public class Bootstrap : SingletonMono<Bootstrap>
|
|||
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()
|
||||
{
|
||||
uiManager.ShowPanel<UI_LoadingPanel>(this, E_UI_Layer.System, (panel) =>
|
||||
{
|
||||
eventCenter.EventTrigger(Enum_EventType.UpdateProgress, 0.1f);
|
||||
scenesManager.LoadSceneAsyn(this, "MenuScene", () =>
|
||||
scenesManager.LoadSceneAsyn("MenuScene", () =>
|
||||
{
|
||||
uiManager.ShowPanel<UI_BGPanel>(this, E_UI_Layer.Bot, (panel) =>
|
||||
{
|
||||
//LoadPPTTest.PPTFiles(pptFolderName);
|
||||
uiManager.ShowPanel<UI_SelectModePanel>(this, E_UI_Layer.Top, (panel) =>
|
||||
{
|
||||
ppts = LoadPPTTest.PPTName();
|
||||
Debug.Log("UI_SelectModePanel");
|
||||
});
|
||||
});
|
||||
eventCenter.EventTrigger(Enum_EventType.UpdateProgress, 0.9f);
|
||||
eventCenter.EventTrigger(Enum_EventType.UpdateProgress, 2f);
|
||||
});
|
||||
|
||||
//uiManager.ShowPanel<UI_LoadingPanel>(this, E_UI_Layer.System, (panel) =>
|
||||
//{
|
||||
|
||||
//});
|
||||
});
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
|
|
|
@ -6,7 +6,11 @@ using UnityEngine.SceneManagement;
|
|||
|
||||
public class ScenesManager
|
||||
{
|
||||
public ScenesManager() { }
|
||||
private MonoBehaviour _target;
|
||||
public ScenesManager(MonoBehaviour target)
|
||||
{
|
||||
_target = target;
|
||||
}
|
||||
/// <summary>
|
||||
/// 同步加载场景
|
||||
/// </summary>
|
||||
|
@ -25,11 +29,9 @@ public class ScenesManager
|
|||
/// <param name="sceneName">场景名称</param>
|
||||
/// <param name="action">委托</param>
|
||||
/// <param name="loadSceneMode">加载场景方式</param>
|
||||
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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@ using UnityEngine.UI;
|
|||
|
||||
public static class LoadPPTTest
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
@ -29,34 +30,27 @@ public static class LoadPPTTest
|
|||
/// <returns></returns>
|
||||
public static List<Texture2D> 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<Texture2D> GetTexture2DsByName(string pptName, string pptPath)
|
||||
{
|
||||
if (!texturesDic.ContainsKey(pptName))
|
||||
{
|
||||
texturesDic.Add(pptName, LoadAllPPTFiles(pptPath));
|
||||
return LoadAllPPTFiles(pptPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var item in texturesDic.Keys)
|
||||
{
|
||||
if (item.Equals(pptName))
|
||||
return texturesDic[item];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -78,42 +72,75 @@ public static class LoadPPTTest
|
|||
/// 获取文件夹下所有.pptx文件
|
||||
/// </summary>
|
||||
/// <param name="folderPath"></param>
|
||||
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<Texture2D> LoadAllPPTFiles(string folderPath)
|
||||
|
||||
public static async UniTask LoadAllPPTFiles(string pptName, string folderPath)
|
||||
{
|
||||
List<Texture2D> texture2Ds = new List<Texture2D>();
|
||||
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<Texture2D> LoadAllPPTFiles(string folderPath)
|
||||
//{
|
||||
// List<Texture2D> texture2Ds = new List<Texture2D>();
|
||||
// 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文件
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -19,7 +19,7 @@ public class TestScene1Manager : MonoBehaviour
|
|||
Bootstrap.Instance.uiManager.ShowPanel<UI_LoadingPanel>(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);
|
||||
|
|
|
@ -20,7 +20,7 @@ public class TestSceneManager : MonoBehaviour
|
|||
Bootstrap.Instance.uiManager.ShowPanel<UI_LoadingPanel>(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);
|
||||
|
|
|
@ -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<UI_SelectModePanel>(this, E_UI_Layer.Top, (panel) =>
|
||||
{
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
@ -9,34 +8,17 @@ 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<Slider>("loadSlider");
|
||||
Slider_Text = GetControl<TextMeshProUGUI>("%");
|
||||
|
||||
image = GetControl<Image>("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<float>(Enum_EventType.UpdateProgress, UpdateProgress);
|
||||
|
||||
}
|
||||
|
@ -44,7 +26,9 @@ public class UI_LoadingPanel : BasePanel
|
|||
public override void HideMe()
|
||||
{
|
||||
base.HideMe();
|
||||
Debug.Log("UI_LoadingPanel HideMe");
|
||||
loadSlider.value = 0;
|
||||
currentProgress = 0;
|
||||
speed = 0;
|
||||
Bootstrap.Instance.eventCenter.RemoveEventListener<float>(Enum_EventType.UpdateProgress, UpdateProgress);
|
||||
|
||||
}
|
||||
|
@ -53,38 +37,23 @@ public class UI_LoadingPanel : BasePanel
|
|||
{
|
||||
if (isLoading)
|
||||
{
|
||||
if (currentProgress < targetProgress)
|
||||
if (currentProgress < 0.98f)
|
||||
{
|
||||
currentProgress += Time.deltaTime;
|
||||
if (currentProgress >= targetProgress)
|
||||
currentProgress = targetProgress;
|
||||
currentProgress += Time.deltaTime * speed;
|
||||
loadSlider.value = currentProgress;
|
||||
// 将Slider的value(0~1)转为百分比(0%~100%)
|
||||
float percent = loadSlider.value * 100f;
|
||||
Slider_Text.text = Mathf.RoundToInt(percent) + "%";
|
||||
}
|
||||
else
|
||||
{
|
||||
isLoading = false;
|
||||
Bootstrap.Instance.uiManager.HidePanel<UI_LoadingPanel>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ public class UI_SelectModePanel : BasePanel
|
|||
Bootstrap.Instance.eventCenter.EventTrigger(Enum_EventType.UpdateProgress, 0.1f);
|
||||
Bootstrap.Instance.uiManager.ShowPanel<UI_LoadingPanel>(this, E_UI_Layer.System, (panel) =>
|
||||
{
|
||||
Bootstrap.Instance.scenesManager.LoadSceneAsyn(this, "理论考核", () =>
|
||||
Bootstrap.Instance.scenesManager.LoadSceneAsyn("理论考核", () =>
|
||||
{
|
||||
Bootstrap.Instance.uiManager.ShowPanel<UI_MainTitlePanel>(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<UI_LoadingPanel>(this, E_UI_Layer.System, (panel) =>
|
||||
{
|
||||
Bootstrap.Instance.scenesManager.LoadSceneAsyn(this, "LiveScene", () =>
|
||||
Bootstrap.Instance.scenesManager.LoadSceneAsyn("LiveScene", () =>
|
||||
{
|
||||
Bootstrap.Instance.uiManager.ShowPanel<UI_MainTitlePanel>(this, E_UI_Layer.Bot, (panel) =>
|
||||
{
|
||||
|
|
|
@ -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<UI_SelectModePanel>(this, E_UI_Layer.Top, (panel) =>
|
||||
{
|
||||
|
|
|
@ -49,6 +49,8 @@ public class UI_TipsForPracticePanel : BasePanel
|
|||
public override void ShowMe()
|
||||
{
|
||||
base.ShowMe();
|
||||
string pptBtnName = Left_content.GetChild(0).GetComponent<UI_TipsForPracticePanelPPTNameItem>().PPTName_Btn.gameObject.name;
|
||||
OnClick(pptBtnName);
|
||||
}
|
||||
public override void HideMe()
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue