From aeaf1bd6f82528150590cf210bad12a7a075656e Mon Sep 17 00:00:00 2001 From: Robin <1121080+rYuuk@users.noreply.github.com> Date: Fri, 1 Dec 2023 11:40:09 +0530 Subject: [PATCH 1/4] feat: refactor PackageManagerEventListener --- Editor/Analytics/AmplitudeEditorLogger.cs | 8 +++----- Editor/Analytics/IAnalyticsEditorLogger.cs | 4 ++-- Editor/Utils/PackageManager/Models.meta | 3 --- .../Utils/PackageManager/Models/PackageCoreInfo.cs | 11 ----------- .../PackageManager/Models/PackageCoreInfo.cs.meta | 3 --- .../PackageManager/PackageManagerEventListener.cs | 14 ++++++-------- 6 files changed, 11 insertions(+), 32 deletions(-) delete mode 100644 Editor/Utils/PackageManager/Models.meta delete mode 100644 Editor/Utils/PackageManager/Models/PackageCoreInfo.cs delete mode 100644 Editor/Utils/PackageManager/Models/PackageCoreInfo.cs.meta diff --git a/Editor/Analytics/AmplitudeEditorLogger.cs b/Editor/Analytics/AmplitudeEditorLogger.cs index 0b83a605..5ba4e901 100644 --- a/Editor/Analytics/AmplitudeEditorLogger.cs +++ b/Editor/Analytics/AmplitudeEditorLogger.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using ReadyPlayerMe.Core.Editor; -using ReadyPlayerMe.Core.Editor.Models; using UnityEditor; using UnityEngine; using static ReadyPlayerMe.Core.Analytics.Constants; @@ -234,13 +233,12 @@ public void LogAvatarCreatorSampleImported() LogEvent(EventName.AVATAR_CREATOR_SAMPLE_IMPORTED); } - public void LogPackageInstalled(PackageCoreInfo packageInfo) + public void LogPackageInstalled(string id, string name) { LogEvent(EventName.INSTALL_PACKAGE, new Dictionary { - { "id", packageInfo.Id }, - { "name", packageInfo.Name }, - { "url", packageInfo.Url }, + { "id", id }, + { "name", name }, }); } diff --git a/Editor/Analytics/IAnalyticsEditorLogger.cs b/Editor/Analytics/IAnalyticsEditorLogger.cs index 939361b4..10e6a03c 100644 --- a/Editor/Analytics/IAnalyticsEditorLogger.cs +++ b/Editor/Analytics/IAnalyticsEditorLogger.cs @@ -1,4 +1,4 @@ -using ReadyPlayerMe.Core.Editor.Models; +using ReadyPlayerMe.Core.Editor; namespace ReadyPlayerMe.Core.Analytics { @@ -33,6 +33,6 @@ public interface IAnalyticsEditorLogger void LogOpenAvatarCreatorDocumentation(); void LogOpenOptimizationDocumentation(); void LogAvatarCreatorSampleImported(); - void LogPackageInstalled(PackageCoreInfo packageInfo); + void LogPackageInstalled(string id, string name); } } diff --git a/Editor/Utils/PackageManager/Models.meta b/Editor/Utils/PackageManager/Models.meta deleted file mode 100644 index b13083ad..00000000 --- a/Editor/Utils/PackageManager/Models.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: d97bf380b02e463ca778a0b3cc8aaf5a -timeCreated: 1699351186 \ No newline at end of file diff --git a/Editor/Utils/PackageManager/Models/PackageCoreInfo.cs b/Editor/Utils/PackageManager/Models/PackageCoreInfo.cs deleted file mode 100644 index 9a2e89b3..00000000 --- a/Editor/Utils/PackageManager/Models/PackageCoreInfo.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace ReadyPlayerMe.Core.Editor.Models -{ - public class PackageCoreInfo - { - public string Id { get; set; } - - public string Name { get; set; } - - public string Url { get; set; } - } -} diff --git a/Editor/Utils/PackageManager/Models/PackageCoreInfo.cs.meta b/Editor/Utils/PackageManager/Models/PackageCoreInfo.cs.meta deleted file mode 100644 index 549b673e..00000000 --- a/Editor/Utils/PackageManager/Models/PackageCoreInfo.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 4a630c9d56da4254a50add08ead9df46 -timeCreated: 1699351210 \ No newline at end of file diff --git a/Editor/Utils/PackageManager/PackageManagerEventListener.cs b/Editor/Utils/PackageManager/PackageManagerEventListener.cs index 828825db..42f34581 100644 --- a/Editor/Utils/PackageManager/PackageManagerEventListener.cs +++ b/Editor/Utils/PackageManager/PackageManagerEventListener.cs @@ -1,11 +1,11 @@ using System.Linq; using ReadyPlayerMe.Core.Analytics; -using ReadyPlayerMe.Core.Editor.Models; using UnityEditor; using UnityEditor.PackageManager; + namespace ReadyPlayerMe.Core.Editor { - public class PackageManagerEventListener + public abstract class PackageManagerEventListener { [InitializeOnLoadMethod] static void Initialize() @@ -16,13 +16,11 @@ static void Initialize() static void OnPackagesInstalled(PackageRegistrationEventArgs packageRegistrationEventArgs) { packageRegistrationEventArgs.added - .Select(package => new PackageCoreInfo - { - Id = package.packageId, - Name = package.displayName, - }) .ToList() - .ForEach(AnalyticsEditorLogger.EventLogger.LogPackageInstalled); + .ForEach(x => + { + AnalyticsEditorLogger.EventLogger.LogPackageInstalled(x.name, x.packageId); + }); } } } From acb1601892132dbfae391fb33067e36443594909 Mon Sep 17 00:00:00 2001 From: Robin <1121080+rYuuk@users.noreply.github.com> Date: Fri, 1 Dec 2023 12:01:43 +0530 Subject: [PATCH 2/4] feat: add check for reaplayerme in the package id --- .../PackageManager/PackageManagerEventListener.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Editor/Utils/PackageManager/PackageManagerEventListener.cs b/Editor/Utils/PackageManager/PackageManagerEventListener.cs index 42f34581..43c1575e 100644 --- a/Editor/Utils/PackageManager/PackageManagerEventListener.cs +++ b/Editor/Utils/PackageManager/PackageManagerEventListener.cs @@ -7,20 +7,26 @@ namespace ReadyPlayerMe.Core.Editor { public abstract class PackageManagerEventListener { + private const string REQUIRED_KEYWORD = "readyplayerme"; + [InitializeOnLoadMethod] static void Initialize() { Events.registeringPackages += OnPackagesInstalled; } + + ~PackageManagerEventListener() + { + Events.registeringPackages -= OnPackagesInstalled; + } static void OnPackagesInstalled(PackageRegistrationEventArgs packageRegistrationEventArgs) { packageRegistrationEventArgs.added + .Where(packageInfo => packageInfo.packageId.Contains(REQUIRED_KEYWORD)) .ToList() - .ForEach(x => - { - AnalyticsEditorLogger.EventLogger.LogPackageInstalled(x.name, x.packageId); - }); + .ForEach(packageInfo => + AnalyticsEditorLogger.EventLogger.LogPackageInstalled(packageInfo.name, packageInfo.packageId)); } } } From 2aa92399a59022f446d0eb261fbab3d3ffa1b506 Mon Sep 17 00:00:00 2001 From: Robin <1121080+rYuuk@users.noreply.github.com> Date: Fri, 1 Dec 2023 14:21:43 +0530 Subject: [PATCH 3/4] feat: add package imported event --- .../PackageManagerEventListener.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Editor/Utils/PackageManager/PackageManagerEventListener.cs b/Editor/Utils/PackageManager/PackageManagerEventListener.cs index 43c1575e..1045856b 100644 --- a/Editor/Utils/PackageManager/PackageManagerEventListener.cs +++ b/Editor/Utils/PackageManager/PackageManagerEventListener.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using ReadyPlayerMe.Core.Analytics; using UnityEditor; using UnityEditor.PackageManager; @@ -8,16 +9,17 @@ namespace ReadyPlayerMe.Core.Editor public abstract class PackageManagerEventListener { private const string REQUIRED_KEYWORD = "readyplayerme"; - + public static event Action OnPackageImported; + [InitializeOnLoadMethod] static void Initialize() { - Events.registeringPackages += OnPackagesInstalled; + Events.registeredPackages += OnPackagesInstalled; } ~PackageManagerEventListener() { - Events.registeringPackages -= OnPackagesInstalled; + Events.registeredPackages -= OnPackagesInstalled; } static void OnPackagesInstalled(PackageRegistrationEventArgs packageRegistrationEventArgs) @@ -25,8 +27,11 @@ static void OnPackagesInstalled(PackageRegistrationEventArgs packageRegistration packageRegistrationEventArgs.added .Where(packageInfo => packageInfo.packageId.Contains(REQUIRED_KEYWORD)) .ToList() - .ForEach(packageInfo => - AnalyticsEditorLogger.EventLogger.LogPackageInstalled(packageInfo.name, packageInfo.packageId)); + .ForEach(packageInfo => + { + OnPackageImported?.Invoke(packageInfo.name); + AnalyticsEditorLogger.EventLogger.LogPackageInstalled(packageInfo.name, packageInfo.packageId); + }); } } } From e8f6b84cea49b7de1ab47b02f4fd4a6ab7ab8367 Mon Sep 17 00:00:00 2001 From: Robin <1121080+rYuuk@users.noreply.github.com> Date: Fri, 1 Dec 2023 14:49:00 +0530 Subject: [PATCH 4/4] chore: remove filter --- Editor/Utils/PackageManager/PackageManagerEventListener.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Editor/Utils/PackageManager/PackageManagerEventListener.cs b/Editor/Utils/PackageManager/PackageManagerEventListener.cs index 1045856b..871e5a0d 100644 --- a/Editor/Utils/PackageManager/PackageManagerEventListener.cs +++ b/Editor/Utils/PackageManager/PackageManagerEventListener.cs @@ -8,7 +8,6 @@ namespace ReadyPlayerMe.Core.Editor { public abstract class PackageManagerEventListener { - private const string REQUIRED_KEYWORD = "readyplayerme"; public static event Action OnPackageImported; [InitializeOnLoadMethod] @@ -25,7 +24,6 @@ static void Initialize() static void OnPackagesInstalled(PackageRegistrationEventArgs packageRegistrationEventArgs) { packageRegistrationEventArgs.added - .Where(packageInfo => packageInfo.packageId.Contains(REQUIRED_KEYWORD)) .ToList() .ForEach(packageInfo => {