app center;增加發送ping的秒

This commit is contained in:
Caiyanpeng committed 2021-11-12 16:21:13 +08:00
1 parent 1bd1ffdb5a
commit d754ff3b15
719 files changed
+34172 -2875

No files matched your search

@@ -0,0 +1,27 @@
using UnityEngine;
using UnityEditor;
namespace AppCenterEditor
{
public class AppCenterEditorHeader : Editor
{
public static void DrawHeader(float progress = 0f)
{
if (AppCenterEditorHelper.uiStyle == null)
return;
using (new AppCenterGuiFieldHelper.UnityHorizontal(AppCenterEditorHelper.uiStyle.GetStyle("gpStyleHeaderWrapper")))
{
//using Begin Vertical as our container.
using (new AppCenterGuiFieldHelper.UnityHorizontal(GUILayout.Height(52)))
{
EditorGUILayout.LabelField("", AppCenterEditorHelper.uiStyle.GetStyle("acLogo"), GUILayout.MaxHeight(60), GUILayout.Width(60));
EditorGUILayout.LabelField("App Center", AppCenterEditorHelper.uiStyle.GetStyle("gpStyleGray2"), GUILayout.MinHeight(52));
//end the vertical container
}
}
ProgressBar.Draw();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 82fe5ebbfbd6e4aa980585a4c5aeb0f0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,39 @@
using UnityEngine;
using UnityEditor;
namespace AppCenterEditor
{
public class AppCenterEditorMenu : Editor
{
#region panel variables
internal enum MenuStates
{
Sdks = 0,
}
internal static MenuStates _menuState = MenuStates.Sdks;
#endregion
public static void DrawMenu()
{
if (AppCenterEditorSDKTools.IsInstalled)
_menuState = (MenuStates)AppCenterEditorPrefsSO.Instance.curMainMenuIdx;
var sdksButtonStyle = AppCenterEditorHelper.uiStyle.GetStyle("textButton");
if (_menuState == MenuStates.Sdks)
sdksButtonStyle = AppCenterEditorHelper.uiStyle.GetStyle("textButton_selected");
using (new AppCenterGuiFieldHelper.UnityHorizontal(AppCenterEditorHelper.uiStyle.GetStyle("gpStyleGray1"), GUILayout.Height(25), GUILayout.ExpandWidth(true)))
{
GUILayout.Space(5);
if (GUILayout.Button("SDK", sdksButtonStyle, GUILayout.MaxWidth(35)))
{
}
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 094bc528ca3754d17bfe99514da8eef3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,602 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace AppCenterEditor
{
public class AppCenterEditorSDKTools : Editor
{
public enum SDKState
{
SDKNotInstalled,
SDKNotInstalledAndInstalling,
SDKNotFull,
SDKNotFullAndInstalling,
SDKIsFull
}
public static bool IsInstalled { get { return AreSomePackagesInstalled(); } }
public static bool IsFullSDK { get { return CheckIfAllPackagesInstalled(); } }
public static bool IsInstalling { get; set; }
public static bool IsUpgrading { get; set; }
public static string LatestSdkVersion { get; private set; }
public static UnityEngine.Object SdkFolder { get; private set; }
public static string InstalledSdkVersion { get; private set; }
public static GUIStyle TitleStyle { get { return new GUIStyle(AppCenterEditorHelper.uiStyle.GetStyle("titleLabel")); } }
private static Type appCenterSettingsType = null;
private static bool isInitialized; // used to check once, gets reset after each compile
private static UnityEngine.Object _previousSdkFolderPath;
private static bool sdkFolderNotFound;
private static int angle = 0;
public static SDKState GetSDKState()
{
if (!IsInstalled)
{
if (IsInstalling)
{
return SDKState.SDKNotInstalledAndInstalling;
}
else
{
return SDKState.SDKNotInstalled;
}
}
//SDK installed.
if (IsFullSDK)
{
return SDKState.SDKIsFull;
}
//SDK is not full.
if (IsInstalling)
{
return SDKState.SDKNotFullAndInstalling;
}
else
{
return SDKState.SDKNotFull;
}
}
public static void DrawSdkPanel()
{
if (!isInitialized)
{
//SDK is installed.
CheckSdkVersion();
isInitialized = true;
GetLatestSdkVersion();
SdkFolder = FindSdkAsset();
if (SdkFolder != null)
{
AppCenterEditorPrefsSO.Instance.SdkPath = AssetDatabase.GetAssetPath(SdkFolder);
// AppCenterEditorDataService.SaveEnvDetails();
}
}
ShowSdkInstallationPanel();
}
public static void DisplayPackagePanel(AppCenterSDKPackage sdkPackage)
{
using (new AppCenterGuiFieldHelper.UnityVertical(AppCenterEditorHelper.uiStyle.GetStyle("gpStyleGray1")))
{
using (new AppCenterGuiFieldHelper.UnityHorizontal(AppCenterEditorHelper.uiStyle.GetStyle("gpStyleClear")))
{
GUILayout.FlexibleSpace();
if (sdkPackage.IsInstalled)
{
sdkPackage.ShowPackageInstalledMenu();
}
else
{
sdkPackage.ShowPackageNotInstalledMenu();
}
GUILayout.FlexibleSpace();
}
}
}
private static void ShowSdkInstallationPanel()
{
sdkFolderNotFound = SdkFolder == null;
if (_previousSdkFolderPath != SdkFolder)
{
// something changed, better save the result.
_previousSdkFolderPath = SdkFolder;
AppCenterEditorPrefsSO.Instance.SdkPath = (AssetDatabase.GetAssetPath(SdkFolder));
//TODO: check if we need this?
// AppCenterEditorDataService.SaveEnvDetails();
sdkFolderNotFound = false;
}
SDKState SDKstate = GetSDKState();
using (new AppCenterGuiFieldHelper.UnityVertical(AppCenterEditorHelper.uiStyle.GetStyle("gpStyleGray1")))
{
switch (SDKstate)
{
case SDKState.SDKNotInstalled:
ShowNOSDKLabel();
ShowInstallButton();
break;
case SDKState.SDKNotInstalledAndInstalling:
ShowNOSDKLabel();
ShowInstallingButton();
break;
case SDKState.SDKNotFull:
ShowSdkInstalledLabel();
ShowFolderObject();
ShowInstallButton();
ShowRemoveButton();
break;
case SDKState.SDKNotFullAndInstalling:
ShowSdkInstalledLabel();
ShowFolderObject();
ShowInstallingButton();
ShowRemoveButton();
break;
case SDKState.SDKIsFull:
ShowSdkInstalledLabel();
ShowFolderObject();
ShowRemoveButton();
break;
}
}
}
public static void ShowUpgradePanel()
{
if (!sdkFolderNotFound)
{
using (new AppCenterGuiFieldHelper.UnityVertical(AppCenterEditorHelper.uiStyle.GetStyle("gpStyleGray1")))
{
string[] versionNumber = !string.IsNullOrEmpty(InstalledSdkVersion) ? InstalledSdkVersion.Split('.') : new string[0];
var numerical = 0;
bool isEmptyVersion = string.IsNullOrEmpty(InstalledSdkVersion) || versionNumber == null || versionNumber.Length == 0;
if (isEmptyVersion || (versionNumber.Length > 0 && int.TryParse(versionNumber[0], out numerical) && numerical < 0))
{
//older version of the SDK
using (new AppCenterGuiFieldHelper.UnityHorizontal(AppCenterEditorHelper.uiStyle.GetStyle("gpStyleClear")))
{
GUILayout.FlexibleSpace();
EditorGUILayout.LabelField("SDK is outdated. Consider upgrading to the get most features.", AppCenterEditorHelper.uiStyle.GetStyle("orTxt"));
GUILayout.FlexibleSpace();
}
}
var buttonWidth = 200;
GUILayout.Space(5);
if (ShowSDKUpgrade())
{
if (IsUpgrading)
{
using (new AppCenterGuiFieldHelper.UnityHorizontal(AppCenterEditorHelper.uiStyle.GetStyle("gpStyleClear")))
{
GUILayout.FlexibleSpace();
var image = DrawUtils.RotateImage(AssetDatabase.LoadAssetAtPath("Assets/AppCenterEditorExtensions/Editor/UI/Images/wheel.png", typeof(Texture2D)) as Texture2D, angle++);
GUILayout.Button(new GUIContent(" Upgrading to " + LatestSdkVersion, image), AppCenterEditorHelper.uiStyle.GetStyle("Button"), GUILayout.MaxWidth(buttonWidth), GUILayout.MinHeight(32));
GUILayout.FlexibleSpace();
}
}
else
{
using (new AppCenterGuiFieldHelper.UnityHorizontal(AppCenterEditorHelper.uiStyle.GetStyle("gpStyleClear")))
{
GUILayout.FlexibleSpace();
if (GUILayout.Button("Upgrade to " + LatestSdkVersion, AppCenterEditorHelper.uiStyle.GetStyle("Button"), GUILayout.MinHeight(32)))
{
IsUpgrading = true;
UpgradeSdk();
}
GUILayout.FlexibleSpace();
}
}
}
else
{
using (new AppCenterGuiFieldHelper.UnityHorizontal(AppCenterEditorHelper.uiStyle.GetStyle("gpStyleClear")))
{
GUILayout.FlexibleSpace();
EditorGUILayout.LabelField("You have the latest SDK!", TitleStyle, GUILayout.MinHeight(32));
GUILayout.FlexibleSpace();
}
}
GUILayout.Space(5);
using (new AppCenterGuiFieldHelper.UnityHorizontal(AppCenterEditorHelper.uiStyle.GetStyle("gpStyleClear")))
{
GUILayout.FlexibleSpace();
if (GUILayout.Button("VIEW RELEASE NOTES", AppCenterEditorHelper.uiStyle.GetStyle("textButton"), GUILayout.MinHeight(32), GUILayout.MinWidth(200)))
{
Application.OpenURL("https://github.com/Microsoft/AppCenter-SDK-Unity/releases");
}
GUILayout.FlexibleSpace();
}
}
}
}
private static void ShowRemoveButton()
{
if (!sdkFolderNotFound)
{
using (new AppCenterGuiFieldHelper.UnityHorizontal(AppCenterEditorHelper.uiStyle.GetStyle("gpStyleClear")))
{
GUILayout.FlexibleSpace();
if (GUILayout.Button("REMOVE SDK", AppCenterEditorHelper.uiStyle.GetStyle("textButton"), GUILayout.MinHeight(32), GUILayout.MinWidth(200)))
{
RemoveSdk();
}
GUILayout.FlexibleSpace();
}
}
}
private static void ShowFolderObject()
{
if (sdkFolderNotFound)
{
EditorGUILayout.LabelField("An SDK was detected, but we were unable to find the directory. Drag-and-drop the top-level App Center SDK folder below.",
AppCenterEditorHelper.uiStyle.GetStyle("orTxt"));
}
else
{
// This hack is needed to disable folder object and remove the blue border around it.
// Other UI is getting enabled later in the method.
GUI.enabled = false;
}
GUILayout.Space(5);
using (new AppCenterGuiFieldHelper.UnityHorizontal(AppCenterEditorHelper.uiStyle.GetStyle("gpStyleClearWithleftPad")))
{
GUILayout.FlexibleSpace();
SdkFolder = EditorGUILayout.ObjectField(SdkFolder, typeof(UnityEngine.Object), false, GUILayout.MaxWidth(200));
GUILayout.FlexibleSpace();
}
GUILayout.Space(5);
GUI.enabled = AppCenterEditor.IsGUIEnabled();
}
private static void ShowSdkInstalledLabel()
{
GUILayout.Space(5);
EditorGUILayout.LabelField(string.Format("SDK {0} is installed", string.IsNullOrEmpty(InstalledSdkVersion) ? Constants.UnknownVersion : InstalledSdkVersion),
TitleStyle, GUILayout.ExpandWidth(true));
GUILayout.Space(5);
}
private static void ShowInstallingButton()
{
var buttonWidth = 250;
GUILayout.Space(5);
using (new AppCenterGuiFieldHelper.UnityHorizontal(AppCenterEditorHelper.uiStyle.GetStyle("gpStyleEmpty")))
{
GUILayout.FlexibleSpace();
var image = DrawUtils.RotateImage(AssetDatabase.LoadAssetAtPath("Assets/AppCenterEditorExtensions/Editor/UI/Images/wheel.png", typeof(Texture2D)) as Texture2D, angle++);
GUILayout.Button(new GUIContent(" SDK is installing", image), AppCenterEditorHelper.uiStyle.GetStyle("Button"), GUILayout.MaxWidth(buttonWidth), GUILayout.MinHeight(32));
GUILayout.FlexibleSpace();
}
GUILayout.Space(5);
}
private static void ShowInstallButton()
{
var buttonWidth = 250;
GUILayout.Space(5);
using (new AppCenterGuiFieldHelper.UnityHorizontal(AppCenterEditorHelper.uiStyle.GetStyle("gpStyleEmpty")))
{
GUILayout.FlexibleSpace();
if (GUILayout.Button("Install all App Center SDK packages", AppCenterEditorHelper.uiStyle.GetStyle("Button"), GUILayout.MaxWidth(buttonWidth), GUILayout.MinHeight(32)))
{
IsInstalling = true;
try
{
PackagesInstaller.ImportLatestSDK(GetNotInstalledPackages(), LatestSdkVersion);
}
catch (Exception exception)
{
EdExLogger.LoggerInstance.LogError("Failed to install SDK packages: " + exception);
IsInstalling = false;
}
}
GUILayout.FlexibleSpace();
}
GUILayout.Space(5);
}
private static void ShowNOSDKLabel()
{
EditorGUILayout.LabelField("No SDK is installed.", TitleStyle, GUILayout.ExpandWidth(true));
GUILayout.Space(10);
}
public static bool AreSomePackagesInstalled()
{
return GetAppCenterSettings() != null;
}
public static List<AppCenterSDKPackage> GetNotInstalledPackages()
{
List<AppCenterSDKPackage> notInstalledPackages = new List<AppCenterSDKPackage>();
if (!IsInstalled)
{
notInstalledPackages.AddRange(AppCenterSDKPackage.SupportedPackages);
return notInstalledPackages;
}
foreach (var package in AppCenterSDKPackage.SupportedPackages)
{
if (!package.IsInstalled)
{
notInstalledPackages.Add(package);
}
}
return notInstalledPackages;
}
public static bool CheckIfAllPackagesInstalled()
{
foreach (var package in AppCenterSDKPackage.SupportedPackages)
{
if (!package.IsInstalled)
{
return false;
}
}
return GetAppCenterSettings() != null;
}
public static Type GetAppCenterSettings()
{
if (appCenterSettingsType == typeof(object))
return null; // Sentinel value to indicate that AppCenterSettings doesn't exist
if (appCenterSettingsType != null)
return appCenterSettingsType;
appCenterSettingsType = typeof(object); // Sentinel value to indicate that AppCenterSettings doesn't exist
var allAssemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (var assembly in allAssemblies)
foreach (var eachType in assembly.GetTypes())
if (eachType.Name == AppCenterEditorHelper.APPCENTER_SETTINGS_TYPENAME)
appCenterSettingsType = eachType;
//if (appCenterSettingsType == typeof(object))
// Debug.LogWarning("Should not have gotten here: " + allAssemblies.Length);
//else
// Debug.Log("Found Settings: " + allAssemblies.Length + ", " + appCenterSettingsType.Assembly.FullName);
return appCenterSettingsType == typeof(object) ? null : appCenterSettingsType;
}
private static bool ShowSDKUpgrade()
{
if (string.IsNullOrEmpty(LatestSdkVersion) || LatestSdkVersion == Constants.UnknownVersion)
{
return false;
}
if (string.IsNullOrEmpty(InstalledSdkVersion) || InstalledSdkVersion == Constants.UnknownVersion)
{
return true;
}
bool isOutdated = false;
foreach (var package in AppCenterSDKPackage.SupportedPackages)
{
if (package.IsInstalled)
{
string packageVersion = package.InstalledVersion;
bool isPackageOutdated = false;
if (string.IsNullOrEmpty(packageVersion) || packageVersion == Constants.UnknownVersion)
{
isPackageOutdated = true;
}
else
{
string[] current = packageVersion.Split('.');
string[] latest = LatestSdkVersion.Split('.');
isPackageOutdated = int.Parse(latest[0]) > int.Parse(current[0])
|| int.Parse(latest[1]) > int.Parse(current[1])
|| int.Parse(latest[2]) > int.Parse(current[2]);
}
if (isPackageOutdated)
{
isOutdated = true;
}
}
}
return isOutdated;
}
private static void UpgradeSdk()
{
if (EditorUtility.DisplayDialog("Confirm SDK Upgrade", "This action will remove the current App Center SDK and install the lastet version.", "Confirm", "Cancel"))
{
try
{
var installedPackages = AppCenterSDKPackage.GetInstalledPackages();
RemoveSdkBeforeUpdate();
PackagesInstaller.ImportLatestSDK(installedPackages, LatestSdkVersion, AppCenterEditorPrefsSO.Instance.SdkPath);
}
catch (Exception exception)
{
EdExLogger.LoggerInstance.LogError("Failed to upgrade SDK: " + exception);
IsUpgrading = false;
}
}
}
private static void RemoveSdkBeforeUpdate()
{
var skippedFiles = new[]
{
"AppCenterSettings.asset",
"AppCenterSettings.asset.meta",
"AppCenterSettingsAdvanced.asset",
"AppCenterSettingsAdvanced.asset.meta"
};
RemoveAndroidSettings();
var toDelete = new List<string>();
toDelete.AddRange(Directory.GetFiles(AppCenterEditorPrefsSO.Instance.SdkPath));
toDelete.AddRange(Directory.GetDirectories(AppCenterEditorPrefsSO.Instance.SdkPath));
foreach (var path in toDelete)
{
if (!skippedFiles.Contains(Path.GetFileName(path)))
{
FileUtil.DeleteFileOrDirectory(path);
}
}
}
public static void RemoveSdk(bool prompt = true)
{
if (prompt && !EditorUtility.DisplayDialog("Confirm SDK Removal", "This action will remove the current App Center SDK.", "Confirm", "Cancel"))
{
return;
}
EdExLogger.LoggerInstance.LogWithTimeStamp("Removing SDK...");
RemoveAndroidSettings();
if (FileUtil.DeleteFileOrDirectory(AppCenterEditorPrefsSO.Instance.SdkPath))
{
FileUtil.DeleteFileOrDirectory(AppCenterEditorPrefsSO.Instance.SdkPath + ".meta");
AppCenterEditor.RaiseStateUpdate(AppCenterEditor.EdExStates.OnSuccess, "App Center SDK removed.");
EdExLogger.LoggerInstance.LogWithTimeStamp("App Center SDK removed.");
// HACK for 5.4, AssetDatabase.Refresh(); seems to cause the install to fail.
if (prompt)
{
AssetDatabase.Refresh();
}
}
else
{
AppCenterEditor.RaiseStateUpdate(AppCenterEditor.EdExStates.OnError, "An unknown error occured and the App Center SDK could not be removed.");
}
}
private static void RemoveAndroidSettings()
{
if (Directory.Exists(Application.dataPath + "/Plugins/Android/res/values"))
{
var files = Directory.GetFiles(Application.dataPath + "/Plugins/Android/res/values", "appcenter-settings.xml*", SearchOption.AllDirectories);
foreach (var file in files)
{
FileUtil.DeleteFileOrDirectory(file);
}
}
}
private static void CheckSdkVersion()
{
if (!string.IsNullOrEmpty(InstalledSdkVersion))
return;
var packageTypes = new Dictionary<AppCenterSDKPackage, Type>();
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
try
{
foreach (var type in assembly.GetTypes())
{
if (type.FullName == Constants.WrapperSdkClassName)
{
foreach (var field in type.GetFields())
{
if (field.Name == Constants.WrapperSdkVersionFieldName)
{
InstalledSdkVersion = field.GetValue(field).ToString();
break;
}
}
}
else
{
foreach (var package in AppCenterSDKPackage.SupportedPackages)
{
if (type.FullName == package.TypeName)
{
package.IsInstalled = true;
packageTypes[package] = type;
}
}
}
}
}
catch (ReflectionTypeLoadException)
{
// For this failure, silently skip this assembly unless we have some expectation that it contains App Center
if (assembly.FullName.StartsWith("Assembly-CSharp")) // The standard "source-code in unity proj" assembly name
{
EdExLogger.LoggerInstance.LogWarning("App Center Editor Extension error, failed to access the main CSharp assembly that probably contains App Center SDK");
}
continue;
}
}
foreach (var packageType in packageTypes)
{
packageType.Key.GetInstalledVersion(packageType.Value, InstalledSdkVersion);
}
}
private static void GetLatestSdkVersion()
{
var threshold = AppCenterEditorPrefsSO.Instance.EdSet_lastSdkVersionCheck != DateTime.MinValue ? AppCenterEditorPrefsSO.Instance.EdSet_lastSdkVersionCheck.AddHours(1) : DateTime.MinValue;
if (DateTime.Today > threshold)
{
AppCenterEditorHttp.MakeGitHubApiCall("https://api.github.com/repos/Microsoft/AppCenter-SDK-Unity/git/refs/tags", (version) =>
{
LatestSdkVersion = version ?? Constants.UnknownVersion;
AppCenterEditorPrefsSO.Instance.EdSet_latestSdkVersion = LatestSdkVersion;
});
}
else
{
LatestSdkVersion = AppCenterEditorPrefsSO.Instance.EdSet_latestSdkVersion;
}
}
private static UnityEngine.Object FindSdkAsset()
{
UnityEngine.Object sdkAsset = null;
// look in editor prefs
if (AppCenterEditorPrefsSO.Instance.SdkPath != null)
{
sdkAsset = AssetDatabase.LoadAssetAtPath(AppCenterEditorPrefsSO.Instance.SdkPath, typeof(UnityEngine.Object));
}
if (sdkAsset != null)
return sdkAsset;
sdkAsset = AssetDatabase.LoadAssetAtPath(AppCenterEditorHelper.DEFAULT_SDK_LOCATION, typeof(UnityEngine.Object));
if (sdkAsset != null)
return sdkAsset;
var fileList = Directory.GetDirectories(Application.dataPath, "*AppCenter", SearchOption.AllDirectories);
if (fileList.Length == 0)
return null;
var relPath = fileList[0].Substring(fileList[0].LastIndexOf("Assets" + Path.DirectorySeparatorChar));
return AssetDatabase.LoadAssetAtPath(relPath, typeof(UnityEngine.Object));
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2b57d3ec8e3cf4c8c8ba6d8d595cd6c1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3d64a1476e9a21a42b7cac2baafca9d4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,31 @@
namespace AppCenterEditor
{
public class AppCenterAnalyticsPackage : AppCenterSDKPackage
{
private const string AnalyticsLatestDownload = "https://mobilecentersdkdev.blob.core.windows.net/sdk/AppCenterAnalyticsLatest.unitypackage";
private const string AnalyticsDownloadFormat = "https://github.com/Microsoft/AppCenter-SDK-Unity/releases/download/{0}/AppCenterAnalytics-v{0}.unitypackage";
public static AppCenterAnalyticsPackage Instance = new AppCenterAnalyticsPackage();
public override string Name { get { return "Analytics"; } }
protected override bool IsSupportedForWSA { get { return true; } }
public override string TypeName { get { return "Microsoft.AppCenter.Unity.Analytics.Analytics"; } }
public override string VersionFieldName { get { return "AnalyticsSDKVersion"; } }
public override string DownloadLatestUrl { get { return AnalyticsLatestDownload; } }
public override string DownloadUrlFormat { get { return AnalyticsDownloadFormat; } }
protected override bool IsSdkPackageSupported()
{
return true;
}
private AppCenterAnalyticsPackage()
{
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 564bbf408bc68c04fa37ddf06c3a47de
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,31 @@
namespace AppCenterEditor
{
public class AppCenterCrashesPackage : AppCenterSDKPackage
{
private const string CrashesLatestDownload = "https://mobilecentersdkdev.blob.core.windows.net/sdk/AppCenterCrashesLatest.unitypackage";
private const string CrashesDownloadFormat = "https://github.com/Microsoft/AppCenter-SDK-Unity/releases/download/{0}/AppCenterCrashes-v{0}.unitypackage";
public static AppCenterCrashesPackage Instance = new AppCenterCrashesPackage();
public override string Name { get { return "Crashes"; } }
protected override bool IsSupportedForWSA { get { return false; } }
public override string TypeName { get { return "Microsoft.AppCenter.Unity.Crashes.Crashes"; } }
public override string VersionFieldName { get { return "CrashesSDKVersion"; } }
public override string DownloadLatestUrl { get { return CrashesLatestDownload; } }
public override string DownloadUrlFormat { get { return CrashesDownloadFormat; } }
protected override bool IsSdkPackageSupported()
{
return true;
}
private AppCenterCrashesPackage()
{
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f2adc8c1aa0190947ae545aac1d99de0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,31 @@
namespace AppCenterEditor
{
public class AppCenterDistributePackage : AppCenterSDKPackage
{
private const string DistributeLatestDownload = "https://mobilecentersdkdev.blob.core.windows.net/sdk/AppCenterDistributeLatest.unitypackage";
private const string DistributeDownloadFormat = "https://github.com/Microsoft/AppCenter-SDK-Unity/releases/download/{0}/AppCenterDistribute-v{0}.unitypackage";
public static AppCenterDistributePackage Instance = new AppCenterDistributePackage();
public override string TypeName { get { return "Microsoft.AppCenter.Unity.Distribute.Distribute"; } }
public override string VersionFieldName { get { return "DistributeSDKVersion"; } }
public override string Name { get { return "Distribute"; } }
protected override bool IsSupportedForWSA { get { return false; } }
public override string DownloadLatestUrl { get { return DistributeLatestDownload; } }
public override string DownloadUrlFormat { get { return DistributeDownloadFormat; } }
protected override bool IsSdkPackageSupported()
{
return true;
}
private AppCenterDistributePackage()
{
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a4c7d12311fbe6c4dbdc48c7f0c955d2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,229 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using System.IO;
namespace AppCenterEditor
{
public abstract class AppCenterSDKPackage
{
private static int angle = 0;
public static IEnumerable<AppCenterSDKPackage> SupportedPackages = new AppCenterSDKPackage[]
{
AppCenterAnalyticsPackage.Instance,
AppCenterCrashesPackage.Instance,
AppCenterDistributePackage.Instance,
};
public string InstalledVersion { get; private set; }
public bool IsInstalled { get; set; }
public bool IsPackageInstalling { get; set; }
public bool IsObjectFieldActive { get; set; }
protected abstract bool IsSupportedForWSA { get; }
public abstract string Name { get; }
public abstract string DownloadLatestUrl { get; }
public abstract string DownloadUrlFormat { get; }
public abstract string TypeName { get; }
public abstract string VersionFieldName { get; }
protected abstract bool IsSdkPackageSupported();
public static IEnumerable<AppCenterSDKPackage> GetInstalledPackages()
{
var installedPackages = new List<AppCenterSDKPackage>();
foreach (var package in SupportedPackages)
{
if (package.IsInstalled)
{
installedPackages.Add(package);
}
}
return installedPackages;
}
private void RemovePackage(bool prompt = true)
{
if (prompt && !EditorUtility.DisplayDialog("Confirm SDK Removal", string.Format("This action will remove the current {0} SDK.", Name), "Confirm", "Cancel"))
{
return;
}
EdExLogger.LoggerInstance.LogWithTimeStamp(string.Format("Removing {0} package...", Name));
var toDelete = new List<string>();
string pluginsPath = Path.Combine(AppCenterEditorPrefsSO.Instance.SdkPath, "Plugins");
string androidPath = Path.Combine(pluginsPath, "Android");
string sdkPath = Path.Combine(pluginsPath, "AppCenterSDK");
string iosPath = Path.Combine(pluginsPath, "iOS");
string wsaPath = Path.Combine(pluginsPath, "WSA");
toDelete.Add(Path.Combine(androidPath, string.Format("appcenter-{0}-release.aar", Name.ToLower())));
toDelete.AddRange(Directory.GetFiles(Path.Combine(sdkPath, Name)));
toDelete.AddRange(Directory.GetDirectories(Path.Combine(sdkPath, Name)));
toDelete.Add(Path.Combine(sdkPath, Name));
toDelete.AddRange(Directory.GetFiles(Path.Combine(iosPath, Name)));
toDelete.AddRange(Directory.GetDirectories(Path.Combine(iosPath, Name)));
toDelete.Add(Path.Combine(iosPath, Name));
if (IsSupportedForWSA)
{
toDelete.AddRange(Directory.GetFiles(Path.Combine(wsaPath, Name)));
toDelete.AddRange(Directory.GetDirectories(Path.Combine(wsaPath, Name)));
toDelete.Add(Path.Combine(wsaPath, Name));
}
bool deleted = true;
foreach (var path in toDelete)
{
if (!FileUtil.DeleteFileOrDirectory(path))
{
if (!path.EndsWith("meta"))
{
deleted = false;
}
}
FileUtil.DeleteFileOrDirectory(path + ".meta");
}
// Remove Core if no packages left.
List<AppCenterSDKPackage> installedPackages = new List<AppCenterSDKPackage>();
installedPackages.AddRange(GetInstalledPackages());
if (installedPackages.Count <= 1)
{
AppCenterEditorSDKTools.RemoveSdk(false);
}
if (deleted)
{
EdExLogger.LoggerInstance.LogWithTimeStamp(string.Format("{0} package removed.", Name));
AppCenterEditor.RaiseStateUpdate(AppCenterEditor.EdExStates.OnSuccess, string.Format("App Center {0} SDK removed.", Name));
// HACK for 5.4, AssetDatabase.Refresh(); seems to cause the install to fail.
if (prompt)
{
AssetDatabase.Refresh();
}
}
else
{
AppCenterEditor.RaiseStateUpdate(AppCenterEditor.EdExStates.OnError, string.Format("An unknown error occured and the {0} SDK could not be removed.", Name));
}
}
public void ShowPackageInstalledMenu()
{
var isPackageSupported = IsSdkPackageSupported();
using (new AppCenterGuiFieldHelper.UnityVertical(AppCenterEditorHelper.uiStyle.GetStyle("gpStyleEmpty")))
{
var sdkPackageVersion = InstalledVersion;
using (new AppCenterGuiFieldHelper.UnityHorizontal(AppCenterEditorHelper.uiStyle.GetStyle("gpStyleEmpty")))
{
GUILayout.FlexibleSpace();
var labelStyle = new GUIStyle(AppCenterEditorHelper.uiStyle.GetStyle("versionText"));
EditorGUILayout.LabelField(string.Format("{0} SDK {1} is installed", Name, sdkPackageVersion), labelStyle);
GUILayout.FlexibleSpace();
}
bool packageVersionIsValid = sdkPackageVersion != null && sdkPackageVersion != Constants.UnknownVersion;
if (packageVersionIsValid && sdkPackageVersion.CompareTo(AppCenterEditorSDKTools.InstalledSdkVersion) != 0)
{
using (new AppCenterGuiFieldHelper.UnityHorizontal(AppCenterEditorHelper.uiStyle.GetStyle("gpStyleEmpty")))
{
GUILayout.FlexibleSpace();
EditorGUILayout.LabelField("Warning! Package version is not equal to the AppCenter Core SDK version. ", AppCenterEditorHelper.uiStyle.GetStyle("orTxt"));
GUILayout.FlexibleSpace();
}
}
if (isPackageSupported && AppCenterEditorSDKTools.SdkFolder != null)
{
using (new AppCenterGuiFieldHelper.UnityHorizontal(AppCenterEditorHelper.uiStyle.GetStyle("gpStyleEmpty")))
{
GUILayout.FlexibleSpace();
if (GUILayout.Button("Remove SDK", AppCenterEditorHelper.uiStyle.GetStyle("textButton")))
{
RemovePackage();
}
GUILayout.FlexibleSpace();
}
}
}
}
public void ShowPackageNotInstalledMenu()
{
using (new AppCenterGuiFieldHelper.UnityVertical(AppCenterEditorHelper.uiStyle.GetStyle("gpStyleEmpty")))
{
using (new AppCenterGuiFieldHelper.UnityHorizontal(AppCenterEditorHelper.uiStyle.GetStyle("gpStyleEmpty")))
{
GUILayout.FlexibleSpace();
var labelStyle = new GUIStyle(AppCenterEditorHelper.uiStyle.GetStyle("versionText"));
EditorGUILayout.LabelField(string.Format("{0} SDK is not installed.", Name), labelStyle);
GUILayout.FlexibleSpace();
}
using (new AppCenterGuiFieldHelper.UnityHorizontal(AppCenterEditorHelper.uiStyle.GetStyle("gpStyleEmpty")))
{
GUILayout.FlexibleSpace();
if (IsPackageInstalling)
{
var image = DrawUtils.RotateImage(AssetDatabase.LoadAssetAtPath("Assets/AppCenterEditorExtensions/Editor/UI/Images/wheel.png", typeof(Texture2D)) as Texture2D, angle++);
GUILayout.Button(new GUIContent(string.Format(" {0} SDK is installing", Name), image), AppCenterEditorHelper.uiStyle.GetStyle("customButton"), GUILayout.MaxWidth(200), GUILayout.MinHeight(32));
}
else
{
if (GUILayout.Button("Install SDK", AppCenterEditorHelper.uiStyle.GetStyle("textButton")))
{
AppCenterEditorSDKTools.IsInstalling = IsPackageInstalling = true;
ImportLatestPackageSDK();
}
}
GUILayout.FlexibleSpace();
}
}
}
public string GetDownloadUrl(string version)
{
if (string.IsNullOrEmpty(version) || version == Constants.UnknownVersion)
{
return DownloadLatestUrl;
}
else
{
return string.Format(DownloadUrlFormat, version);
}
}
public void GetInstalledVersion(Type type, string coreVersion)
{
foreach (var field in type.GetFields())
{
if (field.Name == VersionFieldName)
{
InstalledVersion = field.GetValue(field).ToString();
break;
}
}
if (string.IsNullOrEmpty(InstalledVersion))
{
InstalledVersion = Constants.UnknownVersion;
}
}
private void ImportLatestPackageSDK()
{
try
{
PackagesInstaller.ImportLatestSDK(new[] { this }, AppCenterEditorSDKTools.LatestSdkVersion);
}
catch (Exception exception)
{
EdExLogger.LoggerInstance.LogError("Failed to import package: " + exception);
AppCenterEditorSDKTools.IsInstalling = IsPackageInstalling = false;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9eea6442f3431d240b5fc226398b147f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: