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,8 @@
fileFormatVersion: 2
guid: 9c9afa19d13e148fe93230b0075ee4e3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,165 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine.Networking;
namespace AppCenterEditor
{
public class AppCenterEditorHttp : Editor
{
internal static void MakeDownloadCall(string url, Action<string> resultCallback)
{
EdExLogger.LoggerInstance.LogWithTimeStamp("Downloading file: " + url);
var www = UnityWebRequest.Get(url);
AppCenterEditor.RaiseStateUpdate(AppCenterEditor.EdExStates.OnHttpReq, url, AppCenterEditorHelper.MSG_SPIN_BLOCK);
Coroutiner.StartCoroutine(PostDownload(www, response =>
{
resultCallback(WriteResultFile(url, response));
}, AppCenterEditorHelper.SharedErrorCallback));
}
internal static void MakeDownloadCall(IEnumerable<string> urls, Action<IEnumerable<string>> resultCallback)
{
EdExLogger.LoggerInstance.LogWithTimeStamp("Downloading files: " + string.Join(", ", urls.ToArray()));
var wwws = new List<UnityWebRequest>();
var downloadRequests = new List<DownloadRequest>();
foreach (var url in urls)
{
var www = UnityWebRequest.Get(url);
wwws.Add(www);
downloadRequests.Add(new DownloadRequest(url, www));
}
AppCenterEditor.RaiseStateUpdate(AppCenterEditor.EdExStates.OnHttpReq, "Downloading files", AppCenterEditorHelper.MSG_SPIN_BLOCK);
Coroutiner.StartCoroutine(DownloadFiles(downloadRequests, resultCallback, AppCenterEditorHelper.SharedErrorCallback));
}
internal static void MakeGitHubApiCall(string url, Action<string> resultCallback)
{
var www = UnityWebRequest.Get(url);
Coroutiner.StartCoroutine(Post(www, response => { OnGitHubSuccess(resultCallback, response); }, AppCenterEditorHelper.SharedErrorCallback));
}
private static IEnumerator Post(UnityWebRequest www, Action<string> callBack, Action<string> errorCallback)
{
yield return www.SendWebRequest();
if (!string.IsNullOrEmpty(www.error))
{
errorCallback(www.error);
}
else
{
callBack(www.downloadHandler.text);
}
}
private static IEnumerator PostDownload(UnityWebRequest www, Action<byte[]> callBack, Action<string> errorCallback)
{
yield return www.SendWebRequest();
if (!string.IsNullOrEmpty(www.error))
{
errorCallback(www.error);
}
else
{
callBack(www.downloadHandler.data);
}
}
private static IEnumerator DownloadFiles(IEnumerable<DownloadRequest> downloadRequests, Action<IEnumerable<string>> resultCallback, Action<string> errorCallback)
{
var downloadedFiles = new List<string>();
foreach (var downloadRequest in downloadRequests)
{
yield return downloadRequest.WWW.SendWebRequest();
if (!downloadRequest.WWW.isHttpError && !downloadRequest.WWW.isNetworkError)
{
var downloadedFile = WriteResultFile(downloadRequest.Url, downloadRequest.WWW.downloadHandler.data);
downloadedFiles.Add(downloadedFile);
}
else
{
errorCallback(downloadRequest.WWW.error);
yield break;
}
}
resultCallback(downloadedFiles);
}
private static void OnGitHubSuccess(Action<string> resultCallback, string response)
{
if (resultCallback == null)
{
return;
}
var jsonResponse = JsonWrapper.DeserializeObject<List<object>>(response);
if (jsonResponse == null || jsonResponse.Count == 0)
{
return;
}
// list seems to come back in ascending order (oldest -> newest)
var latestSdkTag = (JsonObject)jsonResponse[jsonResponse.Count - 1];
object tag;
if (latestSdkTag.TryGetValue("ref", out tag))
{
var startIndex = tag.ToString().LastIndexOf('/') + 1;
var length = tag.ToString().Length - startIndex;
resultCallback(tag.ToString().Substring(startIndex, length));
}
else
{
resultCallback(null);
}
}
private static string WriteResultFile(string url, byte[] response)
{
AppCenterEditor.RaiseStateUpdate(AppCenterEditor.EdExStates.OnHttpRes, url);
string fileName;
if (url.IndexOf("AppCenterEditorExtensions-v") > -1)
{
fileName = AppCenterEditorHelper.EDEX_UPGRADE_PATH;
}
else if (url.IndexOf("AppCenterAnalytics-v") > -1)
{
fileName = AppCenterEditorHelper.ANALYTICS_SDK_DOWNLOAD_PATH;
}
else if (url.IndexOf("AppCenterCrashes-v") > -1)
{
fileName = AppCenterEditorHelper.CRASHES_SDK_DOWNLOAD_PATH;
}
else if (url.IndexOf("AppCenterDistribute-v") > -1)
{
fileName = AppCenterEditorHelper.DISTRIBUTE_SDK_DOWNLOAD_PATH;
}
else
{
fileName = AppCenterEditorHelper.EDEX_PACKAGES_PATH;
}
var fileSaveLocation = AppCenterEditorHelper.EDEX_ROOT + fileName;
var fileSaveDirectory = Path.GetDirectoryName(fileSaveLocation);
EdExLogger.LoggerInstance.LogWithTimeStamp("Saving " + response.Length + " bytes to: " + fileSaveLocation);
if (!Directory.Exists(fileSaveDirectory))
{
Directory.CreateDirectory(fileSaveDirectory);
}
File.WriteAllBytes(fileSaveLocation, response);
return fileSaveLocation;
}
private class DownloadRequest
{
public string Url { get; private set; }
public UnityWebRequest WWW { get; private set; }
public DownloadRequest(string url, UnityWebRequest www)
{
Url = url;
WWW = www;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0adb37d42167d491e872d983c8736732
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,9 @@
namespace AppCenterEditor
{
public class Constants
{
public const string UnknownVersion = "Unknown";
public const string WrapperSdkClassName = "Microsoft.AppCenter.Unity.WrapperSdk";
public const string WrapperSdkVersionFieldName = "WrapperSdkVersion";
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9834441b45590434291881207fa97dd9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,12 @@
namespace AppCenterEditor
{
public interface ISerializer
{
T DeserializeObject<T>(string json);
T DeserializeObject<T>(string json, object jsonSerializerStrategy);
object DeserializeObject(string json);
string SerializeObject(object json);
string SerializeObject(object json, object jsonSerializerStrategy);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 573b77bd61fac61499edeaadad015476
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,45 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace AppCenterEditor
{
public class JsonWrapper
{
private static ISerializer _instance = new SimpleJsonInstance();
/// <summary>
/// Use this property to override the Serialization for the SDK.
/// </summary>
public static ISerializer Instance
{
get { return _instance; }
set { _instance = value; }
}
public static T DeserializeObject<T>(string json)
{
return _instance.DeserializeObject<T>(json);
}
public static T DeserializeObject<T>(string json, object jsonSerializerStrategy)
{
return _instance.DeserializeObject<T>(json, jsonSerializerStrategy);
}
public static object DeserializeObject(string json)
{
return _instance.DeserializeObject(json);
}
public static string SerializeObject(object json)
{
return _instance.SerializeObject(json);
}
public static string SerializeObject(object json, object jsonSerializerStrategy)
{
return _instance.SerializeObject(json, jsonSerializerStrategy);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 92da912d9a571464e90d2d08c293f5ea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using UnityEditor;
namespace AppCenterEditor
{
public static class PackagesInstaller
{
public static void ImportLatestSDK(IEnumerable<AppCenterSDKPackage> packagesToImport, string version, string existingSdkPath = null)
{
try
{
var downloadUrls = new List<string>();
foreach (var package in packagesToImport)
{
downloadUrls.Add(package.GetDownloadUrl(version));
}
AppCenterEditorHttp.MakeDownloadCall(downloadUrls, downloadedFiles =>
{
try
{
foreach (var file in downloadedFiles)
{
EdExLogger.LoggerInstance.LogWithTimeStamp("Importing package: " + file);
AssetDatabase.ImportPackage(file, false);
EdExLogger.LoggerInstance.LogWithTimeStamp("Deleting file: " + file);
FileUtil.DeleteFileOrDirectory(file);
}
AppCenterEditorPrefsSO.Instance.SdkPath = string.IsNullOrEmpty(existingSdkPath) ? AppCenterEditorHelper.DEFAULT_SDK_LOCATION : existingSdkPath;
//AppCenterEditorDataService.SaveEnvDetails();
EdExLogger.LoggerInstance.LogWithTimeStamp("App Center SDK install complete");
}
catch (Exception exception)
{
EdExLogger.LoggerInstance.LogError("Failed to import packages: " + exception);
}
finally
{
AppCenterEditorSDKTools.IsInstalling = false;
}
});
}
catch
{
AppCenterEditorSDKTools.IsInstalling = false;
throw;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 49ddc3aac61e4af42bf36700ad5ccb45
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8bfd769747cb35a4ca40e4e9debf31c0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,34 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace AppCenterEditor
{
public class SimpleJsonInstance : ISerializer
{
public T DeserializeObject<T>(string json)
{
return AppCenterSimpleJson.DeserializeObject<T>(json);
}
public T DeserializeObject<T>(string json, object jsonSerializerStrategy)
{
return AppCenterSimpleJson.DeserializeObject<T>(json, (IJsonSerializerStrategy)jsonSerializerStrategy);
}
public object DeserializeObject(string json)
{
return AppCenterSimpleJson.DeserializeObject(json);
}
public string SerializeObject(object json)
{
return AppCenterSimpleJson.SerializeObject(json);
}
public string SerializeObject(object json, object jsonSerializerStrategy)
{
return AppCenterSimpleJson.SerializeObject(json, (IJsonSerializerStrategy)jsonSerializerStrategy);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 260fd54878fe79d42b8e3100b4bf98db
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d4088971449f54227a925f6a05fb09a9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,57 @@
using UnityEngine;
using System;
public class DrawUtils {
private static Color32[] rotateSquare(Color32[] arr, double phi, Texture2D originTexture)
{
int x;
int y;
int i;
int j;
double sn = Math.Sin(phi);
double cs = Math.Cos(phi);
Color32[] arr2 = originTexture.GetPixels32();
int W = originTexture.width;
int H = originTexture.height;
int xc = W / 2;
int yc = H / 2;
for (j = 0; j < H; j++)
{
for (i = 0; i < W; i++)
{
arr2[j * W + i] = new Color32(0, 0, 0, 0);
x = (int)(cs * (i - xc) + sn * (j - yc) + xc);
y = (int)(-sn * (i - xc) + cs * (j - yc) + yc);
if ((x > -1) && (x < W) && (y > -1) && (y < H))
{
arr2[j * W + i] = arr[y * W + x];
}
}
}
return arr2;
}
public static Texture2D RotateImage(Texture2D originTexture, int angle)
{
Texture2D result;
result = new Texture2D(originTexture.width, originTexture.height);
Color32[] pix1 = result.GetPixels32();
Color32[] pix2 = originTexture.GetPixels32();
int W = originTexture.width;
int H = originTexture.height;
int x = 0;
int y = 0;
Color32[] pix3 = rotateSquare(pix2, (Math.PI / 180 * (double)angle), originTexture);
for (int j = 0; j < H; j++)
{
for (var i = 0; i < W; i++)
{
pix1[result.width / 2 - W / 2 + x + i + result.width * (result.height / 2 - H / 2 + j + y)] = pix3[i + j * W];
}
}
result.SetPixels32(pix1);
result.Apply();
return result;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2db30e5e160bb48358ce517ac9f8eea8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,157 @@
using UnityEditor;
using UnityEngine;
namespace AppCenterEditor
{
public class ProgressBar
{
public enum ProgressBarStates { off = 0, on = 1, spin = 2, error = 3, warning = 4, success = 5 }
public static ProgressBarStates currentProgressBarState = ProgressBarStates.off;
public static float progress = 0;
private static GUIStyle pbarStyle = AppCenterEditorHelper.uiStyle.GetStyle("progressBarFg");
private static GUIStyle pbarBgStyle = AppCenterEditorHelper.uiStyle.GetStyle("progressBarBg");
private static float progressWidth = 0;
private static float animationSpeed = 1f;
private static float tickRate = .15f;
private static float stTime;
private static float endTime;
private static float lastUpdateTime;
private static bool isReveresed;
public static void UpdateState(ProgressBarStates state)
{
if (currentProgressBarState == ProgressBarStates.off && state != ProgressBarStates.off)
{
stTime = (float)EditorApplication.timeSinceStartup;
endTime = stTime + animationSpeed;
}
currentProgressBarState = state;
}
//not a good way to do this right now.
public static void UpdateProgress(float p)
{
progress = p;
}
public static void Draw()
{
var progressMaxWidth = AppCenterEditor.InnerContainerWidth;
pbarBgStyle = AppCenterEditorHelper.uiStyle.GetStyle("progressBarBg");
if (currentProgressBarState == ProgressBarStates.off)
{
stTime = 0;
endTime = 0;
progressWidth = 0;
lastUpdateTime = 0;
isReveresed = false;
progressWidth = progressMaxWidth;
pbarStyle = AppCenterEditorHelper.uiStyle.GetStyle("progressBarClear");
pbarBgStyle = AppCenterEditorHelper.uiStyle.GetStyle("progressBarClear");
//return;
}
else if (EditorWindow.focusedWindow != AppCenterEditor.window)
{
// pause draw while we are in the bg
return;
}
else if (currentProgressBarState == ProgressBarStates.success)
{
if ((float)EditorApplication.timeSinceStartup - stTime < animationSpeed)
{
progressWidth = progressMaxWidth;
pbarStyle = AppCenterEditorHelper.uiStyle.GetStyle("progressBarSuccess");
}
else if (AppCenterEditor.blockingRequests.Count > 0)
{
UpdateState(ProgressBarStates.spin);
}
else
{
UpdateState(ProgressBarStates.off);
}
}
else if (currentProgressBarState == ProgressBarStates.warning)
{
if ((float)EditorApplication.timeSinceStartup - stTime < animationSpeed)
{
progressWidth = progressMaxWidth;
pbarStyle = AppCenterEditorHelper.uiStyle.GetStyle("progressBarWarn");
}
else if (AppCenterEditor.blockingRequests.Count > 0)
{
UpdateState(ProgressBarStates.spin);
}
else
{
UpdateState(ProgressBarStates.off);
}
}
else if (currentProgressBarState == ProgressBarStates.error)
{
if ((float)EditorApplication.timeSinceStartup - stTime < animationSpeed)
{
progressWidth = progressMaxWidth;
pbarStyle = AppCenterEditorHelper.uiStyle.GetStyle("progressBarError");
}
else if (AppCenterEditor.blockingRequests.Count > 0)
{
UpdateState(ProgressBarStates.spin);
}
else
{
UpdateState(ProgressBarStates.off);
}
}
else
{
if ((float)EditorApplication.timeSinceStartup - lastUpdateTime > tickRate)
{
lastUpdateTime = (float)EditorApplication.timeSinceStartup;
pbarStyle = AppCenterEditorHelper.uiStyle.GetStyle("progressBarFg");
if (currentProgressBarState == ProgressBarStates.on)
{
progressWidth = progressMaxWidth * progress;
}
else if (currentProgressBarState == ProgressBarStates.spin)
{
var currentTime = (float)EditorApplication.timeSinceStartup;
if (currentTime < endTime && !isReveresed)
{
UpdateProgress((currentTime - stTime) / animationSpeed);
progressWidth = progressMaxWidth * progress;
}
else if (currentTime < endTime && isReveresed)
{
UpdateProgress((currentTime - stTime) / animationSpeed);
progressWidth = progressMaxWidth - progressMaxWidth * progress;
}
else
{
isReveresed = !isReveresed;
stTime = (float)EditorApplication.timeSinceStartup;
endTime = stTime + animationSpeed;
}
}
}
}
using (new AppCenterGuiFieldHelper.UnityHorizontal(pbarBgStyle))
{
if (isReveresed)
{
GUILayout.FlexibleSpace();
}
EditorGUILayout.LabelField("", pbarStyle, GUILayout.Width(progressWidth));
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: eea75b0d7b5ef4c108f3f7d94c1db778
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c0a0aac543bfd421c90c069618185d46
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -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:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 650530f20e6ea42d9a780a37a9774a42
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace AppCenterEditor
{
public static class AppCenterGuiFieldHelper
{
/// <summary>
/// A disposable wrapper for Verticals, to ensure they're paired properly, and to make the code visually block together within them
/// </summary>
public class UnityHorizontal : IDisposable
{
public UnityHorizontal(params GUILayoutOption[] options)
{
EditorGUILayout.BeginHorizontal(options);
}
public UnityHorizontal(GUIStyle style, params GUILayoutOption[] options)
{
EditorGUILayout.BeginHorizontal(style, options);
}
public void Dispose()
{
EditorGUILayout.EndHorizontal();
}
}
/// <summary>
/// A disposable wrapper for Horizontals, to ensure they're paired properly, and to make the code visually block together within them
/// </summary>
public class UnityVertical : IDisposable
{
public UnityVertical(params GUILayoutOption[] options)
{
EditorGUILayout.BeginVertical(options);
}
public UnityVertical(GUIStyle style, params GUILayoutOption[] options)
{
EditorGUILayout.BeginVertical(style, options);
}
public void Dispose()
{
EditorGUILayout.EndVertical();
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d96a7c436f35b439192d00d70db71bf2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,83 @@
using UnityEditor;
using UnityEngine;
using System;
using System.IO;
namespace AppCenterEditor
{
[InitializeOnLoad]
public static partial class AppCenterEditorHelper
{
public static string EDEX_NAME = "AppCenterEditorExtensions";
public static string EDEX_ROOT = Path.Combine(Application.dataPath, "AppCenterEditorExtensions/Editor");
public static string APPCENTER_SETTINGS_TYPENAME = "AppCenterSettings";
public static string APPCENTER_WRAPPER_SDK_TYPENAME = "WrapperSdk";
public static string DEFAULT_SDK_LOCATION = "Assets/AppCenter";
public static string DEFAULT_SDK_LOCATION_PATH = Application.dataPath + "/AppCenter";
public static string MSG_SPIN_BLOCK = "{\"useSpinner\":true, \"blockUi\":true }";
public static string ANALYTICS_SDK_DOWNLOAD_PATH = "/Resources/AppCenterAnalyticsUnitySdk.unitypackage";
public static string CRASHES_SDK_DOWNLOAD_PATH = "/Resources/AppCenterCrashesUnitySdk.unitypackage";
public static string DISTRIBUTE_SDK_DOWNLOAD_PATH = "/Resources/AppCenterDistributeUnitySdk.unitypackage";
public static string EDEX_UPGRADE_PATH = "/Resources/AppCenterUnityEditorExtensions.unitypackage";
public static string EDEX_PACKAGES_PATH = "/Resources/MostRecentPackage.unitypackage";
private static GUISkin _uiStyle;
public static GUISkin uiStyle
{
get
{
if (_uiStyle != null)
return _uiStyle;
_uiStyle = GetUiStyle();
return _uiStyle;
}
}
public static void SharedErrorCallback(string error)
{
AppCenterEditor.RaiseStateUpdate(AppCenterEditor.EdExStates.OnError, error);
}
private static GUISkin GetUiStyle()
{
var searchRoot = string.IsNullOrEmpty(EDEX_ROOT) ? Application.dataPath : EDEX_ROOT;
string[] guiPaths;
if (Directory.Exists(searchRoot))
{
guiPaths = FindGuiSkinPaths(searchRoot);
}
else
{
EDEX_ROOT = FindEdexRoot();
guiPaths = FindGuiSkinPaths(EDEX_ROOT);
}
foreach (var eachPath in guiPaths)
{
var loadPath = eachPath.Substring(eachPath.LastIndexOf("Assets" + Path.DirectorySeparatorChar, StringComparison.Ordinal));
return (GUISkin) AssetDatabase.LoadAssetAtPath(loadPath, typeof(GUISkin));
}
return null;
}
private static string[] FindGuiSkinPaths(string searchPath)
{
return Directory.GetFiles(searchPath, "AppCenterStyles.guiskin", SearchOption.AllDirectories);
}
private static string FindEdexRoot()
{
var directoryList = Directory.GetDirectories(Application.dataPath, "*" + EDEX_NAME, SearchOption.AllDirectories);
if (directoryList.Length == 0)
{
throw new DirectoryNotFoundException(EDEX_NAME + " not found");
}
var relativePath = directoryList[0].Substring(directoryList[0].LastIndexOf("Assets" + Path.DirectorySeparatorChar, StringComparison.Ordinal));
return Path.Combine(relativePath, "Editor");
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f7e4708e69744494f98d2972fc0a1584
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,99 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using System;
using System.IO;
using System.Globalization;
namespace AppCenterEditor
{
#if UNITY_5_3_OR_NEWER
[CreateAssetMenu(fileName = "AppCenterEditorPrefsSO", menuName = "App Center/Make Prefs SO", order = 1)]
#endif
public class AppCenterEditorPrefsSO : ScriptableObject
{
public const string EdExLastCheckDateKey = "EdExLastCheckDateKey";
public const string SdkLastCheckDateKey = "SdkLastCheckDateKey";
public string SdkPath;
public string EdExPath;
public bool PanelIsShown;
public int curMainMenuIdx;
private string _latestSdkVersion;
private string _latestEdExVersion;
private DateTime _lastSdkVersionCheck;
private DateTime _lastEdExVersionCheck;
private static AppCenterEditorPrefsSO _instance;
public string EdSet_latestSdkVersion
{
get
{
return _latestSdkVersion;
}
set
{
_latestSdkVersion = value;
_lastSdkVersionCheck = DateTime.UtcNow;
PlayerPrefs.SetString(SdkLastCheckDateKey, _lastSdkVersionCheck.ToString(CultureInfo.InvariantCulture));
}
}
public string EdSet_latestEdExVersion
{
get
{
return _latestEdExVersion;
}
set
{
_latestEdExVersion = value;
_lastEdExVersionCheck = DateTime.UtcNow;
PlayerPrefs.SetString(EdExLastCheckDateKey, _lastEdExVersionCheck.ToString(CultureInfo.InvariantCulture));
}
}
public DateTime EdSet_lastSdkVersionCheck
{
get
{
return PlayerPrefs.HasKey(SdkLastCheckDateKey) ? DateTime.Parse(PlayerPrefs.GetString(SdkLastCheckDateKey), CultureInfo.InvariantCulture) : _lastSdkVersionCheck;
}
}
public DateTime EdSet_lastEdExVersionCheck
{
get
{
return PlayerPrefs.HasKey(EdExLastCheckDateKey) ? DateTime.Parse(PlayerPrefs.GetString(EdExLastCheckDateKey), CultureInfo.InvariantCulture) : _lastEdExVersionCheck;
}
}
public static AppCenterEditorPrefsSO Instance
{
get
{
if (_instance != null)
return _instance;
var settingsList = Resources.LoadAll<AppCenterEditorPrefsSO>("AppCenterEditorPrefsSO");
if (settingsList.Length == 1)
_instance = settingsList[0];
if (_instance != null)
return _instance;
_instance = CreateInstance<AppCenterEditorPrefsSO>();
if (!Directory.Exists(Path.Combine(Application.dataPath, "AppCenterEditorExtensions/Editor/Resources")))
Directory.CreateDirectory(Path.Combine(Application.dataPath, "AppCenterEditorExtensions/Editor/Resources"));
AssetDatabase.CreateAsset(_instance, "Assets/AppCenterEditorExtensions/Editor/Resources/AppCenterEditorPrefsSO.asset");
AssetDatabase.SaveAssets();
EdExLogger.LoggerInstance.LogWithTimeStamp("Created missing AppCenterEditorPrefsSO file");
return _instance;
}
}
public static void Save()
{
EditorUtility.SetDirty(_instance);
AssetDatabase.SaveAssets();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cbb9dcf2e78804b9384db79873454e2f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,7 @@
namespace AppCenterEditor
{
public static partial class AppCenterEditorHelper
{
public static string EDEX_VERSION = "3.0.0";
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ca7cc6f0d12514529b75b5a1e489ef41
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,45 @@
using UnityEngine;
using System.Collections;
/// <summary>
/// Author: Sebastiaan Fehr (Seb@TheBinaryMill.com)
/// Date: March 2013
/// Summary: Creates MonoBehaviour instance through which
/// static classes can call StartCoroutine.
/// Description: Classes that do not inherit from MonoBehaviour, or static
/// functions within MonoBehaviours are inertly unable to
/// call StartCoroutene, as this function is not static and
/// does not exist on Object. This Class creates a proxy though
/// which StartCoroutene can be called, and destroys it when
/// no longer needed.
/// </summary>
public class Coroutiner
{
public static Coroutine StartCoroutine(IEnumerator iterationResult)
{
//Create GameObject with MonoBehaviour to handle task.
GameObject routeneHandlerGo = new GameObject("Coroutiner");
CoroutinerInstance routeneHandler
= routeneHandlerGo.AddComponent(typeof(CoroutinerInstance))
as CoroutinerInstance;
return routeneHandler.ProcessWork(iterationResult);
}
}
public class CoroutinerInstance : MonoBehaviour
{
public Coroutine ProcessWork(IEnumerator iterationResult)
{
return StartCoroutine(DestroyWhenComplete(iterationResult));
}
public IEnumerator DestroyWhenComplete(IEnumerator iterationResult)
{
yield return StartCoroutine(iterationResult);
DestroyImmediate(gameObject);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4761e800aa3aef34a9e4b2083e5acb5c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,25 @@
//Factory.
namespace AppCenterEditor
{
class EdExLogger
{
private static IEdExLogger _instance;
public static IEdExLogger LoggerInstance
{
get
{
if (_instance == null)
{
_instance = new LocalLogger();
}
return _instance;
}
}
private EdExLogger()
{
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ecaed167bfab43f4b952d32525e60583
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,13 @@
namespace AppCenterEditor
{
interface IEdExLogger
{
void LogWithTimeStamp(string message);
void LogWarning(string message);
void LogError(string message);
void Log(string message);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8bd5be8d50f07d94b9ecdd399064d573
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,34 @@
using System;
using UnityEngine;
namespace AppCenterEditor
{
class LocalLogger: IEdExLogger
{
public void LogWithTimeStamp(string message)
{
Debug.Log(GetUniqueMessage(message));
}
public void LogWarning(string message)
{
Debug.LogWarning(GetUniqueMessage(message));
}
public void LogError(string message)
{
Debug.LogError(GetUniqueMessage(message));
}
public void Log(string message)
{
Debug.Log(message);
}
private string GetUniqueMessage(string message)
{
// Return unique message in order to distinguish similar messages.
return string.Format("[App Center EdEx MSG{0}] {1}", DateTime.Now.Millisecond, message);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3bc93f39e9d0fc34eb720ccbc6bd5dc9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: