UGUIFunctiontemplateWindow.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using UnityEngine;
  6. using UnityEngine.UI.PackgTool;
  7. namespace UnityEditor.UI
  8. {
  9. public class UGUIFunctiontemplateWindow : EditorWindow
  10. {
  11. private static System.Action<PackInfo> callBack;
  12. public static void OpenWidow(System.Action<PackInfo> callBack)
  13. {
  14. UGUIFunctiontemplateWindow.callBack = callBack;
  15. EditorWindow.GetWindow<UGUIFunctiontemplateWindow>().Show();
  16. }
  17. public string functionPathJson = "/Art/UIAssets/TextrueJson";
  18. Vector2 pos = Vector2.zero;
  19. private string _currSelectName;
  20. private void OnGUI()
  21. {
  22. string path = Application.dataPath + functionPathJson;
  23. string[] allPath = System.IO.Directory.GetFiles(path, "*.txt");
  24. List<TextrueJson> gameAllModel = new List<TextrueJson>();
  25. for (int i = 0; i < allPath.Length; i++)
  26. {
  27. string jsonPath = File.ReadAllText(allPath[i]);
  28. TextrueJson textrueJson = JsonUtility.FromJson<TextrueJson>(jsonPath);
  29. gameAllModel.Add(textrueJson);
  30. }
  31. _currSelectName= GUILayout.TextArea(_currSelectName,"筛选" );
  32. pos = GUILayout.BeginScrollView(pos);
  33. for (int i = 0; i < gameAllModel.Count; i++)
  34. {
  35. if (!string.IsNullOrEmpty(_currSelectName)&&_currSelectName!=""&&!gameAllModel[i].packName.Contains(_currSelectName))
  36. {
  37. continue;
  38. }
  39. if (GUILayout.Button(gameAllModel[i].packName))
  40. {
  41. Close();
  42. PackInfo packInfo= UGUICacheInfo.GetPackDB(gameAllModel[i].packName);
  43. if (packInfo == null)
  44. {
  45. packInfo= UGUICacheInfo.AddNewPackInfo(allPath[i].Replace(Application.dataPath, ""), gameAllModel[i]);
  46. }
  47. callBack?.Invoke(packInfo);
  48. }
  49. }
  50. GUILayout.EndScrollView();
  51. }
  52. }
  53. }