EntityComponentInspector.cs 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.Entity;
  9. using UnityEditor;
  10. using UnityGameFramework.Runtime;
  11. namespace UnityGameFramework.Editor
  12. {
  13. [CustomEditor(typeof(EntityComponent))]
  14. internal sealed class EntityComponentInspector : GameFrameworkInspector
  15. {
  16. private SerializedProperty m_EnableShowEntityUpdateEvent = null;
  17. private SerializedProperty m_EnableShowEntityDependencyAssetEvent = null;
  18. private SerializedProperty m_InstanceRoot = null;
  19. private SerializedProperty m_EntityGroups = null;
  20. private HelperInfo<EntityHelperBase> m_EntityHelperInfo = new HelperInfo<EntityHelperBase>("Entity");
  21. private HelperInfo<EntityGroupHelperBase> m_EntityGroupHelperInfo = new HelperInfo<EntityGroupHelperBase>("EntityGroup");
  22. public override void OnInspectorGUI()
  23. {
  24. base.OnInspectorGUI();
  25. serializedObject.Update();
  26. EntityComponent t = (EntityComponent)target;
  27. EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
  28. {
  29. EditorGUILayout.PropertyField(m_EnableShowEntityUpdateEvent);
  30. EditorGUILayout.PropertyField(m_EnableShowEntityDependencyAssetEvent);
  31. EditorGUILayout.PropertyField(m_InstanceRoot);
  32. m_EntityHelperInfo.Draw();
  33. m_EntityGroupHelperInfo.Draw();
  34. EditorGUILayout.PropertyField(m_EntityGroups, true);
  35. }
  36. EditorGUI.EndDisabledGroup();
  37. if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject))
  38. {
  39. EditorGUILayout.LabelField("Entity Group Count", t.EntityGroupCount.ToString());
  40. EditorGUILayout.LabelField("Entity Count (Total)", t.EntityCount.ToString());
  41. IEntityGroup[] entityGroups = t.GetAllEntityGroups();
  42. foreach (IEntityGroup entityGroup in entityGroups)
  43. {
  44. EditorGUILayout.LabelField(Utility.Text.Format("Entity Count ({0})", entityGroup.Name), entityGroup.EntityCount.ToString());
  45. }
  46. }
  47. serializedObject.ApplyModifiedProperties();
  48. Repaint();
  49. }
  50. protected override void OnCompileComplete()
  51. {
  52. base.OnCompileComplete();
  53. RefreshTypeNames();
  54. }
  55. private void OnEnable()
  56. {
  57. m_EnableShowEntityUpdateEvent = serializedObject.FindProperty("m_EnableShowEntityUpdateEvent");
  58. m_EnableShowEntityDependencyAssetEvent = serializedObject.FindProperty("m_EnableShowEntityDependencyAssetEvent");
  59. m_InstanceRoot = serializedObject.FindProperty("m_InstanceRoot");
  60. m_EntityGroups = serializedObject.FindProperty("m_EntityGroups");
  61. m_EntityHelperInfo.Init(serializedObject);
  62. m_EntityGroupHelperInfo.Init(serializedObject);
  63. RefreshTypeNames();
  64. }
  65. private void RefreshTypeNames()
  66. {
  67. m_EntityHelperInfo.Refresh();
  68. m_EntityGroupHelperInfo.Refresh();
  69. serializedObject.ApplyModifiedProperties();
  70. }
  71. }
  72. }