Make a generic booster pack giver
This commit is contained in:
@@ -307,6 +307,92 @@ namespace Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays the booster pack reward UI and grants the specified number of booster packs.
|
||||
/// This method is awaitable and handles input mode switching automatically.
|
||||
/// Supports awarding 1 to N booster packs with animated visuals.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of booster packs to grant</param>
|
||||
/// <returns>Task that completes when the UI sequence is finished</returns>
|
||||
public async System.Threading.Tasks.Task GiveBoosterPacksAsync(int count)
|
||||
{
|
||||
Logging.Debug($"[GameManager] GiveBoosterPacksAsync called with count: {count}");
|
||||
|
||||
// Get prefab from settings
|
||||
var settings = GetSettingsObject<ICardSystemSettings>();
|
||||
if (settings?.BoosterPackRewardPrefab == null)
|
||||
{
|
||||
Logging.Warning("[GameManager] BoosterPackRewardPrefab not set in CardSystemSettings. Cannot show reward UI.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Find main canvas
|
||||
GameObject mainCanvasObj = GameObject.FindGameObjectWithTag("MainCanvas");
|
||||
if (mainCanvasObj == null)
|
||||
{
|
||||
Logging.Warning("[GameManager] MainCanvas not found in scene. Cannot show reward UI.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Switch to UI input mode
|
||||
InputManager.Instance?.SetInputMode(InputMode.UI);
|
||||
Logging.Debug("[GameManager] Switched to UI input mode");
|
||||
|
||||
// Instantiate UI prefab
|
||||
GameObject uiInstance = Instantiate(settings.BoosterPackRewardPrefab);
|
||||
var component = uiInstance.GetComponent<UI.CardSystem.MinigameBoosterGiver>();
|
||||
|
||||
if (component == null)
|
||||
{
|
||||
Logging.Warning("[GameManager] BoosterPackRewardPrefab does not have MinigameBoosterGiver component!");
|
||||
Destroy(uiInstance);
|
||||
InputManager.Instance?.SetInputMode(InputMode.GameAndUI);
|
||||
return;
|
||||
}
|
||||
|
||||
// Parent to main canvas and set stretch-fill anchoring
|
||||
RectTransform rectTransform = uiInstance.GetComponent<RectTransform>();
|
||||
if (rectTransform != null)
|
||||
{
|
||||
rectTransform.SetParent(mainCanvasObj.transform, false);
|
||||
|
||||
// Set anchors to stretch-fill (all corners)
|
||||
rectTransform.anchorMin = Vector2.zero;
|
||||
rectTransform.anchorMax = Vector2.one;
|
||||
rectTransform.offsetMin = Vector2.zero;
|
||||
rectTransform.offsetMax = Vector2.zero;
|
||||
|
||||
Logging.Debug("[GameManager] UI parented to MainCanvas with stretch-fill anchoring");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback: just parent without RectTransform adjustments
|
||||
uiInstance.transform.SetParent(mainCanvasObj.transform, false);
|
||||
Logging.Warning("[GameManager] UI does not have RectTransform, parented without anchor adjustment");
|
||||
}
|
||||
|
||||
// Create TaskCompletionSource for awaiting
|
||||
var tcs = new System.Threading.Tasks.TaskCompletionSource<bool>();
|
||||
|
||||
// Initialize the component with pack count
|
||||
component.Initialize(count);
|
||||
|
||||
// Call GiveBooster to start the sequence
|
||||
component.GiveBooster(() =>
|
||||
{
|
||||
Logging.Debug("[GameManager] Booster reward UI sequence completed");
|
||||
Destroy(uiInstance);
|
||||
tcs.SetResult(true);
|
||||
});
|
||||
|
||||
// Await completion
|
||||
await tcs.Task;
|
||||
|
||||
// Restore input mode to GameAndUI (default gameplay mode)
|
||||
InputManager.Instance?.SetInputMode(InputMode.GameAndUI);
|
||||
Logging.Debug("[GameManager] Restored to GameAndUI input mode");
|
||||
}
|
||||
|
||||
|
||||
// Helper method to get settings
|
||||
private T GetSettings<T>() where T : class
|
||||
|
||||
Reference in New Issue
Block a user