using System; using System.IO; using GameLauncher.Models; namespace GameLauncher.Engines.Unity { /// /// Unityゲームのデータモデル /// public class UnityGameItem : GameItemBase { private string _dataDirectoryPath = string.Empty; private string _companyName = string.Empty; private string _productName = string.Empty; private UnityBackendType _backendType = UnityBackendType.Unknown; private string _unityVersion = string.Empty; private bool _hasSaveData; public override GameEngineKind EngineKind => GameEngineKind.Unity; /// [Game]_Data ディレクトリ絶対パス public string DataDirectoryPath { get => this._dataDirectoryPath; set { if (this._dataDirectoryPath != value) { this._dataDirectoryPath = value; this.OnPropertyChanged(); } } } /// app.info 由来の会社名/開発者名 public string CompanyName { get => this._companyName; set { if (this._companyName != value) { this._companyName = value; this.OnPropertyChanged(); this.OnPropertyChanged(nameof(this.RegistryPath)); this.OnPropertyChanged(nameof(this.LocalLowPath)); } } } /// app.info 由来の製品名 public string ProductName { get => this._productName; set { if (this._productName != value) { this._productName = value; this.OnPropertyChanged(); this.OnPropertyChanged(nameof(this.RegistryPath)); this.OnPropertyChanged(nameof(this.LocalLowPath)); } } } public override bool IsIL2CPP => this.BackendType == UnityBackendType.IL2CPP; public override bool IsMono => this.BackendType == UnityBackendType.Mono; /// バックエンド形式 (IL2CPP / Mono) public UnityBackendType BackendType { get => this._backendType; set { if (this._backendType != value) { this._backendType = value; this.OnPropertyChanged(); this.OnPropertyChanged(nameof(this.BackendBadgeText)); this.OnPropertyChanged(nameof(this.IsIL2CPP)); this.OnPropertyChanged(nameof(this.IsMono)); } } } /// Unityバージョン文字列 public override string UnityVersion { get => this._unityVersion; set { if (this._unityVersion != value) { this._unityVersion = value; this.OnPropertyChanged(); } } } /// セーブデータ(レジストリまたはファイル)が検出されたかどうか public override bool HasSaveData { get => this._hasSaveData; set { if (this._hasSaveData != value) { this._hasSaveData = value; this.OnPropertyChanged(); } } } /// /// レジストリ (PlayerPrefs) のキーパス /// HKCU\Software\[CompanyName]\[ProductName] /// public override string RegistryPath { get { if (string.IsNullOrEmpty(this.CompanyName) || string.IsNullOrEmpty(this.ProductName)) return string.Empty; return $@"Software\{this.CompanyName}\{this.ProductName}"; } } /// /// LocalLow のセーブデータ保存ディレクトリ /// %USERPROFILE%\AppData\LocalLow\[CompanyName]\[ProductName] /// public override string LocalLowPath { get { if (string.IsNullOrEmpty(this.CompanyName) || string.IsNullOrEmpty(this.ProductName)) return string.Empty; var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); var appData = Path.GetDirectoryName(localAppData); if (string.IsNullOrEmpty(appData)) return string.Empty; return Path.Combine(appData, "LocalLow", this.CompanyName, this.ProductName); } } public override string BackendBadgeText => this.BackendType switch { UnityBackendType.IL2CPP => "IL2CPP", UnityBackendType.Mono => "Mono", _ => "Unity" }; /// /// エンジン種別ラベル。Unityは専用バッジ(IL2CPP/Mono等)で表現するため空文字を返し、 /// エンジン種別ラベル自体は表示しません。 /// public override string EngineLabelText => string.Empty; } }