diff --git a/Assets/Builds.meta b/Assets/Builds.meta deleted file mode 100644 index 8754605..0000000 --- a/Assets/Builds.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 344d15cb1e8bb3d4f938bacdd1ca85b9 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Builds/Core_1.3.unitypackage.meta b/Assets/Builds/Core_1.3.unitypackage.meta deleted file mode 100644 index 9960811..0000000 --- a/Assets/Builds/Core_1.3.unitypackage.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 146af9f28785df94e96dd4051f3c1f0e -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Builds/Core_1.4.unitypackage.meta b/Assets/Builds/Core_1.4.unitypackage.meta deleted file mode 100644 index 61f0751..0000000 --- a/Assets/Builds/Core_1.4.unitypackage.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 63abef4a9c33fec46880ba4a9d4a2499 -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/CoreCustumization/Scripts/RewardedButton.cs b/Assets/Core/Ads/RewardedButton.cs similarity index 100% rename from Assets/CoreCustumization/Scripts/RewardedButton.cs rename to Assets/Core/Ads/RewardedButton.cs diff --git a/Assets/CoreCustumization/Scripts/RewardedButton.cs.meta b/Assets/Core/Ads/RewardedButton.cs.meta similarity index 100% rename from Assets/CoreCustumization/Scripts/RewardedButton.cs.meta rename to Assets/Core/Ads/RewardedButton.cs.meta diff --git a/Assets/Core/Tools/Editor/UnusedAssetsMarker.cs b/Assets/Core/Tools/Editor/UnusedAssetsMarker.cs new file mode 100644 index 0000000..533d31e --- /dev/null +++ b/Assets/Core/Tools/Editor/UnusedAssetsMarker.cs @@ -0,0 +1,178 @@ +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; +using UnityEditor; +using UnityEditor.SceneManagement; +using UnityEngine; +using UnityEngine.SceneManagement; + +[InitializeOnLoad] +public static class UnusedAssetsMarker +{ + private struct FolderInfo + { + public int usedCount; + public int unusedCount; + } + + private static List _usedAssets = new List(); + private static List _allAssets = new List(); + + private static Dictionary _foldersInfo = new Dictionary(); + private static Dictionary _assetsInfo = new Dictionary(); + + static UnusedAssetsMarker() + { + ResearchDependecies(); + + EditorApplication.projectWindowItemOnGUI += DrawAssetDetails; + } + + [MenuItem("Core/Research unused assets", false, 0)] + private static void ResearchDependecies() + { + _usedAssets = new List(); + _allAssets = AssetDatabase.GetAllAssetPaths().ToList(); + _foldersInfo = new Dictionary(); + + for (int i = 0; i < EditorBuildSettings.scenes.Length; i++) + { + string scenePath = EditorBuildSettings.scenes[i].path; + string[] dependencies = AssetDatabase.GetDependencies(scenePath); + _usedAssets.AddRange(dependencies); + } + + Object[] resources = Resources.LoadAll(""); + + for (int i = 0; i < resources.Length; i++) + { + _usedAssets.AddRange(AssetDatabase.GetDependencies(AssetDatabase.GetAssetPath(resources[i]))); + } + } + + private static void DrawAssetDetails(string guid, Rect rect) + { + string assetPath = AssetDatabase.GUIDToAssetPath(guid); + + if (Application.isPlaying || Event.current.type != EventType.Repaint || IsInvalidFile(assetPath) || assetPath == "Assets") + { + GUI.backgroundColor = Color.white; + return; + } + + if (AssetDatabase.IsValidFolder(assetPath)) + { + if (IsMainListAsset(rect)) + { + int usedCount = 0; + int unusedCount = 0; + + if (_foldersInfo.ContainsKey(assetPath)) + { + usedCount = _foldersInfo[assetPath].usedCount; + unusedCount = _foldersInfo[assetPath].unusedCount; + } + else + { + string[] assetsInFolder = _allAssets.Where(path => path.Contains(assetPath) && !AssetDatabase.IsValidFolder(path)).ToArray(); + + for (int i = 0; i < assetsInFolder.Length; i++) + { + if (IsAssetsUsed(assetsInFolder[i]) || IsInvalidFile(assetsInFolder[i])) + usedCount++; + else + unusedCount++; + } + + _foldersInfo.Add(assetPath, new FolderInfo { usedCount = usedCount, unusedCount = unusedCount }); + } + + GUIStyle style = new GUIStyle(EditorStyles.label); + style.alignment = TextAnchor.MiddleRight; + + Rect newRect = rect; + newRect.x += rect.width - 305; + newRect.width = 200; + + GUI.Label(newRect, $"Used assets count: {usedCount}"); + + newRect = rect; + newRect.x += rect.width - 155; + newRect.width = 200; + + GUI.Label(newRect, $"Unused assets count: {unusedCount}"); + } + + GUI.backgroundColor = Color.white; + return; + } + + if (AssetDatabase.LoadAssetAtPath(assetPath) != null) { + + bool isUsed = false; + + if (_assetsInfo.ContainsKey(assetPath)) + isUsed = _assetsInfo[assetPath]; + else + { + isUsed = IsAssetsUsed(assetPath); + _assetsInfo.Add(assetPath, isUsed); + } + + if (isUsed) + { + GUI.backgroundColor = Color.white; + return; + } + + if (IsMainListAsset(rect)) + { + Rect newRect = rect; + newRect.x += rect.width - 55; + newRect.width = 100; + + GUIStyle style = new GUIStyle(EditorStyles.label); + style.alignment = TextAnchor.MiddleRight; + + GUI.Label(newRect, "Unused"); + } + + if (isUsed) + GUI.color = Color.clear; + else + GUI.color = Color.red; + + GUI.Box(rect, ""); + + GUI.color = Color.white; + } + } + + private static bool IsMainListAsset(Rect rect) + { + if (rect.height > 20) + return false; + + if (rect.x > 16) + return false; + + return true; + } + + private static bool IsInvalidFile(string path) + { + return + Path.GetExtension(path) == ".cs" || + Path.GetExtension(path) == ".dll" || + Path.GetExtension(path) == ".unity" || + Regex.IsMatch(path, "[\\/\\\\]Editor[\\/\\\\]") == true || + Regex.IsMatch(path, "[\\/\\\\]Resources[\\/\\\\]") == true || + Regex.IsMatch(path, "[\\/\\\\]Plugins[\\/\\\\]") == true; + } + + private static bool IsAssetsUsed(string path) + { + return _usedAssets.Contains(path); + } +} diff --git a/Assets/Core/Tools/Editor/UnusedAssetsMarker.cs.meta b/Assets/Core/Tools/Editor/UnusedAssetsMarker.cs.meta new file mode 100644 index 0000000..3e5ca66 --- /dev/null +++ b/Assets/Core/Tools/Editor/UnusedAssetsMarker.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 58c6268c557aa8c4fa61e6db42d2af44 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Core/Window/Editor/CoreSettingsWindow.cs b/Assets/Core/Window/Editor/CoreSettingsWindow.cs index 2c3a975..e37a5c6 100644 --- a/Assets/Core/Window/Editor/CoreSettingsWindow.cs +++ b/Assets/Core/Window/Editor/CoreSettingsWindow.cs @@ -24,7 +24,7 @@ namespace Core.Settings private bool m_IsInCompilation = false; - [MenuItem("Window/Core Settings", false, -1000)] + [MenuItem("Core/Settings", false, 1000)] public static void Init() { window = EditorWindow.GetWindow("Core Settings", typeof(SceneView));