修改ppt加载(点一个加载一个)

This commit is contained in:
taosuqi 2025-04-11 16:02:01 +08:00
parent 0631c29109
commit 20855f01c0
4 changed files with 38 additions and 45 deletions

View File

@ -64,7 +64,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 0}
m_RaycastTarget: 1
m_RaycastTarget: 0
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:

View File

@ -19,8 +19,8 @@ public class Bootstrap : SingletonMono<Bootstrap>
eventCenter = new EventCenter();
scenesManager = new ScenesManager(this);
pptFolderName = Application.streamingAssetsPath + "/PPT";
//LoadPPTTest.PPTFiles(pptFolderName);
//ppts = LoadPPTTest.PPTName();
LoadPPTTest.PPTFiles(pptFolderName);
ppts = LoadPPTTest.PPTName();
DontDestroyOnLoad(gameObject);
}
@ -33,10 +33,9 @@ public class Bootstrap : SingletonMono<Bootstrap>
{
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");
});
});

View File

@ -80,44 +80,38 @@ public static class LoadPPTTest
/// 获取文件夹下所有.pptx文件
/// </summary>
/// <param name="folderPath"></param>
public static async void PPTFiles(string folderPath)
public static 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 UniTask.Yield();
await LoadAllPPTFiles(pptName, pptsPath[i]);
}
}
public static async UniTask LoadAllPPTFiles(string pptName, string folderPath)
{
List<Texture2D> texture2Ds = new List<Texture2D>();
Presentation presentation = new Presentation(folderPath);
// 遍历文档(只做示例使用自己根据需求拓展)
for (int i = 0; i < presentation.Slides.Count; i++)
{
await UniTask.Yield();
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);
await ms.ReadAsync(buff, 0, (int)ms.Length);
Texture2D texture2D = new Texture2D(2, 2);
texture2D.LoadImage(buff);
texture2Ds.Add(texture2D);
}
}
texturesDic.Add(pptName, texture2Ds);
Debug.Log("所有PPT加载完成");
}
//public static async UniTask LoadAllPPTFiles(string pptName, string folderPath)
//{
// List<Texture2D> texture2Ds = new List<Texture2D>();
// Presentation presentation = new Presentation(folderPath);
// // 遍历文档(只做示例使用自己根据需求拓展)
// for (int i = 0; i < presentation.Slides.Count; i++)
// {
// await UniTask.Yield();
// 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);
// await ms.ReadAsync(buff, 0, (int)ms.Length);
// Texture2D texture2D = new Texture2D(2, 2);
// texture2D.LoadImage(buff);
// texture2Ds.Add(texture2D);
// }
// }
// texturesDic.Add(pptName, texture2Ds);
// Debug.Log("所有PPT加载完成");
//}
public static List<Texture2D> LoadAllPPTFiles(string folderPath)
{

View File

@ -21,8 +21,7 @@ public class UI_TipsForPracticePanel : BasePanel
protected override void Awake()
{
base.Awake();
canvasGroup.alpha = 0f;
canvasGroup.alpha = 1f;
// 1. 提取文件名并解析数字前缀
var sortedItems = Bootstrap.Instance.ppts
.Select(path => new
@ -41,6 +40,7 @@ public class UI_TipsForPracticePanel : BasePanel
buttonItem.PPTName_Tog.gameObject.name = item.Name;
Debug.Log($"已创建按钮: {item.Name} (排序键: {item.Order})");
}
base.Awake();
//pptConfig = JsonManager.LoadData<PPTConfig>("pptConfig");
if (Bootstrap.Instance.ppts == null || Bootstrap.Instance.ppts.Length == 0)
{
@ -50,17 +50,17 @@ public class UI_TipsForPracticePanel : BasePanel
}
public override async void ShowMe(int time = 0)
public override void ShowMe(int time = 0)
{
base.ShowMe();
string pptBtnName = Left_content.GetChild(0).GetComponent<UI_TipsForPracticePanelPPTNameItem>().PPTName_Tog.gameObject.name;
OnClick(pptBtnName);
await ToolManager.CanvasFadeIn(canvasGroup, 0.5f);
//string pptBtnName = Left_content.GetChild(0).GetComponent<UI_TipsForPracticePanelPPTNameItem>().PPTName_Tog.gameObject.name;
//OnClick(pptBtnName);
///await ToolManager.CanvasFadeIn(canvasGroup, 0.5f);
}
public override async void HideMe(int time = 0)
public override void HideMe(int time = 0)
{
base.HideMe();
await ToolManager.CanvasFadeOut(canvasGroup, 0.5f);
//await ToolManager.CanvasFadeOut(canvasGroup, 0.5f);
}
protected override async void OnClick(string btnName)