chunk 1: core gameplay scripts scenes runtime assets

This commit is contained in:
2026-04-06 11:02:34 +03:00
parent fa0388bc79
commit 0d11a097d8
703 changed files with 2292651 additions and 0 deletions

View File

@@ -0,0 +1,393 @@
using System;
using UnityEngine;
using UnityEngine.Purchasing;
using System.Collections;
using UnityEngine.Purchasing.Extension;
using System.Threading.Tasks;
public class IAPManager : MonoBehaviour, IDetailedStoreListener
{
private static IStoreController storeController;
private static IExtensionProvider storeExtensionProvider;
public const string PRODUCT_1000_COINS = "1000_coins";
public const string PRODUCT_2150_COINS = "2150_coins";
public const string PRODUCT_4350_COINS = "4350_coins";
public const string PRODUCT_6700_COINS = "6700_coins";
public const string PRODUCT_11500_COINS = "11500_coins";
private CoinWalletSystem coinWalletSystem;
private StoreUIManager storeUIManager;
[SerializeField] private GameObject purchaseLoadingUI;
[SerializeField] private GameObject purchaseSuccessUI;
[SerializeField] private GameObject purchaseFailedUI;
private void Start()
{
coinWalletSystem = CoinWalletSystem.Instance;
storeUIManager = FindAnyObjectByType<StoreUIManager>();
// Deactivate both UIs initially
if (storeUIManager != null) storeUIManager.gameObject.SetActive(false);
// Check if in development (Editor) or production (build)
#if UNITY_EDITOR
// In development, show fake store UI
#else
// In production, show real store UI
//if (storeUIManager != null) storeUIManager.gameObject.SetActive(true);
#endif
if (storeController == null)
{
InitializePurchasing();
}
}
private void InitializePurchasing()
{
if (IsInitialized()) return;
try
{
var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
builder.AddProduct(PRODUCT_1000_COINS, ProductType.Consumable);
builder.AddProduct(PRODUCT_2150_COINS, ProductType.Consumable);
builder.AddProduct(PRODUCT_4350_COINS, ProductType.Consumable);
builder.AddProduct(PRODUCT_6700_COINS, ProductType.Consumable);
builder.AddProduct(PRODUCT_11500_COINS, ProductType.Consumable);
Debug.Log("Initializing Unity Purchasing...");
UnityPurchasing.Initialize(this, builder);
}
catch (Exception e)
{
Debug.LogError($"Error initializing IAP: {e.Message}");
}
}
private bool IsInitialized() => storeController != null && storeExtensionProvider != null;
public void Buy1000Coins() { BuyProduct(PRODUCT_1000_COINS, 1000); }
public void Buy2150Coins() { BuyProduct(PRODUCT_2150_COINS, 2150); }
public void Buy4350Coins() { BuyProduct(PRODUCT_4350_COINS, 4350); }
public void Buy6700Coins() { BuyProduct(PRODUCT_6700_COINS, 6700); }
public void Buy11500Coins() { BuyProduct(PRODUCT_11500_COINS, 11500); }
public void BuyProduct(string productID, int coinsToAdd)
{
try
{
ShowPurchaseLoading(true);
Debug.Log($"Attempting to purchase {coinsToAdd} coins");
if (coinWalletSystem == null)
{
coinWalletSystem = CoinWalletSystem.Instance;
if (coinWalletSystem == null)
{
Debug.LogError("CoinWalletSystem is not initialized!");
ShowPurchaseResult(false);
return;
}
}
// Check if in development (Editor) or production (build)
#if UNITY_EDITOR
// In development mode, simulate the purchase
Debug.Log($"Development mode: Simulating purchase of {coinsToAdd} coins");
SimulatePurchase(coinsToAdd);
#else
// In production mode, trigger the real IAP purchase flow
if (IsInitialized())
{
Product product = storeController.products.WithID(productID);
if (product != null && product.availableToPurchase)
{
storeController.InitiatePurchase(product);
}
else
{
Debug.LogError("Product not available for purchase: " + productID);
ShowPurchaseResult(false);
}
}
else
{
Debug.LogError("In-App Purchasing is not initialized.");
ShowPurchaseResult(false);
}
#endif
}
catch (System.Exception e)
{
Debug.LogError($"Error purchasing coins: {e.Message}");
ShowPurchaseResult(false);
}
finally
{
ShowPurchaseLoading(false);
}
}
// Add this new method to handle development mode purchases
private async void SimulatePurchase(int coinsToAdd)
{
if (!gameObject.activeInHierarchy)
{
gameObject.SetActive(true);
}
try
{
Debug.Log($"Simulating purchase of {coinsToAdd} coins");
ShowPurchaseLoading(true);
// Simulate a short delay to mimic network request
await Task.Delay(1000);
// Add coins directly in development mode
await coinWalletSystem.AddCoins(coinsToAdd);
// Ensure the game object is still active before showing the result
if (gameObject != null && gameObject.activeInHierarchy)
{
ShowPurchaseResult(true);
}
Debug.Log($"Development mode: Successfully added {coinsToAdd} coins");
}
catch (Exception e)
{
Debug.LogError($"Development mode: Failed to simulate purchase: {e.Message}");
if (gameObject != null && gameObject.activeInHierarchy)
{
ShowPurchaseResult(false);
}
}
finally
{
if (gameObject != null && gameObject.activeInHierarchy)
{
ShowPurchaseLoading(false);
}
}
}
// Called when a purchase completes
public void OnPurchaseComplete(Product product)
{
try
{
int coinsToAdd = 0;
// Determine the number of coins based on the product ID
if (product.definition.id == PRODUCT_1000_COINS)
{
coinsToAdd = 1000;
}
else if (product.definition.id == PRODUCT_2150_COINS)
{
coinsToAdd = 2150;
}
else if (product.definition.id == PRODUCT_4350_COINS)
{
coinsToAdd = 4350;
}
else if (product.definition.id == PRODUCT_6700_COINS)
{
coinsToAdd = 6700;
}
else if (product.definition.id == PRODUCT_11500_COINS)
{
coinsToAdd = 11500;
}
else
{
Debug.LogError("Unrecognized product ID.");
ShowPurchaseResult(false);
return;
}
// Add the coins to the wallet and show the result
if (coinWalletSystem != null)
{
coinWalletSystem.AddCoins(coinsToAdd);
ShowPurchaseResult(true); // Show success UI
}
else
{
Debug.LogError("CoinWalletSystem not found!");
ShowPurchaseResult(false); // Show failure UI
}
}
catch (Exception e)
{
Debug.LogError($"Error processing purchase: {e.Message}");
ShowPurchaseResult(false); // Show failure UI
}
}
// Called when a purchase fails
public void OnPurchaseFailed(Product product, PurchaseFailureDescription failureDescription)
{
Debug.LogError($"Purchase failed for {product.definition.id}: {failureDescription.message}");
ShowPurchaseResult(false);
}
// This method simulates showing the store UI in the development build
private void ShowFakeStore(string productID, int coinsToAdd)
{
// Show the fake store UI or simulate the purchase process
Debug.Log($"Fake store: ready to purchase {coinsToAdd} coins.");
// You may trigger the "Buy" button in the fake store UI to simulate a successful purchase
}
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
if (!gameObject.activeInHierarchy)
{
gameObject.SetActive(true);
}
Debug.Log($"Processing purchase for product: {args.purchasedProduct.definition.id}");
if (coinWalletSystem == null)
{
coinWalletSystem = CoinWalletSystem.Instance;
}
string productId = args.purchasedProduct.definition.id;
int coinsToAdd = 0;
switch (productId)
{
case PRODUCT_1000_COINS: coinsToAdd = 1000; break;
case PRODUCT_2150_COINS: coinsToAdd = 2150; break;
case PRODUCT_4350_COINS: coinsToAdd = 4350; break;
case PRODUCT_6700_COINS: coinsToAdd = 6700; break;
case PRODUCT_11500_COINS: coinsToAdd = 11500; break;
default:
Debug.LogError($"Unrecognized product ID {productId}");
return PurchaseProcessingResult.Complete;
}
if (coinsToAdd > 0 && coinWalletSystem != null)
{
// Use async/await pattern with Task.Run to handle the async operation
StartCoroutine(ProcessPurchaseAsync(coinsToAdd));
}
else
{
Debug.LogError("Failed to add coins: CoinWalletSystem not found or coins amount is 0");
ShowPurchaseResult(false);
}
return PurchaseProcessingResult.Complete;
}
private IEnumerator ProcessPurchaseAsync(int coinsToAdd)
{
ShowPurchaseLoading(true);
var task = coinWalletSystem.AddCoins(coinsToAdd);
while (!task.IsCompleted)
{
yield return null;
}
if (task.Exception == null)
{
ShowPurchaseResult(true);
}
else
{
Debug.LogError($"Failed to process purchase: {task.Exception}");
ShowPurchaseResult(false);
}
ShowPurchaseLoading(false);
}
public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
{
storeController = controller;
storeExtensionProvider = extensions;
}
public void OnInitializeFailed(InitializationFailureReason error)
{
Debug.LogError($"IAP initialization failed: {error.ToString()}");
}
public void OnInitializeFailed(InitializationFailureReason error, string message)
{
Debug.LogError($"IAP initialization failed: {error.ToString()}, Message: {message}");
}
// Add the BuyProductID method here
public void BuyProductID(string productID)
{
if (IsInitialized())
{
Product product = storeController.products.WithID(productID);
if (product != null && product.availableToPurchase)
{
storeController.InitiatePurchase(product);
}
else
{
Debug.LogError("Product not available for purchase: " + productID);
}
}
else
{
Debug.LogError("In-App Purchasing is not initialized.");
}
}
private void ShowPurchaseLoading(bool show)
{
if (purchaseLoadingUI != null)
purchaseLoadingUI.SetActive(show);
}
private void ShowPurchaseResult(bool success)
{
if (!gameObject.activeInHierarchy) return;
if (success && purchaseSuccessUI != null)
{
purchaseSuccessUI.SetActive(true);
StartCoroutine(HideUI(purchaseSuccessUI, 2f));
}
else if (!success && purchaseFailedUI != null)
{
purchaseFailedUI.SetActive(true);
StartCoroutine(HideUI(purchaseFailedUI, 2f));
}
}
private IEnumerator HideUI(GameObject ui, float duration)
{
if (ui == null) yield break;
yield return new WaitForSeconds(duration);
if (ui != null && gameObject != null && gameObject.activeInHierarchy)
{
ui.SetActive(false);
}
}
public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
{
Debug.LogError($"Purchase failed - Product: {product.definition.id}, Reason: {failureReason}");
ShowPurchaseResult(false);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c05dd064c165a49468fdd8d8ba6ba56b

View File

@@ -0,0 +1,68 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class MainStore2 : MonoBehaviour{
public GameObject ButtonToToggleMenu;
public GameObject MenuToToggle;
// public GameObject OutsideMenuArea;
Button button;
// Button OutsideMenu_button;
public GameObject[] OutsideMenu_gameObjects; // Array to hold the list of GameObjects
void OnEnable(){
MenuToToggle.SetActive(false);
// Get the Button component from the GameObject
button = ButtonToToggleMenu.GetComponent<Button>();
// OutsideMenu_button = OutsideMenuArea.GetComponent<Button>();
}
// This method is called when the button is clicked
public void ToggleObject(){
Debug.Log("YK");
// Check if the objectToToggle is active
bool isActive = MenuToToggle.activeSelf;
Debug.Log(isActive);
// Toggle the active state of the object
MenuToToggle.SetActive(!isActive);
}
public void CloseMenu(){
MenuToToggle.SetActive(false);
}
// Start is called before the first frame update
void Start(){
// Add an onClick listener to the button
button.onClick.AddListener(ToggleObject);
// Loop through each GameObject in the array
foreach (GameObject obj in OutsideMenu_gameObjects){
// Add a pointer click listener to each GameObject
EventTrigger trigger = obj.GetComponent<EventTrigger>();
if (trigger == null){
trigger = obj.AddComponent<EventTrigger>();
}
EventTrigger.Entry entry = new EventTrigger.Entry { eventID = EventTriggerType.PointerClick };
entry.callback.AddListener((data) => CloseMenu());
trigger.triggers.Add(entry);
}
}
// Update is called once per frame
void Update(){
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a6c09475103b3da46aa05b104cb04396
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,320 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;
using UnityEngine.EventSystems;
using TMPro;
public class MainStore_Menu : MonoBehaviour{
public TextMeshProUGUI MenuSelection_text;
public GameObject FirstShopMenuSelectedObject;
public GameObject[] MainStoreMenu_ToggleGameObjects;
public GameObject[] Originals_GameObjects; // Array to hold the list of GameObjects
public GameObject[] Coins_GameObjects; // Array to hold the list of GameObjects
public GameObject[] BattlePass_GameObjects; // Array to hold the list of GameObjects
private GameObject[] combinedArray;
private Button[] MainStoreMenu_buttons;
private string currentActiveMenuItem;
private Color whiteColor = new Color(1f, 1f, 1f); // Color for the currently selected GameObject
private Color blue_selectedColor = new Color(0.4313726f, 0.6235294f, 0.9607843f);
private Color normalColor = new Color(0.04705882f, 0.07058824f, 0.1215686f);
void OnEnable(){
// Initialize the array to store Button components
MainStoreMenu_buttons = new Button[MainStoreMenu_ToggleGameObjects.Length];
// Iterate over each GameObject in the array
for (int i = 0; i < MainStoreMenu_ToggleGameObjects.Length; i++){
// Get the Button component from the current GameObject
Button button = MainStoreMenu_ToggleGameObjects[i].GetComponent<Button>();
// Check if the Button component exists
if (button != null)
{
// Store the Button component in the array
MainStoreMenu_buttons[i] = button;
}
else
{
Debug.LogWarning("Button component not found on GameObject: " + MainStoreMenu_ToggleGameObjects[i].name);
}
}
// MainStoreMenu_buttons = GetComponentsInChildren<Button>();
EventSystem.current.SetSelectedGameObject(null); //Clear previous selected gameobject
EventSystem.current.SetSelectedGameObject(FirstShopMenuSelectedObject);
Debug.LogWarning(FirstShopMenuSelectedObject.name);
// Find all GameObjects with the tag "MainStore_MenuItem"
// GameObject[] menuItems = GameObject.FindGameObjectsWithTag("MainStore_MenuItem");
// Concatenate the arrays
combinedArray = Originals_GameObjects.Concat(Coins_GameObjects).Concat(BattlePass_GameObjects).ToArray();
// Set the active state of each GameObject to false
foreach (GameObject menuItem in combinedArray){
menuItem.SetActive(false);
}
foreach(GameObject menuItem in MainStoreMenu_ToggleGameObjects){
setCaretDown(menuItem);
}
}
void setCaretDown(GameObject currentGameObject){
GameObject caretup_GO = (currentGameObject.transform.Find("caretUp")).gameObject;
caretup_GO.SetActive(false);
GameObject caretdown_GO = (currentGameObject.transform.Find("caretDown")).gameObject;
// Debug.Log("CD = " + caretdown_GO.name);
caretdown_GO.SetActive(true);
setTabBG(false, currentGameObject);
}
void setCaretUp(GameObject currentGameObject){
GameObject caretup_GO = (currentGameObject.transform.Find("caretUp")).gameObject;
caretup_GO.SetActive(true);
GameObject caretdown_GO = (currentGameObject.transform.Find("caretDown")).gameObject;
caretdown_GO.SetActive(false);
setTabBG(true, currentGameObject);
}
void setTabBG(bool tabBG_value, GameObject currentGameObject){
// GameObject tabBG_GO = (currentGameObject.transform.Find("Tab_BG")).gameObject;
// tabBG_GO.SetActive(tabBG_value);
}
// Method to handle button clicks
void ClickHandler(Button clickedButton){
// Determine which button is clicked
if (clickedButton != null){
GameObject selectedGameObject = clickedButton.gameObject;
string buttonName = clickedButton.gameObject.name;
// currentActiveMenuItem = clickedButton.gameObject.name;
// Debug.Log("Btn Clicked = " + buttonName);
// Debug.Log("SelectedGameObject = " + selectedGameObject);
//Perform actions based on the button clicked
switch (buttonName){
case "Originals":
GoToSelectedMenuItemChild(Originals_GameObjects);
DeactiveMenuItems(Originals_GameObjects, selectedGameObject);
break;
case "Coins":
GoToSelectedMenuItemChild(Coins_GameObjects);
DeactiveMenuItems(Coins_GameObjects, selectedGameObject);
ChangeContentToCurrentSelection("Coins");
break;
case "BattlePass":
GoToSelectedMenuItemChild(BattlePass_GameObjects);
DeactiveMenuItems(BattlePass_GameObjects, selectedGameObject);
ChangeContentToCurrentSelection("BattlePass");
break;
case "Maasai":
// GoToSelectedMenuItemChild(BattlePass_GameObjects);
// DeactiveMenuItems(BattlePass_GameObjects, selectedGameObject);
ChangeContentToCurrentSelection("Maasai1");
break;
case "Maasai2":
// GoToSelectedMenuItemChild(BattlePass_GameObjects);
// DeactiveMenuItems(BattlePass_GameObjects, selectedGameObject);
ChangeContentToCurrentSelection("Maasai2");
break;
}
}
}
void ChangeContentToCurrentSelection(string selectionText){
Debug.Log("XD = " + selectionText);
MenuSelection_text.text = selectionText;
}
//When a Menu item is selected, go to its first child as selected
void GoToSelectedMenuItemChild(GameObject[] selectedItemChild){
EventSystem.current.SetSelectedGameObject(null); //Clear previous selected gameobject
EventSystem.current.SetSelectedGameObject(selectedItemChild[0]);
}
// private GameObject currentSelectedMenu_GameObject = null;
//Deactivate all GameObject except those in ActivategameObject
void DeactiveMenuItems(GameObject[] ActivegameObject, GameObject selectedGameObject){
// Debug.Log("S = " + selectedGameObject.name);
// CheckIfMenuItemIsActive(selectedGameObject);
foreach(GameObject obj in combinedArray){
// Check if the object is within BattlePass_GameObjects, which Array items to show
bool isActiveGameObject_Present = System.Array.Exists(ActivegameObject, element => element == obj);
//If in the selected item array
if (isActiveGameObject_Present){
obj.SetActive(true);
}else{ //If not in the selected item array
obj.SetActive(false);
}
if (CheckIfMenuItemIsActive(selectedGameObject)){
Debug.Log("Already Active");
obj.SetActive(false);
}
}
// currentSelectedMenu_GameObject = selectedGameObject;
//Set the caret icon
foreach(GameObject obj in MainStoreMenu_ToggleGameObjects){
Debug.LogError(obj.name);
if (selectedGameObject != null){
if (obj == selectedGameObject){
if (CheckIfMenuItemIsActive(obj) == true){
Debug.LogError("A");
setCaretDown(selectedGameObject);
}else{
// if (CheckIfMenuItemIsActive(obj) == false){
Debug.LogError("N");
setCaretUp(selectedGameObject);
}
}
// if ((obj == selectedGameObject) && (CheckIfMenuItemIsActive(obj))){
// Debug.Log("Carat Already Active");
// setCaretDown(obj);
// }
// if ((obj == selectedGameObject) && !(CheckIfMenuItemIsActive(obj))){
// // Debug.Log("YUP");
// setCaretUp(selectedGameObject);
// }
if (obj != selectedGameObject){
// Debug.Log("NOPE");
setCaretDown(obj);
}
}
}
}
public bool CheckIfMenuItemIsActive(GameObject menuItem){
GameObject caretup_GO = (menuItem.transform.Find("caretUp")).gameObject;
//If Active
if (caretup_GO.activeSelf){
Debug.Log(menuItem.name + " Already Active");
return true;
}else{
Debug.Log(menuItem.name + " Not Active");
return false;
}
}
// Start is called before the first frame update
void Start(){
foreach (Button button in MainStoreMenu_buttons){
button.onClick.AddListener(() => ClickHandler(button));
}
}
void ChangeCurrentSelectedGameObject(GameObject selectedObject){
// Find the child GameObject named "text" under the selectedObject
Transform textTransform = selectedObject.transform.Find("text");
// Transform imgTransform = selectedObject.transform.Find("img_icon");
// //There is a text element child found
if (textTransform != null){
TextMeshProUGUI textMesh = textTransform.GetComponent<TextMeshProUGUI>();
textMesh.fontSize = 145;
}
// if (imgTransform != null){
// RectTransform rectTransform = imgTransform.GetComponent<RectTransform>(); //Get the RectTransform component of the child GameObject
// rectTransform.sizeDelta = new Vector2(50, 50); //Set the size of the RectTransform component
// }
// Debug.Log("Current = " + selectedObject.name);
Image image = selectedObject.GetComponent<Image>(); //Get the Image component attached to the selected GameObject
image.color = whiteColor;
Button btn = selectedObject.GetComponent<Button>();
ColorBlock colors = btn.colors; //Get the colors structure of the button
colors.normalColor = blue_selectedColor; //Assign the selected color to the selected state
btn.colors = colors; //Assign the modified colors back to the button
}
private static GameObject lastSelectedObject = null;
// Update is called once per frame
void Update(){
if ((EventSystem.current != null)){
GameObject selectedObject = EventSystem.current.currentSelectedGameObject; // Get the currently selected GameObject
// lastMenuSceneSelectedObject = selectedObject;
Debug.Log("Sel = " + selectedObject.name);
ChangeCurrentSelectedGameObject (selectedObject);
// Check if the current selected GameObject is different from the last selected GameObject
if ((selectedObject != lastSelectedObject) && (lastSelectedObject != null)){
// Check if the GameObject has an Image component
Image lastImage = lastSelectedObject.GetComponent<Image>();
lastImage.color = normalColor;
Button btn = lastSelectedObject.GetComponent<Button>();
ColorBlock colors = btn.colors; //Get the colors structure of the button
colors.normalColor = whiteColor; //Assign the selected color to the selected state
btn.colors = colors; //Assign the modified colors back to the button
Transform textTransform2 = lastSelectedObject.transform.Find("text");
// Transform imgTransform2 = lastSelectedObject.transform.Find("img_icon");
if (textTransform2 != null){
TextMeshProUGUI textMesh = textTransform2.GetComponent<TextMeshProUGUI>();
textMesh.fontSize = 125;
}
// if (imgTransform2 != null){
// // Get the RectTransform component of the child GameObject
// RectTransform rectTransform = imgTransform2.GetComponent<RectTransform>();
// // Set the size of the RectTransform component
// rectTransform.sizeDelta = new Vector2(40, 40);
// }
// Update the reference to the last selected GameObject
lastSelectedObject = selectedObject;
}
if (lastSelectedObject == null){
lastSelectedObject = selectedObject;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5ce3f9070783020489a0bd6057462375
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0d11a5d970055744499c99af026a71cd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,136 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;
using UnityEngine.EventSystems;
using TMPro;
public class MainStore : MonoBehaviour{
public Button MenuTogglerButton; //Reference to the Button used to Toggle the Menu's state
public GameObject Menu; //Reference to the Menu to be shown
public GameObject[] ParentChildPrefab; //First item is Parent, Second item is Child
public GameObject ContainerParentChildPrefab; //Container for the Menu Items
public Sprite[] MenuDropdownSprites; //Icons for menu items which are dropdowns in the Menu, 0 = Caret down, 1 = Caret up
//Menu Items in the Menu, they will be added dynamically to the Menu in the Shop UI
private Dictionary<string, List<string>> menuData = new Dictionary<string, List<string>>()
{
{ "Outfits", new List<string> { "Maasai1", "Maasai2" } }, //Dropdown
{ "Coins", null }, //Not dropdown
{ "BattlePass", null }, //Not dropdown
{ "Characters", null }, //Not dropdown
};
void OnEnable(){
Menu.SetActive(false); //Sets initial state of Menu when the UI is activated
}
void Start(){
MenuTogglerButton.onClick.AddListener(() => ToggleMenu("toggle"));
PopulateMenu();
}
void PopulateMenu(){
foreach (var item in menuData){
string key = item.Key;
List<string> children = item.Value;
// Console.WriteLine(key);
if (children != null)
{
InstantiateMenuItem(key, "parent", "isDropdown");
Debug.Log(key); //Parent
foreach (string child in children)
{
InstantiateMenuItem(child, "child", "isDropdown");
Debug.Log(" - " + child); //Child
}
}
//If there are no children, not a dropdown
if (children == null){
InstantiateMenuItem(key, "parent", "isNotDropdown");
// isNotDropdown();
}
}
//Remove the Menu Item Prefabs
foreach (GameObject obj in ParentChildPrefab){
obj.SetActive(false);
}
}
void InstantiateMenuItem(string MenuItemName, string MenuItemType, string MenuItemParentType){
GameObject MenuItem_Instance;
switch(MenuItemType){
case "parent":
MenuItem_Instance = Instantiate(ParentChildPrefab[0], ContainerParentChildPrefab.transform);
if (MenuItemParentType == "isNotDropdown"){
ParentisNotDropdown(MenuItem_Instance);
}
(MenuItem_Instance.transform.Find("text")).GetComponent<TextMeshProUGUI>().text = MenuItemName;
MenuItem_Instance.name = MenuItemName;
break;
case "child":
MenuItem_Instance = Instantiate(ParentChildPrefab[1], ContainerParentChildPrefab.transform);
(MenuItem_Instance.transform.Find("text")).GetComponent<TextMeshProUGUI>().text = MenuItemName;
MenuItem_Instance.name = MenuItemName;
break;
}
}
//Changes state of the Menu, if Open then Closes it and vice versa
void ToggleMenu(string menuStatus){
bool isActive = Menu.activeSelf; //Check if the Menu is active
bool currentMenuStatus = !isActive;
if (menuStatus == "toggle"){
Menu.SetActive(currentMenuStatus); //Change the current state of the Menu, if false then true, and vice versa
}else if(menuStatus == "close"){
Menu.SetActive(false);
}
//Menu has been opened
if (currentMenuStatus == true){
// MenuIsOpen();
}
}
//When Menu is Opened, set the Selected Item within the Menu
void MenuIsOpen(){
// foreach(GameObject obj in MenuParents){
// setCaretDown(obj);
// }
// SetMenuSelectedGameObject(MenuParents[0]);
// ShowHideChildren(new GameObject[0]); //Pass empty array, so all children are hidden
}
void ParentisNotDropdown(GameObject MenuItem_Instance){
GameObject caret_GameObject = (MenuItem_Instance.transform.Find("caret")).gameObject;
caret_GameObject.SetActive(false);
Debug.Log("Parent is Not Dropdown");
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6c81c92b23c4f4345ac6054f351dcfec
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,158 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System;
using System.Linq;
//ONLY FOR TESTING
#region
//Progress of missions
[System.Serializable]
public class ProductDetails{
public string productID; //records the week the player is at
public string productName;
public string productDescription; //records the week the player is at
public int productPrice; //records the week the player is at
public string productImage;
}
#endregion
public class PopulateStore : MonoBehaviour
{
public GameObject[] BBundle_Prefab; //Big Bundle, The 1st is Container, 2nd is Prefab
public GameObject[] SBundle_Prefab; //Big Bundle, The 1st is Container, 2nd is Prefab
public GameObject[] ProductPage; //0 is the gameobject for the individual product page, 1 is product page dismiss button
[HideInInspector]
public List<ProductDetails> retrievedProductDetails, retrievedBundleProductDetails;
public Sprite[] productSprites; // Array of product sprites
// private Dictionary<string, string, string> SamplePurchaseItems = new Dictionary<string, string, string>()
// {
// { "Outfit1", "1", "2" }, //Dropdown
// { "Outfit2", "3", "4" }, //Not dropdown
// { "Outfit3", "5", "6" }, //Not dropdown
// };
void onEnable(){
}
void Awake(){
Button ProductPageDismissBtn = ProductPage[1].GetComponent<Button>();
ProductPageDismissBtn.onClick.AddListener(BackButton_RemoveProductPage);
retrievedBundleProductDetails = new List<ProductDetails>{
new ProductDetails { productID = "com.ex.cat1", productName = "Cat", productDescription = "Cat Character", productPrice = 40, productImage = "Cat4X-removebg-preview 2" },
new ProductDetails { productID = "com.ex.cheetah2", productName = "Cheetah", productDescription = "Cheetah Character", productPrice = 50, productImage = "Cheetah5X-removebg-preview 2" },
new ProductDetails { productID = "com.ex.hyena3", productName = "Hyena", productDescription = "Hyena Character", productPrice = 60, productImage = "Heyna3X-removebg-preview 2" },
new ProductDetails { productID = "com.ex.cat1", productName = "Cat", productDescription = "Cat Character", productPrice = 40, productImage = "Cat4X-removebg-preview 2" },
new ProductDetails { productID = "com.ex.cheetah2", productName = "Cheetah", productDescription = "Cheetah Character", productPrice = 50, productImage = "Cheetah5X-removebg-preview 2" },
new ProductDetails { productID = "com.ex.hyena3", productName = "Hyena", productDescription = "Hyena Character", productPrice = 60, productImage = "Heyna3X-removebg-preview 2" },
new ProductDetails { productID = "com.ex.cat1", productName = "Cat", productDescription = "Cat Character", productPrice = 40, productImage = "Cat4X-removebg-preview 2" },
new ProductDetails { productID = "com.ex.cheetah2", productName = "Cheetah", productDescription = "Cheetah Character", productPrice = 50, productImage = "Cheetah5X-removebg-preview 2" },
new ProductDetails { productID = "com.ex.hyena3", productName = "Hyena", productDescription = "Hyena Character", productPrice = 60, productImage = "Heyna3X-removebg-preview 2" },
};
retrievedProductDetails = new List<ProductDetails>{
new ProductDetails { productID = "com.ex.cat", productName = "Cat", productDescription = "Cat Character", productPrice = 40, productImage = "Cat4X-removebg-preview 2" },
new ProductDetails { productID = "com.ex.cheetah", productName = "Cheetah", productDescription = "Cheetah Character", productPrice = 50, productImage = "Cheetah5X-removebg-preview 2" },
new ProductDetails { productID = "com.ex.hyena", productName = "Hyena", productDescription = "Hyena Character", productPrice = 60, productImage = "Heyna3X-removebg-preview 2" },
new ProductDetails { productID = "com.ex.hippo", productName = "Hippo", productDescription = "Hippo Character", productPrice = 80, productImage = "Hipos2X-removebg-preview 2" },
new ProductDetails { productID = "com.ex.hammerhead", productName = "HammerHead", productDescription = "HammerHead Character", productPrice = 100, productImage = "hM3X-removebg-preview 2" },
};
}
// Start is called before the first frame update
void Start()
{
//Bundle
foreach (ProductDetails prodDet in retrievedBundleProductDetails){
GameObject MenuItem_Instance = Instantiate(BBundle_Prefab[1], BBundle_Prefab[0].transform);
Button GameObject_Button = MenuItem_Instance.GetComponent<Button>();
GameObject_Button.onClick.AddListener(() => ShowProductPage(prodDet));
Debug.Log(prodDet.productID + "\n");
}
BBundle_Prefab[1].SetActive(false);
//Small Product
foreach (ProductDetails prodDet in retrievedProductDetails){
GameObject MenuItem_Instance = Instantiate(SBundle_Prefab[1], SBundle_Prefab[0].transform);
Button GameObject_Button = MenuItem_Instance.GetComponent<Button>();
GameObject_Button.onClick.AddListener(() => ShowProductPage(prodDet));
Debug.Log(prodDet.productID + "\n");
}
SBundle_Prefab[1].SetActive(false);
}
void BackButton_RemoveProductPage(){
ProductPage[0].SetActive(false);
}
void ShowProductPage(ProductDetails productDetails)
{
ProductPage[0].SetActive(true);
Debug.Log($"Product ID: {productDetails.productID}\nProduct Name: {productDetails.productName}\nProduct Description: {productDetails.productDescription}\nProduct Price: {productDetails.productPrice}");
// Get the TextMeshProUGUI component from the "productName" GameObject
TextMeshProUGUI productNameText = ProductPage[0].transform.Find("CharacterPurchase/productName").GetComponent<TextMeshProUGUI>();
productNameText.text = productDetails.productName;
TextMeshProUGUI productPriceText = ProductPage[0].transform.Find("CharacterPurchase/GameObject (2)/productPrice/price").GetComponent<TextMeshProUGUI>();
productPriceText.text = (productDetails.productPrice).ToString();
// GameObject fkw = ProductPage[0].transform.Find("CharacterPurchase/Panel/item_image").gameObject;
// fkw.name = "fkw";
// Get the Image component from the "item_image" GameObject
Image itemImage = ProductPage[0].transform.Find("CharacterPurchase/Panel/item_image").GetComponent<Image>();
Sprite newSprite = FindSpriteByName(productDetails.productImage);
if (newSprite != null)
{
itemImage.sprite = newSprite;
}
else
{
Debug.LogError("Failed to load image with name: " + productDetails.productImage);
}
}
Sprite FindSpriteByName(string spriteName)
{
foreach (Sprite sprite in productSprites)
{
if (sprite.name == spriteName)
{
return sprite;
}
}
return null;
}
//API-ish
void GetProductDataByID(string productID){
// MissionInfo mission = missionInfo.Find(m => m.missionID == missionID);
// return mission.missionProgressCount;
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6ffb34de054161748ad9a240bbe8b9ca
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,59 @@
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class StoreUIManager : MonoBehaviour
{
[Header("Store UI Elements")]
[SerializeField] private GameObject storePanel;
[SerializeField] private Button buyButton;
[SerializeField] private Button cancelButton;
[SerializeField] private TextMeshProUGUI productDetailsText;
private IAPManager iapManager;
private string currentProductID;
private int currentCoinsToAdd;
private void Awake()
{
// Initialize the IAPManager
iapManager = FindObjectOfType<IAPManager>();
// Add listeners to buttons
buyButton.onClick.AddListener(OnBuyClicked);
cancelButton.onClick.AddListener(OnCancelClicked);
// Hide the store UI initially
storePanel.SetActive(false);
}
// Show the store UI with product details
public void ShowStore(string productID, int coinsToAdd)
{
currentProductID = productID;
currentCoinsToAdd = coinsToAdd;
// Update product details (optional)
productDetailsText.text = $"Do you want to buy {coinsToAdd} coins?";
// Show the store panel
storePanel.SetActive(true);
}
// Called when the "Buy" button is clicked
private void OnBuyClicked()
{
// Call the IAPManager to initiate the purchase
iapManager.BuyProduct(currentProductID, currentCoinsToAdd);
// Hide the store panel after initiating the purchase
storePanel.SetActive(false);
}
// Called when the "Cancel" button is clicked
private void OnCancelClicked()
{
// Just close the store panel without doing anything
storePanel.SetActive(false);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0d0b84fd8c738534298650d783da7811

View File

@@ -0,0 +1,44 @@
using UnityEngine;
using UnityEngine.UI;
public class UIProduct : MonoBehaviour
{
[Header("Coin Package Buttons")]
[SerializeField] private Button purchaseButton1000Coins; // Button for purchasing 1000 coins
[SerializeField] private Button purchaseButton2150Coins; // Button for purchasing 2150 coins
[SerializeField] private Button purchaseButton4350Coins; // Button for purchasing 4350 coins
[SerializeField] private Button purchaseButton6700Coins; // Button for purchasing 6700 coins
[SerializeField] private Button purchaseButton11500Coins; // Button for purchasing 11500 coins
private IAPManager iapManager;
private StoreUIManager storeUIManager;
private void Start()
{
// Find the IAPManager and StoreUIManager components in the scene
iapManager = FindObjectOfType<IAPManager>();
storeUIManager = FindObjectOfType<StoreUIManager>();
if (iapManager != null && storeUIManager != null)
{
// Assign button listeners to show the store UI and pass product details
purchaseButton1000Coins.onClick.AddListener(() => ShowStoreUI(IAPManager.PRODUCT_1000_COINS, 1000));
purchaseButton2150Coins.onClick.AddListener(() => ShowStoreUI(IAPManager.PRODUCT_2150_COINS, 2150));
purchaseButton4350Coins.onClick.AddListener(() => ShowStoreUI(IAPManager.PRODUCT_4350_COINS, 4350));
purchaseButton6700Coins.onClick.AddListener(() => ShowStoreUI(IAPManager.PRODUCT_6700_COINS, 6700));
purchaseButton11500Coins.onClick.AddListener(() => ShowStoreUI(IAPManager.PRODUCT_11500_COINS, 11500));
}
else
{
Debug.LogError("IAPManager or StoreUIManager not found in the scene.");
}
}
// Method to show the store UI with the correct product details
private void ShowStoreUI(string productID, int coinsToAdd)
{
// Pass product ID and the number of coins to the StoreUIManager to display
storeUIManager.ShowStore(productID, coinsToAdd);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 2b8cf7eee5a0250469c3f0a32d193896