FsmComponentInspector.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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.Fsm;
  9. using UnityEditor;
  10. using UnityGameFramework.Runtime;
  11. namespace UnityGameFramework.Editor
  12. {
  13. [CustomEditor(typeof(FsmComponent))]
  14. internal sealed class FsmComponentInspector : GameFrameworkInspector
  15. {
  16. public override void OnInspectorGUI()
  17. {
  18. base.OnInspectorGUI();
  19. if (!EditorApplication.isPlaying)
  20. {
  21. EditorGUILayout.HelpBox("Available during runtime only.", MessageType.Info);
  22. return;
  23. }
  24. FsmComponent t = (FsmComponent)target;
  25. if (IsPrefabInHierarchy(t.gameObject))
  26. {
  27. EditorGUILayout.LabelField("FSM Count", t.Count.ToString());
  28. FsmBase[] fsms = t.GetAllFsms();
  29. foreach (FsmBase fsm in fsms)
  30. {
  31. DrawFsm(fsm);
  32. }
  33. }
  34. Repaint();
  35. }
  36. private void OnEnable()
  37. {
  38. }
  39. private void DrawFsm(FsmBase fsm)
  40. {
  41. EditorGUILayout.LabelField(fsm.FullName, fsm.IsRunning ? Utility.Text.Format("{0}, {1} s", fsm.CurrentStateName, fsm.CurrentStateTime.ToString("F1")) : (fsm.IsDestroyed ? "Destroyed" : "Not Running"));
  42. }
  43. }
  44. }