DataTableComponentInspector.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.DataTable;
  9. using UnityEditor;
  10. using UnityGameFramework.Runtime;
  11. namespace UnityGameFramework.Editor
  12. {
  13. [CustomEditor(typeof(DataTableComponent))]
  14. internal sealed class DataTableComponentInspector : GameFrameworkInspector
  15. {
  16. private SerializedProperty m_EnableLoadDataTableUpdateEvent = null;
  17. private SerializedProperty m_EnableLoadDataTableDependencyAssetEvent = null;
  18. private SerializedProperty m_CachedBytesSize = null;
  19. private HelperInfo<DataTableHelperBase> m_DataTableHelperInfo = new HelperInfo<DataTableHelperBase>("DataTable");
  20. public override void OnInspectorGUI()
  21. {
  22. base.OnInspectorGUI();
  23. serializedObject.Update();
  24. DataTableComponent t = (DataTableComponent)target;
  25. EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
  26. {
  27. EditorGUILayout.PropertyField(m_EnableLoadDataTableUpdateEvent);
  28. EditorGUILayout.PropertyField(m_EnableLoadDataTableDependencyAssetEvent);
  29. m_DataTableHelperInfo.Draw();
  30. EditorGUILayout.PropertyField(m_CachedBytesSize);
  31. }
  32. EditorGUI.EndDisabledGroup();
  33. if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject))
  34. {
  35. EditorGUILayout.LabelField("Data Table Count", t.Count.ToString());
  36. EditorGUILayout.LabelField("Cached Bytes Size", t.CachedBytesSize.ToString());
  37. DataTableBase[] dataTables = t.GetAllDataTables();
  38. foreach (DataTableBase dataTable in dataTables)
  39. {
  40. DrawDataTable(dataTable);
  41. }
  42. }
  43. serializedObject.ApplyModifiedProperties();
  44. Repaint();
  45. }
  46. protected override void OnCompileComplete()
  47. {
  48. base.OnCompileComplete();
  49. RefreshTypeNames();
  50. }
  51. private void OnEnable()
  52. {
  53. m_EnableLoadDataTableUpdateEvent = serializedObject.FindProperty("m_EnableLoadDataTableUpdateEvent");
  54. m_EnableLoadDataTableDependencyAssetEvent = serializedObject.FindProperty("m_EnableLoadDataTableDependencyAssetEvent");
  55. m_CachedBytesSize = serializedObject.FindProperty("m_CachedBytesSize");
  56. m_DataTableHelperInfo.Init(serializedObject);
  57. RefreshTypeNames();
  58. }
  59. private void DrawDataTable(DataTableBase dataTable)
  60. {
  61. EditorGUILayout.LabelField(dataTable.FullName, Utility.Text.Format("{0} Rows", dataTable.Count.ToString()));
  62. }
  63. private void RefreshTypeNames()
  64. {
  65. m_DataTableHelperInfo.Refresh();
  66. serializedObject.ApplyModifiedProperties();
  67. }
  68. }
  69. }