FileSystemComponentInspector.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //------------------------------------------------------------
  2. // Game Framework
  3. // Copyright © 2013-2021 loyalsoft. All rights reserved.
  4. // Homepage: http://www.game7000.com/
  5. // Feedback: http://www.game7000.com/
  6. //------------------------------------------------------------
  7. using GameFramework;
  8. using GameFramework.FileSystem;
  9. using UnityEditor;
  10. using UnityGameFramework.Runtime;
  11. namespace UnityGameFramework.Editor
  12. {
  13. [CustomEditor(typeof(FileSystemComponent))]
  14. internal sealed class FileSystemComponentInspector : GameFrameworkInspector
  15. {
  16. private HelperInfo<FileSystemHelperBase> m_FileSystemHelperInfo = new HelperInfo<FileSystemHelperBase>("FileSystem");
  17. public override void OnInspectorGUI()
  18. {
  19. base.OnInspectorGUI();
  20. FileSystemComponent t = (FileSystemComponent)target;
  21. EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
  22. {
  23. m_FileSystemHelperInfo.Draw();
  24. }
  25. EditorGUI.EndDisabledGroup();
  26. if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject))
  27. {
  28. EditorGUILayout.LabelField("File System Count", t.Count.ToString());
  29. IFileSystem[] fileSystems = t.GetAllFileSystems();
  30. foreach (IFileSystem fileSystem in fileSystems)
  31. {
  32. DrawFileSystem(fileSystem);
  33. }
  34. }
  35. serializedObject.ApplyModifiedProperties();
  36. Repaint();
  37. }
  38. protected override void OnCompileComplete()
  39. {
  40. base.OnCompileComplete();
  41. RefreshTypeNames();
  42. }
  43. private void OnEnable()
  44. {
  45. m_FileSystemHelperInfo.Init(serializedObject);
  46. RefreshTypeNames();
  47. }
  48. private void RefreshTypeNames()
  49. {
  50. m_FileSystemHelperInfo.Refresh();
  51. serializedObject.ApplyModifiedProperties();
  52. }
  53. private void DrawFileSystem(IFileSystem fileSystem)
  54. {
  55. EditorGUILayout.LabelField(fileSystem.FullPath, Utility.Text.Format("{0}, {1} / {2} Files", fileSystem.Access.ToString(), fileSystem.FileCount.ToString(), fileSystem.MaxFileCount.ToString()));
  56. }
  57. }
  58. }