using System; using System.Collections; using System.IO; using System.Reflection; using System.Text; using Sirenix.OdinInspector; using Unity.EditorCoroutines.Editor; using UnityEditor; using UnityEngine; using UnityEngine.Networking; namespace TriflesGames.SDKManagement.Editor.SDKFiles { public class ElephantSDKFile : SDKFile { private const string SDK_VERSION_URL = "https://elephant-sdks.s3.amazonaws.com/ElephantSdkManagerManifest.json"; private string _sdkVersion; public override string SDKVersion => _sdkVersion; public ElephantSDKFile(string id, string name, long driveVersion, long localVersion) : base(id, name, driveVersion, localVersion) { EditorWindow.GetWindow().StartCoroutine(GetCurrentVersion()); } private IEnumerator GetCurrentVersion() { var unityWebRequest = new UnityWebRequest(SDK_VERSION_URL) { downloadHandler = new DownloadHandlerBuffer(), timeout = 10, }; if (!string.IsNullOrEmpty(unityWebRequest.error)) { Debug.LogError(unityWebRequest.error); } yield return unityWebRequest.SendWebRequest(); var responseJson = unityWebRequest.downloadHandler.text; if (string.IsNullOrEmpty(responseJson)) { Debug.LogError("Unable to retrieve SDK version manifest. Showing installed SDKs only."); yield break; } var sb = new StringBuilder(); var onlineVersionList = JsonUtility.FromJson(responseJson); var elephantVersionClass = Type.GetType("ElephantSDK.ElephantVersion"); if (elephantVersionClass != null) { var downloadedActualVersion = elephantVersionClass .GetField( "SDK_VERSION", BindingFlags.NonPublic | BindingFlags.Static) ?.GetValue(default); sb.Append($"current: {downloadedActualVersion} -> "); } else { sb.Append($"current: --- -> "); } if (onlineVersionList != null && onlineVersionList.sdkList.Length > 0) { sb.Append($"latest: {onlineVersionList.sdkList[0].version}"); } else { sb.Append("latest: ---"); } _sdkVersion = sb.ToString(); } [System.Serializable] private class SdkArray { public Sdk[] sdkList; } [System.Serializable] private class Sdk { public string downloadUrl; public string sdkName; public string version; public string type; } } }