using System; using System.IO; using Sirenix.OdinInspector; using UnityEditor; using UnityEngine; namespace TriflesGames.SDKManagement.Editor { [System.Serializable] public class SDKFile { [DisplayAsString, HideLabel] public string Id { get; private set; } [ShowInInspector, DisplayAsString, HideLabel] public string Name { get; private set; } [ShowInInspector, DisplayAsString, HideLabel] public long LocalVersion { get; private set; } [ShowInInspector, DisplayAsString, HideLabel] public long DriveVersion { get; private set; } [ShowInInspector, DisplayAsString] public virtual string SDKVersion => "---"; public SDKFile(string id, string name, long driveVersion, long localVersion) { Id = id; Name = name; DriveVersion = driveVersion; LocalVersion = localVersion; } [EnableIf("$ButtonActive")] [HorizontalGroup("Actions"), Button("$ButtonText", ButtonSizes.Medium)] public void Update() { var sdkId = Id; var downloadedVersion = DriveVersion; var filePath = SDKUtils.DownloadTempUnityPackage(sdkId); AssetDatabase.ImportPackage(filePath, false); AssetDatabase.importPackageCompleted += (packageName) => { var sdkInfo = SDKUtils.GetInfo(); var entry = sdkInfo.DownloadedSDKs.Find(s => s.Id == sdkId); if (entry == null) { entry = new SDKVersion(); entry.Id = sdkId; sdkInfo.DownloadedSDKs.Add(entry); } entry.Version = downloadedVersion; EditorUtility.SetDirty(sdkInfo); AssetDatabase.SaveAssets(); Debug.Log($"Imported {packageName} successfully"); File.Delete(filePath); EditorWindow.GetWindow().Refresh(); }; } private string ButtonText() { if (LocalVersion == default) return "Download"; if (LocalVersion == DriveVersion) return "Up To Date"; return "Update"; } private bool ButtonActive() { return LocalVersion < DriveVersion; } } }