diff --git a/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkImporterEditor.cs b/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkImporterEditor.cs
index 2ff58af4..fe4317ee 100644
--- a/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkImporterEditor.cs
+++ b/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkImporterEditor.cs
@@ -1,5 +1,7 @@
using System.Collections.Generic;
+using System.IO;
using System.Linq;
+using LDtkUnity.InternalBridge;
using UnityEditor;
using UnityEngine;
@@ -24,7 +26,8 @@ internal abstract class LDtkImporterEditor : ScriptedImporterEditor
protected LDtkSectionDependencies SectionDependencies;
private SerializedProperty _reimportOnDependencyChangedProp;
- private readonly GUIContent _reimportOnDependencyChanged = new GUIContent
+
+ private static readonly GUIContent ReimportOnDependencyChanged = new GUIContent
{
text = "Depend On Dependencies",
tooltip = "Controls whether this project/level should be reimported when any of the dependencies are changed. (ex. saved changes to a prefab)\n" +
@@ -100,7 +103,60 @@ protected static void DrawTextBox(string msg = null, MessageType type = MessageT
public void DrawDependenciesProperty()
{
- EditorGUILayout.PropertyField(_reimportOnDependencyChangedProp, _reimportOnDependencyChanged);
+ EditorGUILayout.PropertyField(_reimportOnDependencyChangedProp, ReimportOnDependencyChanged);
+ }
+
+ public void DrawProfilerButton()
+ {
+ if (serializedObject.isEditingMultipleObjects)
+ {
+ return;
+ }
+
+ //bool defined = LDtkScriptingDefines.IsProfilingEnabled();
+
+ string fileName = Path.GetFileName(Importer.assetPath);
+ string pathToSample = LDtkProfiler.GetOutputFilePath(fileName);
+ bool exists = File.Exists(pathToSample);
+
+ string FigureOutText()
+ {
+ string firstSentence = "Opens the profiler window with this file's sampled profiler recording. Make sure to reimport to get the latest sample.";
+ if (!exists)
+ {
+ return firstSentence + "\n\nNo profiler sample exists. Enable the profiler define in the LDtkUnity project settings and reimport to generate one.";
+ }
+
+ return firstSentence;
+ }
+
+ GUIContent profilerButtonContent = new GUIContent
+ {
+ text = "View Sample",
+ tooltip = FigureOutText(),
+ image = LDtkIconUtility.GetUnityIcon("UnityEditor.ProfilerWindow", ""),
+ };
+
+ using (new LDtkGUIEnabledScope(exists))
+ {
+ GUILayout.BeginHorizontal();
+ GUILayout.FlexibleSpace();
+ bool pressed = GUILayout.Button(profilerButtonContent);
+ GUILayout.EndHorizontal();
+
+ if (!pressed)
+ {
+ return;
+ }
+ }
+
+ if (!exists)
+ {
+ Debug.LogError($"No profiler sample exists for this import. Maybe the file wasn't generated yet.\n{pathToSample}");
+ return;
+ }
+
+ InternalEditorBridge.ShowAndLoadProfilerSample(pathToSample);
}
public void DrawLogEntries()
diff --git a/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkLevelImporterEditor.cs b/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkLevelImporterEditor.cs
index cf44448a..3c54c788 100644
--- a/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkLevelImporterEditor.cs
+++ b/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkLevelImporterEditor.cs
@@ -54,6 +54,8 @@ public override void OnInspectorGUI()
try
{
+ DrawProfilerButton();
+ LDtkEditorGUIUtility.DrawDivider();
DrawLogEntries();
TryDrawProjectReferenceButton();
DrawDependenciesProperty();
diff --git a/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkProjectImporterEditor.cs b/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkProjectImporterEditor.cs
index 07cb1c84..852bb4f9 100644
--- a/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkProjectImporterEditor.cs
+++ b/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkProjectImporterEditor.cs
@@ -150,8 +150,8 @@ private void ShowGUI()
//todo disabled for now. Currently doesn't work perfectly as expected
//DrawExportButton();
-
-
+ DrawProfilerButton();
+ LDtkEditorGUIUtility.DrawDivider();
_sectionMain.SetJson(data);
_commandUpdater.TryDrawFixButton(data);
diff --git a/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkSubImporterEditor.cs b/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkSubImporterEditor.cs
index ba84c288..ef232747 100644
--- a/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkSubImporterEditor.cs
+++ b/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkSubImporterEditor.cs
@@ -3,6 +3,9 @@
namespace LDtkUnity.Editor
{
+ ///
+ /// A sub asset would be anything that isn't the project, like levels and tileset files.
+ ///
internal abstract class LDtkSubImporterEditor : LDtkImporterEditor
{
private static readonly GUIContent ReimportProjectButton = new GUIContent()
diff --git a/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkTilesetImporterEditor.cs b/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkTilesetImporterEditor.cs
index c1b551de..c30792f7 100644
--- a/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkTilesetImporterEditor.cs
+++ b/Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkTilesetImporterEditor.cs
@@ -71,6 +71,8 @@ public override void OnInspectorGUI()
return;
}
+ DrawProfilerButton();
+ LDtkEditorGUIUtility.DrawDivider();
DrawLogEntries();
try
@@ -87,10 +89,9 @@ public override void OnInspectorGUI()
}
DrawDependenciesProperty();
-
DoOpenSpriteEditorButton();
-
SectionDependencies.Draw();
+
}
catch (Exception e)
{
diff --git a/Assets/LDtkUnity/Editor/Utility/LDtkScriptingDefines.cs b/Assets/LDtkUnity/Editor/Utility/LDtkScriptingDefines.cs
index 50468577..ce8d53f5 100644
--- a/Assets/LDtkUnity/Editor/Utility/LDtkScriptingDefines.cs
+++ b/Assets/LDtkUnity/Editor/Utility/LDtkScriptingDefines.cs
@@ -31,16 +31,28 @@ public static void PreprocessorAddRemoveGui()
}
}
- private static void DrawButton()
+ public static bool IsProfilingEnabled()
{
BuildTargetGroup current = EditorUserBuildSettings.selectedBuildTargetGroup;
+ string currentDefines = GetDefines(current);
+ return currentDefines.Contains(DEFINE);
+ }
+ private static string GetDefines(BuildTargetGroup current)
+ {
#if UNITY_2021_2_OR_NEWER
NamedBuildTarget group = NamedBuildTarget.FromBuildTargetGroup(current);
string currentDefines = PlayerSettings.GetScriptingDefineSymbols(group);
#else
string currentDefines = PlayerSettings.GetScriptingDefineSymbolsForGroup(current);
#endif
+ return currentDefines;
+ }
+
+ private static void DrawButton()
+ {
+ BuildTargetGroup current = EditorUserBuildSettings.selectedBuildTargetGroup;
+ string currentDefines = GetDefines(current);
GUILayoutOption width = GUILayout.Width(180);
if (currentDefines.Contains(DEFINE))
@@ -67,11 +79,13 @@ private static void DrawButton()
void SetNewDefines(string newDefines)
{
#if UNITY_2021_2_OR_NEWER
- PlayerSettings.SetScriptingDefineSymbols(group, newDefines);
+ PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(current), newDefines);
#else
PlayerSettings.SetScriptingDefineSymbolsForGroup(current, newDefines);
#endif
}
}
+
+
}
}
\ No newline at end of file
diff --git a/Assets/LDtkUnity/InternalBridge/InternalEditorBridge.cs b/Assets/LDtkUnity/InternalBridge/InternalEditorBridge.cs
index 0fe71325..5fbcbe8d 100644
--- a/Assets/LDtkUnity/InternalBridge/InternalEditorBridge.cs
+++ b/Assets/LDtkUnity/InternalBridge/InternalEditorBridge.cs
@@ -1,8 +1,10 @@
using System;
using System.Reflection;
using UnityEditor;
+using UnityEditor.Profiling;
using UnityEditor.ShortcutManagement;
using UnityEditor.U2D.Sprites;
+using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Events;
@@ -156,6 +158,15 @@ public static GameObject InstantiateForAnimatorPreview(UnityEngine.Object origin
{
return EditorUtility.InstantiateForAnimatorPreview(original);
}
+
+ public static void ShowAndLoadProfilerSample(string filename)
+ {
+ ProfilerWindow window = EditorWindow.GetWindow(false);
+ if (ProfilerDriver.LoadProfile(filename, false))
+ {
+ window.SetRecordingEnabled(false);
+ }
+ }
public static void AddManagedGameObject(this PreviewRenderUtility scene, GameObject go) => scene.AddManagedGO(go);
}
diff --git a/Assets/LDtkUnity/Runtime/Tools/LDtkProfiler.cs b/Assets/LDtkUnity/Runtime/Tools/LDtkProfiler.cs
index 0b59708f..6643f759 100644
--- a/Assets/LDtkUnity/Runtime/Tools/LDtkProfiler.cs
+++ b/Assets/LDtkUnity/Runtime/Tools/LDtkProfiler.cs
@@ -44,6 +44,13 @@ public static void BeginWriting(string path)
Profiler.BeginSample(path);
}
+ public static string GetOutputFilePath(string assetName)
+ {
+ string directory = $"{Path.GetDirectoryName(Application.dataPath)}/Profiler";
+ string fullPath = $"{directory}/{assetName}.raw";
+ return fullPath;
+ }
+
[Conditional("LDTK_ENABLE_PROFILER")]
public static void EndWriting()
{