Преглед изворни кода

feat: 增加打开文件功能

zhangwenjie пре 1 година
родитељ
комит
663c5d5b81
2 измењених фајлова са 35 додато и 2 уклоњено
  1. 34 1
      Assets/Scripts/Core/File/FileManager.cs
  2. 1 1
      Assets/Scripts/UI/MainWindow/MainWindow.cs

+ 34 - 1
Assets/Scripts/Core/File/FileManager.cs

@@ -49,8 +49,41 @@ public class FileManager
     }
 
     //读取文件
-    public void OpenFile()
+    public static void OpenFile()
     {
+        try
+        {
+            Testfile openFileName = new Testfile();
+            openFileName.structSize = Marshal.SizeOf(openFileName);
+            openFileName.filter = "JSON Files (*.json)\0*.json\0"; ;
+            openFileName.file = new string(new char[256]);
+            openFileName.maxFile = openFileName.file.Length;
+            openFileName.fileTitle = new string(new char[64]);
+            openFileName.maxFileTitle = openFileName.fileTitle.Length;
+            openFileName.title = "选择文件";
+            openFileName.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000008;
+            if (DllTest.GetSaveFileName(openFileName))
+            {
+                string filepath = openFileName.file; //选择的文件路径;  
+                if (File.Exists(filepath))
+                {
+                    //if (callback != null)
+                    //    callback(filepath);
+                    //return;
+                }
+                Debug.Log(filepath);
+                string json = File.ReadAllText(filepath);
+                jsonData data = JsonUtility.FromJson<jsonData>(json);
+                Debug.Log(data.ProjectName);
+            }
+        }
+        catch (Exception e)
+        {
+            Debug.LogError(e);
+        }
+
+        //if (callback != null)
+        //    callback(string.Empty);
 
     }
 

+ 1 - 1
Assets/Scripts/UI/MainWindow/MainWindow.cs

@@ -39,13 +39,13 @@ namespace XiZiZhiShu
         private void OnClickOpenFile(InputUIOnClickEvent inputEvent)
         {
             Debug.Log("打开文件夹");
+            FileManager.OpenFile();
         }
 
         //新建文件按钮事件回调
         private void OnClickNewFile(InputUIOnClickEvent inputEvent)
         {
             Debug.Log("新建文件夹");
-            FileManager  file = new FileManager();
             string input = "C/";
             FileManager.CreatFolder(input);
         }