### Localization Module Setup and Usage in C# Source: https://context7.com/ellanjiang/unitygameframework/llms.txt Demonstrates how to set up and use the Localization Module in Unity Game Framework. It covers subscribing to localization events, setting the current language, loading dictionary files, retrieving localized strings with and without parameters, checking for key existence, and modifying localized strings at runtime. ```csharp using UnityGameFramework.Runtime; using GameFramework.Localization; using GameFramework.Event; LocalizationComponent localization = GameEntry.GetComponent(); EventComponent eventComponent = GameEntry.GetComponent(); // Subscribe to localization events eventComponent.Subscribe(LoadDictionarySuccessEventArgs.EventId, OnLoadDictionarySuccess); eventComponent.Subscribe(LoadDictionaryFailureEventArgs.EventId, OnLoadDictionaryFailure); // Set current language localization.Language = Language.English; localization.Language = Language.ChineseSimplified; localization.Language = Language.ChineseTraditional; localization.Language = Language.Korean; localization.Language = Language.Japanese; // Get system language Language systemLang = localization.SystemLanguage; // Load dictionary file localization.ReadData("Assets/Localization/English.txt"); localization.ReadData("Assets/Localization/English.txt", priority: 100, userData: null); // Get localized string string welcomeText = localization.GetString("UI.Welcome"); // Returns: "Welcome to the game!" // Get localized string with parameters (up to 16 parameters supported) string levelText = localization.GetString("UI.Level", 5); // Dictionary entry: "UI.Level" = "Level: {0}" // Returns: "Level: 5" string scoreText = localization.GetString("UI.Score", 1000, 50); // Dictionary entry: "UI.Score" = "Score: {0} / Combo: {1}" // Returns: "Score: 1000 / Combo: 50" string playerInfo = localization.GetString("UI.PlayerInfo", "Alice", 25, 15000); // Dictionary entry: "UI.PlayerInfo" = "Player: {0}, Level: {1}, XP: {2}" // Returns: "Player: Alice, Level: 25, XP: 15000" // Check if key exists bool hasKey = localization.HasRawString("UI.Welcome"); // Add or update localized string at runtime localization.AddRawString("NewKey", "New Value"); // Remove localized strings localization.RemoveRawString("OldKey"); localization.RemoveAllRawStrings(); // Dictionary file format (tab-separated): // Key\tValue // UI.Welcome\tWelcome to the game! // UI.Level\tLevel: {0} // UI.Score\tScore: {0} / Combo: {1} // UI.PlayerInfo\tPlayer: {0}, Level: {1}, XP: {2} // Event handlers void OnLoadDictionarySuccess(object sender, GameEventArgs e) { LoadDictionarySuccessEventArgs args = (LoadDictionarySuccessEventArgs)e; Log.Info("Dictionary loaded: {0}, Duration: {1}s", args.DictionaryAssetName, args.Duration); } void OnLoadDictionaryFailure(object sender, GameEventArgs e) { LoadDictionaryFailureEventArgs args = (LoadDictionaryFailureEventArgs)e; Log.Error("Dictionary failed: {0}, Error: {1}", args.DictionaryAssetName, args.ErrorMessage); } ``` -------------------------------- ### C# Event Handling with Unity Game Framework Source: https://context7.com/ellanjiang/unitygameframework/llms.txt Demonstrates how to define custom event arguments, subscribe to and unsubscribe from framework and custom events, check for subscriptions, get handler counts, and fire events using Unity Game Framework's EventComponent. It also shows how to use ReferencePool for efficient event argument management. ```csharp using UnityGameFramework.Runtime; using GameFramework.Event; using System; // Define custom game event public class PlayerLevelUpEventArgs : GameEventArgs { public static readonly int EventId = typeof(PlayerLevelUpEventArgs).GetHashCode(); public int PlayerId { get; set; } public int NewLevel { get; set; } public override int Id { get { return EventId; } } public override void Clear() { PlayerId = 0; NewLevel = 0; } } public class GameManager : MonoBehaviour { private EventComponent m_EventComponent; void Start() { m_EventComponent = GameEntry.GetComponent(); // Subscribe to built-in framework events m_EventComponent.Subscribe(ShowEntitySuccessEventArgs.EventId, OnShowEntitySuccess); m_EventComponent.Subscribe(LoadConfigSuccessEventArgs.EventId, OnLoadConfigSuccess); // Subscribe to custom game events m_EventComponent.Subscribe(PlayerLevelUpEventArgs.EventId, OnPlayerLevelUp); // Check if handler is subscribed bool isSubscribed = m_EventComponent.Check( PlayerLevelUpEventArgs.EventId, OnPlayerLevelUp); // Get handler count for event int handlerCount = m_EventComponent.Count(PlayerLevelUpEventArgs.EventId); } void OnDestroy() { // Unsubscribe from events m_EventComponent.Unsubscribe(ShowEntitySuccessEventArgs.EventId, OnShowEntitySuccess); m_EventComponent.Unsubscribe(LoadConfigSuccessEventArgs.EventId, OnLoadConfigSuccess); m_EventComponent.Unsubscribe(PlayerLevelUpEventArgs.EventId, OnPlayerLevelUp); } void LevelUpPlayer(int playerId, int newLevel) { // Fire event (thread-safe, dispatched next frame) PlayerLevelUpEventArgs e = ReferencePool.Acquire(); e.PlayerId = playerId; e.NewLevel = newLevel; m_EventComponent.Fire(this, e); ReferencePool.Release(e); // Or fire immediately (not thread-safe, immediate dispatch) // m_EventComponent.FireNow(this, e); } void OnPlayerLevelUp(object sender, GameEventArgs e) { PlayerLevelUpEventArgs args = (PlayerLevelUpEventArgs)e; Log.Info("Player {0} leveled up to {1}!", args.PlayerId, args.NewLevel); } void OnShowEntitySuccess(object sender, GameEventArgs e) { ShowEntitySuccessEventArgs args = (ShowEntitySuccessEventArgs)e; Log.Info("Entity {0} shown successfully", args.Entity.Id); } void OnLoadConfigSuccess(object sender, GameEventArgs e) { LoadConfigSuccessEventArgs args = (LoadConfigSuccessEventArgs)e; Log.Info("Config {0} loaded", args.ConfigAssetName); } } ``` -------------------------------- ### Unity C# Download Files Asynchronously Source: https://context7.com/ellanjiang/unitygameframework/llms.txt This snippet demonstrates how to use the DownloadComponent in UnityGameFramework to download files asynchronously. It covers subscribing to download events (start, update, success, failure), configuring download settings like timeout and flush size, checking download status (total, free, working agents, speed), adding new downloads with specified paths and URIs, pausing and resuming all downloads, removing individual or all downloads, and implementing basic event handlers for logging download progress and status. It requires UnityGameFramework runtime components. ```csharp using UnityGameFramework.Runtime; using GameFramework.Event; using GameFramework.Download; DownloadComponent download = GameEntry.GetComponent(); EventComponent eventComponent = GameEntry.GetComponent(); // Subscribe to download events eventComponent.Subscribe(DownloadStartEventArgs.EventId, OnDownloadStart); eventComponent.Subscribe(DownloadUpdateEventArgs.EventId, OnDownloadUpdate); eventComponent.Subscribe(DownloadSuccessEventArgs.EventId, OnDownloadSuccess); eventComponent.Subscribe(DownloadFailureEventArgs.EventId, OnDownloadFailure); // Configure download settings download.Timeout = 30f; // Timeout in seconds download.FlushSize = 1048576; // 1MB flush size for resume support // Check download status int totalAgents = download.TotalAgentCount; // Total downloaders int freeAgents = download.FreeAgentCount; // Available downloaders int workingAgents = download.WorkingAgentCount; // Active downloads float downloadSpeed = download.CurrentSpeed; // Bytes per second // Add download agent helpers (configure in Inspector or at runtime) // Default count is 3 concurrent downloaders // Start file download int serialId = download.AddDownload( downloadPath: "Assets/UpdatedAssets/Level2.bundle", downloadUri: "https://cdn.example.com/assets/Level2.bundle", userData: null ); // Start download with custom save path serialId = download.AddDownload( downloadPath: "/CustomPath/level2.bundle", downloadUri: "https://cdn.example.com/assets/Level2.bundle", priority: 100, userData: null ); // Pause and resume all downloads download.Paused = true; // Pause download.Paused = false; // Resume // Remove download download.RemoveDownload(serialId); // Remove all downloads download.RemoveAllDownloads(); // Event handlers void OnDownloadStart(object sender, GameEventArgs e) { DownloadStartEventArgs args = (DownloadStartEventArgs)e; Log.Info("Download started: {0}", args.DownloadPath); } void OnDownloadUpdate(object sender, GameEventArgs e) { DownloadUpdateEventArgs args = (DownloadUpdateEventArgs)e; float progress = (float)args.CurrentLength / args.TotalLength; Log.Info("Downloading: {0}, Progress: {1:P}, Speed: {2} KB/s", args.DownloadPath, progress, args.CurrentSpeed / 1024f); } void OnDownloadSuccess(object sender, GameEventArgs e) { DownloadSuccessEventArgs args = (DownloadSuccessEventArgs)e; Log.Info("Download complete: {0}, Size: {1} bytes", args.DownloadPath, args.CurrentLength); } void OnDownloadFailure(object sender, GameEventArgs e) { DownloadFailureEventArgs args = (DownloadFailureEventArgs)e; Log.Error("Download failed: {0}, Error: {1}", args.DownloadUri, args.ErrorMessage); } ``` -------------------------------- ### C# UI Form Logic and Usage in UnityGameFramework Source: https://context7.com/ellanjiang/unitygameframework/llms.txt Demonstrates the implementation of a custom UI form (MainMenuUI) inheriting from UIFormLogic and provides examples of how to use the UIComponent for managing UI forms and groups within UnityGameFramework. This includes opening, closing, refocusing forms, and handling UI events. ```csharp using UnityGameFramework.Runtime; using GameFramework.Event; using UnityEngine; using UnityEngine.UI; // Define custom UI form logic public class MainMenuUI : UIFormLogic { private Button m_StartButton; private Button m_SettingsButton; private Button m_QuitButton; protected internal override void OnInit(object userData) { base.OnInit(userData); // Initialize UI (called once when created) m_StartButton = CachedTransform.Find("StartButton").GetComponent