SceneComponentInspector.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 UnityEditor;
  8. using UnityEngine;
  9. using UnityGameFramework.Runtime;
  10. namespace UnityGameFramework.Editor
  11. {
  12. [CustomEditor(typeof(SceneComponent))]
  13. internal sealed class SceneComponentInspector : GameFrameworkInspector
  14. {
  15. private SerializedProperty m_EnableLoadSceneUpdateEvent = null;
  16. private SerializedProperty m_EnableLoadSceneDependencyAssetEvent = null;
  17. public override void OnInspectorGUI()
  18. {
  19. base.OnInspectorGUI();
  20. serializedObject.Update();
  21. SceneComponent t = (SceneComponent)target;
  22. EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
  23. {
  24. EditorGUILayout.PropertyField(m_EnableLoadSceneUpdateEvent);
  25. EditorGUILayout.PropertyField(m_EnableLoadSceneDependencyAssetEvent);
  26. }
  27. EditorGUI.EndDisabledGroup();
  28. serializedObject.ApplyModifiedProperties();
  29. if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject))
  30. {
  31. EditorGUILayout.LabelField("Loaded Scene Asset Names", GetSceneNameString(t.GetLoadedSceneAssetNames()));
  32. EditorGUILayout.LabelField("Loading Scene Asset Names", GetSceneNameString(t.GetLoadingSceneAssetNames()));
  33. EditorGUILayout.LabelField("Unloading Scene Asset Names", GetSceneNameString(t.GetUnloadingSceneAssetNames()));
  34. EditorGUILayout.ObjectField("Main Camera", t.MainCamera, typeof(Camera), true);
  35. Repaint();
  36. }
  37. }
  38. private void OnEnable()
  39. {
  40. m_EnableLoadSceneUpdateEvent = serializedObject.FindProperty("m_EnableLoadSceneUpdateEvent");
  41. m_EnableLoadSceneDependencyAssetEvent = serializedObject.FindProperty("m_EnableLoadSceneDependencyAssetEvent");
  42. }
  43. private string GetSceneNameString(string[] sceneAssetNames)
  44. {
  45. if (sceneAssetNames == null || sceneAssetNames.Length <= 0)
  46. {
  47. return "<Empty>";
  48. }
  49. string sceneNameString = string.Empty;
  50. foreach (string sceneAssetName in sceneAssetNames)
  51. {
  52. if (!string.IsNullOrEmpty(sceneNameString))
  53. {
  54. sceneNameString += ", ";
  55. }
  56. sceneNameString += SceneComponent.GetSceneName(sceneAssetName);
  57. }
  58. return sceneNameString;
  59. }
  60. }
  61. }