Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: package event listener #177

Merged
merged 4 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions Editor/Analytics/AmplitudeEditorLogger.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)
rYuuk marked this conversation as resolved.
Show resolved Hide resolved
{
LogEvent(EventName.INSTALL_PACKAGE, new Dictionary<string, object>
{
{ "id", packageInfo.Id },
{ "name", packageInfo.Name },
{ "url", packageInfo.Url },
rYuuk marked this conversation as resolved.
Show resolved Hide resolved
{ "id", id },
{ "name", name },
});
}

Expand Down
4 changes: 2 additions & 2 deletions Editor/Analytics/IAnalyticsEditorLogger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ReadyPlayerMe.Core.Editor.Models;
using ReadyPlayerMe.Core.Editor;

namespace ReadyPlayerMe.Core.Analytics
{
Expand Down Expand Up @@ -33,6 +33,6 @@ public interface IAnalyticsEditorLogger
void LogOpenAvatarCreatorDocumentation();
void LogOpenOptimizationDocumentation();
void LogAvatarCreatorSampleImported();
void LogPackageInstalled(PackageCoreInfo packageInfo);
void LogPackageInstalled(string id, string name);
}
}
3 changes: 0 additions & 3 deletions Editor/Utils/PackageManager/Models.meta

This file was deleted.

11 changes: 0 additions & 11 deletions Editor/Utils/PackageManager/Models/PackageCoreInfo.cs

This file was deleted.

3 changes: 0 additions & 3 deletions Editor/Utils/PackageManager/Models/PackageCoreInfo.cs.meta

This file was deleted.

27 changes: 17 additions & 10 deletions Editor/Utils/PackageManager/PackageManagerEventListener.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
using System.Linq;
using System;
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
{
public static event Action<string> OnPackageImported;

[InitializeOnLoadMethod]
static void Initialize()
{
Events.registeringPackages += OnPackagesInstalled;
Events.registeredPackages += OnPackagesInstalled;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

~PackageManagerEventListener()
{
Events.registeredPackages -= OnPackagesInstalled;
}

static void OnPackagesInstalled(PackageRegistrationEventArgs packageRegistrationEventArgs)
{
packageRegistrationEventArgs.added
.Select(package => new PackageCoreInfo
{
Id = package.packageId,
Name = package.displayName,
})
.ToList()
.ForEach(AnalyticsEditorLogger.EventLogger.LogPackageInstalled);
.ForEach(packageInfo =>
{
OnPackageImported?.Invoke(packageInfo.name);
AnalyticsEditorLogger.EventLogger.LogPackageInstalled(packageInfo.name, packageInfo.packageId);
});
}
}
}