private void Awake() { _lastTime = EditorApplication.timeSinceStartup; // 加载提示图片 string folderPath = EditorTools.FindFolder(Application.dataPath, "ParticleProfiler"); if (string.IsNullOrEmpty(folderPath) == false) { string temp = EditorTools.AbsolutePathToAssetPath(folderPath); _texTips = AssetDatabase.LoadAssetAtPath <Texture2D>($"{temp}/GUI/tips.png"); if (_texTips == null) { Debug.LogWarning("Not found ParticleProfilerWindows tips texture."); } } else { Debug.LogWarning("Not found ParticleProfiler folder."); } // 加载测试场景 string path = EditorPrefs.GetString(PROFILER_SCENE_KEY, string.Empty); if (string.IsNullOrEmpty(path) == false) { _profilerScene = AssetDatabase.LoadAssetAtPath <SceneAsset>(path); } }
protected void ShowLobbyScenes() { NetworkLobbyManager target = this.target as NetworkLobbyManager; if ((Object)target == (Object)null) { return; } SceneAsset sceneObject1 = this.GetSceneObject(target.lobbyScene); EditorGUI.BeginChangeCheck(); Object object1 = EditorGUILayout.ObjectField(this.m_LobbySceneLabel, (Object)sceneObject1, typeof(SceneAsset), false, new GUILayoutOption[0]); if (EditorGUI.EndChangeCheck()) { if (object1 == (Object)null) { this.SetLobbyScene(target, string.Empty); } else if (object1.name != target.offlineScene) { if ((Object)this.GetSceneObject(object1.name) == (Object)null) { Debug.LogWarning((object)("The scene " + object1.name + " cannot be used. To use this scene add it to the build settings for the project")); } else { this.SetLobbyScene(target, object1.name); } } } SceneAsset sceneObject2 = this.GetSceneObject(target.playScene); EditorGUI.BeginChangeCheck(); Object object2 = EditorGUILayout.ObjectField(this.m_PlaySceneLabel, (Object)sceneObject2, typeof(SceneAsset), false, new GUILayoutOption[0]); if (!EditorGUI.EndChangeCheck()) { return; } if (object2 == (Object)null) { this.SetPlayScene(target, string.Empty); } else { if (!(object2.name != this.m_NetworkManager.onlineScene)) { return; } if ((Object)this.GetSceneObject(object2.name) == (Object)null) { Debug.LogWarning((object)("The scene " + object2.name + " cannot be used. To use this scene add it to the build settings for the project")); } else { this.SetPlayScene(target, object2.name); } } }
protected void ShowLobbyScenes() { NetworkLobbyManager target = base.target as NetworkLobbyManager; if (target != null) { SceneAsset sceneObject = base.GetSceneObject(target.lobbyScene); EditorGUI.BeginChangeCheck(); UnityEngine.Object obj2 = EditorGUILayout.ObjectField(this.m_LobbySceneLabel, sceneObject, typeof(SceneAsset), false, new GUILayoutOption[0]); if (EditorGUI.EndChangeCheck()) { if (obj2 == null) { this.SetLobbyScene(target, ""); } else if (obj2.name != target.offlineScene) { if (base.GetSceneObject(obj2.name) == null) { Debug.LogWarning("The scene " + obj2.name + " cannot be used. To use this scene add it to the build settings for the project"); } else { this.SetLobbyScene(target, obj2.name); } } } SceneAsset asset3 = base.GetSceneObject(target.playScene); EditorGUI.BeginChangeCheck(); UnityEngine.Object obj3 = EditorGUILayout.ObjectField(this.m_PlaySceneLabel, asset3, typeof(SceneAsset), false, new GUILayoutOption[0]); if (EditorGUI.EndChangeCheck()) { if (obj3 == null) { this.SetPlayScene(target, ""); } else if (obj3.name != base.m_NetworkManager.onlineScene) { if (base.GetSceneObject(obj3.name) == null) { Debug.LogWarning("The scene " + obj3.name + " cannot be used. To use this scene add it to the build settings for the project"); } else { this.SetPlayScene(target, obj3.name); } } } } }
private void CacheProperties(SerializedProperty property) { scene = property.FindPropertyRelative("Scene"); sceneName = property.FindPropertyRelative("SceneName"); sceneIndex = property.FindPropertyRelative("sceneIndex"); sceneEnabled = property.FindPropertyRelative("sceneEnabled"); sceneAsset = scene.objectReferenceValue as UnityEditor.SceneAsset; if (sceneAsset != null) { sceneAssetPath = AssetDatabase.GetAssetPath(scene.objectReferenceValue); sceneAssetGUID = AssetDatabase.AssetPathToGUID(sceneAssetPath); } else { sceneAssetPath = null; sceneAssetGUID = null; } }
private void OnGUI() { EditorGUILayout.Space(); // 测试场景 SceneAsset scene = (SceneAsset)EditorGUILayout.ObjectField($"测试场景", _profilerScene, typeof(SceneAsset), false); if (_profilerScene != scene) { _profilerScene = scene; string path = AssetDatabase.GetAssetPath(scene); EditorPrefs.SetString(PROFILER_SCENE_KEY, path); } // 测试特效 _effectPrefab = EditorGUILayout.ObjectField($"请选择特效", _effectPrefab, typeof(UnityEngine.Object), false); // 测试按钮 if (GUILayout.Button("测试")) { if (CheckProfilerCondition() == false) { return; } // 焦点锁定游戏窗口 var gameViewType = typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.GameView"); EditorWindow gameView = EditorWindow.GetWindow(gameViewType); gameView.Focus(); // 开始分析 _isPause = false; _profiler.Analyze(_effectPrefab); Debug.Log($"开始测试特效:{_effectPrefab.name}"); } // 暂停按钮 if (_isPause) { if (GUILayout.Button("点击按钮恢复")) { _isPause = false; } } else { if (GUILayout.Button("点击按钮暂停")) { _isPause = true; } } // 粒子基本信息 EditorGUILayout.Space(); EditorGUILayout.LabelField($"材质数量:{_profiler.MaterialCount}"); EditorGUILayout.LabelField($"纹理数量:{_profiler.TextureCount}"); EditorGUILayout.LabelField($"纹理内存:{EditorUtility.FormatBytes(_profiler.TextureMemory)}"); EditorGUILayout.LabelField($"粒子系统组件:{_profiler.ParticleSystemComponentCount} 个"); // 粒子动态信息 EditorGUILayout.Space(); EditorGUILayout.LabelField($"DrawCall:{_profiler.DrawCallCurrentNum} 最大:{_profiler.DrawCallMaxNum}"); EditorGUILayout.LabelField($"粒子数量:{_profiler.ParticleCurrentCount} 最大:{_profiler.ParticleMaxCount}"); EditorGUILayout.LabelField($"三角面数:{_profiler.TriangleCurrentCount} 最大:{_profiler.TriangleMaxCount}"); // 错误信息 if (_profiler.Errors.Count > 0) { EditorGUILayout.Space(); EditorGUILayout.HelpBox($"请修正以下错误提示", MessageType.Error, true); EditorGUI.indentLevel = 1; foreach (var error in _profiler.Errors) { GUIStyle style = new GUIStyle(); style.normal.textColor = new Color(0.8f, 0, 0); EditorGUILayout.LabelField(error, style); } EditorGUI.indentLevel = 0; } // 曲线图 EditorGUILayout.Space(); using (new EditorGUI.DisabledScope(false)) { _isShowCurves = EditorGUILayout.Foldout(_isShowCurves, "时间曲线"); if (_isShowCurves) { float curveHeight = 80; EditorGUI.indentLevel = 1; EditorGUILayout.LabelField($"采样时长 {_profiler.CurveSampleTime} 秒"); EditorGUILayout.CurveField("DrawCall", _profiler.DrawCallCurve, GUILayout.Height(curveHeight)); EditorGUILayout.CurveField("粒子数量", _profiler.ParticleCountCurve, GUILayout.Height(curveHeight)); EditorGUILayout.CurveField("三角面数", _profiler.TriangleCountCurve, GUILayout.Height(curveHeight)); EditorGUI.indentLevel = 0; } } // 纹理列表 EditorGUILayout.Space(); using (new EditorGUI.DisabledScope(false)) { _isShowTextures = EditorGUILayout.Foldout(_isShowTextures, "纹理列表"); if (_isShowTextures) { EditorGUI.indentLevel = 1; _scrollPos1 = EditorGUILayout.BeginScrollView(_scrollPos1); { List <Texture> textures = _profiler.AllTextures; foreach (var tex in textures) { EditorGUILayout.LabelField($"{tex.name} 尺寸:{tex.height }*{tex.width} 格式:{ParticleProfiler.GetTextureFormatString(tex)}"); EditorGUILayout.ObjectField("", tex, typeof(Texture), false, GUILayout.Width(80)); } } EditorGUILayout.EndScrollView(); EditorGUI.indentLevel = 0; } } // 网格列表 EditorGUILayout.Space(); using (new EditorGUI.DisabledScope(false)) { _isShowMeshs = EditorGUILayout.Foldout(_isShowMeshs, "网格列表"); if (_isShowMeshs) { EditorGUI.indentLevel = 1; _scrollPos2 = EditorGUILayout.BeginScrollView(_scrollPos2); { List <Mesh> meshs = _profiler.AllMeshs; foreach (var mesh in meshs) { EditorGUILayout.ObjectField($"三角面数 : {mesh.triangles.Length / 3}", mesh, typeof(MeshFilter), false, GUILayout.Width(300)); } } EditorGUILayout.EndScrollView(); EditorGUI.indentLevel = 0; } } // 过程化检测结果 EditorGUILayout.Space(); using (new EditorGUI.DisabledScope(false)) { _isShowTips = EditorGUILayout.Foldout(_isShowTips, "过程化检测结果"); if (_isShowTips) { EditorGUI.indentLevel = 1; _scrollPos3 = EditorGUILayout.BeginScrollView(_scrollPos3); { GUILayout.Button(_texTips); //绘制提示图片 EditorGUILayout.HelpBox($"以下粒子系统组件不支持过程化模式!具体原因查看气泡提示", MessageType.Warning, true); #if UNITY_2018_4_OR_NEWER List <ParticleSystem> particleList = _profiler.AllParticles; foreach (var ps in particleList) { if (ps.proceduralSimulationSupported == false) { EditorGUILayout.ObjectField($"{ps.gameObject.name}", ps.gameObject, typeof(GameObject), false, GUILayout.Width(300)); } } #else EditorGUILayout.LabelField("当前版本不支持过程化检测,请升级至2018.4版本或最新版本"); #endif } EditorGUILayout.EndScrollView(); EditorGUI.indentLevel = 0; } } }
public override void OnInspectorGUI() { serializedObject.Update(); // GUI.enabled hack because we don't want some controls to be disabled if the EditorSettings.asset is locked // since some of the controls are not dependent on the Editor Settings asset. Unfortunately, this assumes // that the editor will only be disabled because of version control locking which may change in the future. var editorEnabled = GUI.enabled; ShowUnityRemoteGUI(editorEnabled); bool collabEnabled = Collab.instance.IsCollabEnabledForCurrentProject(); GUILayout.Space(10); int index = (int)EditorSettings.serializationMode; using (new EditorGUI.DisabledScope(!collabEnabled)) { GUI.enabled = !collabEnabled; GUILayout.Label(Content.assetSerialization, EditorStyles.boldLabel); GUI.enabled = editorEnabled && !collabEnabled; CreatePopupMenu("Mode", serializationPopupList, index, SetAssetSerializationMode); } if (collabEnabled) { EditorGUILayout.HelpBox("Asset Serialization is forced to Text when using Collaboration feature.", MessageType.Warning); } if (EditorSettings.serializationMode != SerializationMode.ForceBinary) { EditorSettings.serializeInlineMappingsOnOneLine = EditorGUILayout.Toggle(Content.textSerializeMappingsOnOneLine, EditorSettings.serializeInlineMappingsOnOneLine); } GUILayout.Space(10); GUI.enabled = true; GUILayout.Label(Content.defaultBehaviorMode, EditorStyles.boldLabel); GUI.enabled = editorEnabled; index = Mathf.Clamp((int)EditorSettings.defaultBehaviorMode, 0, behaviorPopupList.Length - 1); CreatePopupMenu(Content.mode.text, behaviorPopupList, index, SetDefaultBehaviorMode); { var wasEnabled = GUI.enabled; GUI.enabled = true; DoAssetPipelineSettings(); if (EditorSettings.assetPipelineMode == AssetPipelineMode.Version2) { DoCacheServerSettings(); } GUI.enabled = wasEnabled; } GUILayout.Space(10); GUI.enabled = true; GUILayout.Label("Prefab Editing Environments", EditorStyles.boldLabel); GUI.enabled = editorEnabled; { EditorGUI.BeginChangeCheck(); SceneAsset scene = EditorSettings.prefabRegularEnvironment; scene = (SceneAsset)EditorGUILayout.ObjectField("Regular Environment", scene, typeof(SceneAsset), false); if (EditorGUI.EndChangeCheck()) { EditorSettings.prefabRegularEnvironment = scene; } } { EditorGUI.BeginChangeCheck(); SceneAsset scene = EditorSettings.prefabUIEnvironment; scene = (SceneAsset)EditorGUILayout.ObjectField("UI Environment", scene, typeof(SceneAsset), false); if (EditorGUI.EndChangeCheck()) { EditorSettings.prefabUIEnvironment = scene; } } GUILayout.Space(10); GUI.enabled = true; GUILayout.Label(Content.graphics, EditorStyles.boldLabel); GUI.enabled = editorEnabled; EditorGUI.BeginChangeCheck(); bool showRes = LightmapVisualization.showResolution; showRes = EditorGUILayout.Toggle(Content.showLightmapResolutionOverlay, showRes); if (EditorGUI.EndChangeCheck()) { LightmapVisualization.showResolution = showRes; } EditorGUI.BeginChangeCheck(); bool useLegacyProbeSampleCountValue = EditorSettings.useLegacyProbeSampleCount; useLegacyProbeSampleCountValue = EditorGUILayout.Toggle(Content.useLegacyProbeSampleCount, useLegacyProbeSampleCountValue); if (EditorGUI.EndChangeCheck()) { EditorApplication.RequestRepaintAllViews(); EditorSettings.useLegacyProbeSampleCount = useLegacyProbeSampleCountValue; } GUILayout.Space(10); GUI.enabled = true; GUILayout.Label(Content.spritePacker, EditorStyles.boldLabel); GUI.enabled = editorEnabled; index = Mathf.Clamp((int)EditorSettings.spritePackerMode, 0, spritePackerPopupList.Length - 1); CreatePopupMenu(Content.mode.text, spritePackerPopupList, index, SetSpritePackerMode); if (EditorSettings.spritePackerMode == SpritePackerMode.SpriteAtlasV2) { var message = "Sprite Atlas V2 (Experimental) supports CacheServer with Importer workflow. Please take a backup of your project before switching to V2."; EditorGUILayout.HelpBox(message, MessageType.Info, true); } if (EditorSettings.spritePackerMode == SpritePackerMode.AlwaysOn || EditorSettings.spritePackerMode == SpritePackerMode.BuildTimeOnly) { index = Mathf.Clamp((int)(EditorSettings.spritePackerPaddingPower - 1), 0, 2); CreatePopupMenu("Padding Power (Legacy Sprite Packer)", spritePackerPaddingPowerPopupList, index, SetSpritePackerPaddingPower); } DoProjectGenerationSettings(); DoEtcTextureCompressionSettings(); DoLineEndingsSettings(); DoStreamingSettings(); DoShaderCompilationSettings(); DoEnterPlayModeSettings(); serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { serializedObject.Update(); // GUI.enabled hack because we don't want some controls to be disabled if the EditorSettings.asset is locked // since some of the controls are not dependent on the Editor Settings asset. Unfortunately, this assumes // that the editor will only be disabled because of version control locking which may change in the future. var editorEnabled = GUI.enabled; ShowUnityRemoteGUI(editorEnabled); GUILayout.Space(10); bool collabEnabled = Collab.instance.IsCollabEnabledForCurrentProject(); using (new EditorGUI.DisabledScope(!collabEnabled)) { GUI.enabled = !collabEnabled; GUILayout.Label(Content.versionControl, EditorStyles.boldLabel); ExternalVersionControl selvc = EditorSettings.externalVersionControl; CreatePopupMenuVersionControl(Content.mode.text, vcPopupList, selvc, SetVersionControlSystem); GUI.enabled = editorEnabled && !collabEnabled; } if (collabEnabled) { EditorGUILayout.HelpBox("Version Control not available when using Collaboration feature.", MessageType.Warning); } if (VersionControlSystemHasGUI()) { GUI.enabled = true; bool hasRequiredFields = false; if (EditorSettings.externalVersionControl == ExternalVersionControl.Generic || EditorSettings.externalVersionControl == ExternalVersionControl.Disabled) { // no specific UI for these VCS types } else { ConfigField[] configFields = Provider.GetActiveConfigFields(); hasRequiredFields = true; foreach (ConfigField field in configFields) { string newVal; string oldVal = EditorUserSettings.GetConfigValue(field.name); if (field.isPassword) { newVal = EditorGUILayout.PasswordField(field.label, oldVal); if (newVal != oldVal) { EditorUserSettings.SetPrivateConfigValue(field.name, newVal); } } else { newVal = EditorGUILayout.TextField(field.label, oldVal); if (newVal != oldVal) { EditorUserSettings.SetConfigValue(field.name, newVal); } } if (field.isRequired && string.IsNullOrEmpty(newVal)) { hasRequiredFields = false; } } } // Log level popup string logLevel = EditorUserSettings.GetConfigValue("vcSharedLogLevel"); int idx = System.Array.FindIndex(logLevelPopupList, (item) => item.ToLower() == logLevel); if (idx == -1) { logLevel = "notice"; idx = System.Array.FindIndex(logLevelPopupList, (item) => item.ToLower() == logLevel); if (idx == -1) { idx = 0; } logLevel = logLevelPopupList[idx]; EditorUserSettings.SetConfigValue("vcSharedLogLevel", logLevel); } int newIdx = EditorGUILayout.Popup(Content.logLevel, idx, logLevelPopupList); if (newIdx != idx) { EditorUserSettings.SetConfigValue("vcSharedLogLevel", logLevelPopupList[newIdx].ToLower()); } GUI.enabled = editorEnabled; string osState = "Connected"; if (Provider.onlineState == OnlineState.Updating) { osState = "Connecting..."; } else if (Provider.onlineState == OnlineState.Offline) { osState = "Disconnected"; } EditorGUILayout.LabelField(Content.status.text, osState); if (Provider.onlineState != OnlineState.Online && !string.IsNullOrEmpty(Provider.offlineReason)) { GUI.enabled = false; GUILayout.TextArea(Provider.offlineReason); GUI.enabled = editorEnabled; } GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUI.enabled = hasRequiredFields && Provider.onlineState != OnlineState.Updating; if (GUILayout.Button("Connect", EditorStyles.miniButton)) { Provider.UpdateSettings(); } GUILayout.EndHorizontal(); EditorUserSettings.AutomaticAdd = EditorGUILayout.Toggle(Content.automaticAdd, EditorUserSettings.AutomaticAdd); if (Provider.requiresNetwork) { bool workOfflineNew = EditorGUILayout.Toggle(Content.workOffline, EditorUserSettings.WorkOffline); // Enabled has a slightly different behaviour if (workOfflineNew != EditorUserSettings.WorkOffline) { // On toggling on show a warning if (workOfflineNew && !EditorUtility.DisplayDialog("Confirm working offline", "Working offline and making changes to your assets means that you will have to manually integrate changes back into version control using your standard version control client before you stop working offline in Unity. Make sure you know what you are doing.", "Work offline", "Cancel")) { workOfflineNew = false; // User cancelled working offline } EditorUserSettings.WorkOffline = workOfflineNew; EditorApplication.RequestRepaintAllViews(); } EditorUserSettings.allowAsyncStatusUpdate = EditorGUILayout.Toggle(Content.allowAsyncUpdate, EditorUserSettings.allowAsyncStatusUpdate); } if (Provider.hasCheckoutSupport) { EditorUserSettings.showFailedCheckout = EditorGUILayout.Toggle(Content.showFailedCheckouts, EditorUserSettings.showFailedCheckout); } GUI.enabled = editorEnabled; // Semantic merge popup EditorUserSettings.semanticMergeMode = (SemanticMergeMode)EditorGUILayout.Popup(Content.smartMerge, (int)EditorUserSettings.semanticMergeMode, semanticMergePopupList); DrawOverlayDescriptions(); } GUILayout.Space(10); int index = (int)EditorSettings.serializationMode; using (new EditorGUI.DisabledScope(!collabEnabled)) { GUI.enabled = !collabEnabled; GUILayout.Label(Content.assetSerialization, EditorStyles.boldLabel); GUI.enabled = editorEnabled && !collabEnabled; CreatePopupMenu("Mode", serializationPopupList, index, SetAssetSerializationMode); } if (collabEnabled) { EditorGUILayout.HelpBox("Asset Serialization is forced to Text when using Collaboration feature.", MessageType.Warning); } GUILayout.Space(10); GUI.enabled = true; GUILayout.Label(Content.defaultBehaviorMode, EditorStyles.boldLabel); GUI.enabled = editorEnabled; index = Mathf.Clamp((int)EditorSettings.defaultBehaviorMode, 0, behaviorPopupList.Length - 1); CreatePopupMenu(Content.mode.text, behaviorPopupList, index, SetDefaultBehaviorMode); DoAssetPipelineSettings(); if (m_AssetPipelineMode.intValue == (int)AssetPipelineMode.Version2) { DoCacheServerSettings(); } GUILayout.Space(10); GUI.enabled = true; GUILayout.Label("Prefab Editing Environments", EditorStyles.boldLabel); GUI.enabled = editorEnabled; { EditorGUI.BeginChangeCheck(); SceneAsset scene = EditorSettings.prefabRegularEnvironment; scene = (SceneAsset)EditorGUILayout.ObjectField("Regular Environment", scene, typeof(SceneAsset), false); if (EditorGUI.EndChangeCheck()) { EditorSettings.prefabRegularEnvironment = scene; } } { EditorGUI.BeginChangeCheck(); SceneAsset scene = EditorSettings.prefabUIEnvironment; scene = (SceneAsset)EditorGUILayout.ObjectField("UI Environment", scene, typeof(SceneAsset), false); if (EditorGUI.EndChangeCheck()) { EditorSettings.prefabUIEnvironment = scene; } } GUILayout.Space(10); GUI.enabled = true; GUILayout.Label(Content.graphics, EditorStyles.boldLabel); GUI.enabled = editorEnabled; EditorGUI.BeginChangeCheck(); bool showRes = LightmapVisualization.showResolution; showRes = EditorGUILayout.Toggle(Content.showLightmapResolutionOverlay, showRes); if (EditorGUI.EndChangeCheck()) { LightmapVisualization.showResolution = showRes; } GUILayout.Space(10); GUI.enabled = true; GUILayout.Label(Content.spritePacker, EditorStyles.boldLabel); GUI.enabled = editorEnabled; index = Mathf.Clamp((int)EditorSettings.spritePackerMode, 0, spritePackerPopupList.Length - 1); CreatePopupMenu(Content.mode.text, spritePackerPopupList, index, SetSpritePackerMode); if (EditorSettings.spritePackerMode == SpritePackerMode.AlwaysOn || EditorSettings.spritePackerMode == SpritePackerMode.BuildTimeOnly) { index = Mathf.Clamp((int)(EditorSettings.spritePackerPaddingPower - 1), 0, 2); CreatePopupMenu("Padding Power (Legacy Sprite Packer)", spritePackerPaddingPowerPopupList, index, SetSpritePackerPaddingPower); } DoProjectGenerationSettings(); DoEtcTextureCompressionSettings(); DoLineEndingsSettings(); DoStreamingSettings(); DoShaderCompilationSettings(); serializedObject.ApplyModifiedProperties(); LoadEditorUserSettings(); m_EditorUserSettings.ApplyModifiedProperties(); }