示例#1
0
    private void SetListener()
    {
        //set all the listener for the function related to the button onClick
        switch (gameObject.tag)
        {
        case StaticDb.telephoneTag:
            TutorialTelephoneListener telephoneListener = GetComponent <TutorialTelephoneListener>();
            telephoneListener.SetTelephoneListeners();
            break;

        case StaticDb.securityCheckTag:
            TutorialSecurityListener securityListener = GetComponent <TutorialSecurityListener>();
            securityListener.SetSecurityListeners();
            break;

        case StaticDb.roomPcTag:
            TutorialRoomPcListener roomPcListener = GetComponent <TutorialRoomPcListener>();
            roomPcListener.SetComputerListeners();
            break;

        case StaticDb.serverPcTag:
            TutorialServerPcListener serverPcListener = GetComponent <TutorialServerPcListener>();
            serverPcListener.SetSeverPcListeners();
            break;

        default:
            actionButtonManager.ResetButtonOnClick();
            break;
        }
    }
示例#2
0
    private void OnEnable()
    {
        manager         = SetLevelManager();
        tutorialManager = FindObjectOfType <TutorialManager>();

        sprites = Resources.LoadAll <Sprite>("ItemStoreSprite");

        roomPcListener         = FindObjectOfType <RoomPcListener>();
        tutorialRoomPcListener = FindObjectOfType <TutorialRoomPcListener>();

        scrollRect = gameObject.GetComponentInChildren <ScrollRect>();

        itemAsset = new List <TextAsset>();
        itemAsset = Resources.LoadAll <TextAsset>("ItemStore").ToList();
        content   = scrollRect.content;

        content.sizeDelta = new Vector2(content.sizeDelta.x, 300f * (itemAsset.Count - 1));

        itemList = manager != null
            ? manager.GetGameData().itemStoreList
            : tutorialManager.tutorialGameData.itemStoreList;


        itemDescription = GameObject.Find("InfoTxt").GetComponent <TextMeshProUGUI>();

        backBtn = GameObject.Find("BackBtn").GetComponent <Button>();
        backBtn.onClick.RemoveAllListeners();
        backBtn.onClick.AddListener(delegate
        {
            if (manager != null)
            {
                if (manager.GetGameData().storeEnabled)
                {
                    roomPcListener.ToggleStoreScreen();
                }
            }
            else
            {
                if (tutorialManager.tutorialGameData.storeEnabled)
                {
                    tutorialRoomPcListener.ToggleStoreScreen();
                }
            }
        });

        //POPULATE ITEMLIST
        if (itemList.Count == 0)
        {
            foreach (TextAsset textAsset in itemAsset)
            {
                ItemStore itemStore = ItemStoreFromJson(textAsset);
                itemList.Add(itemStore);
            }
        }

        //SORT ITEMLIST
        itemList.Sort(ItemStore.nameComparer);

        foreach (ItemStore item in itemList)
        {
            GameObject itemOnList = ClassDb.prefabManager.GetPrefab(ClassDb.prefabManager.prefabStoreItem.gameObject, PrefabManager.storeItemIndex);
            item.itemObject = itemOnList;
            itemOnList.transform.SetParent(content);
            itemOnList.transform.localScale = Vector3.one;
            itemOnList.name = "Item" + itemList.IndexOf(item);
            itemOnList.GetComponentsInChildren <TextMeshProUGUI>()[0].text = item.name.ToUpper();
            itemOnList.GetComponentsInChildren <TextMeshProUGUI>()[2].text = item.currentLevel.ToString();
            itemOnList.GetComponentsInChildren <TextMeshProUGUI>()[3].text = item.price.ToString();
            itemOnList.GetComponent <Button>().onClick.RemoveAllListeners();
            ItemStore item1 = item;
            itemOnList.GetComponent <Button>().onClick.AddListener(delegate
            {
                if (manager.GetGameData().itemStoreSelected.itemObject != null)
                {
                    manager.GetGameData().itemStoreSelected.itemObject.GetComponent <Button>().image.sprite = sprites[0];
                }
                manager.GetGameData().itemStoreSelected = item1;
                item1.itemObject.GetComponent <Button>().image.sprite = sprites[sprites.Length - 1];
                SetDescription(manager.GetGameData().itemStoreSelected);
            });
            CheckItemLevel(item);
        }

        if (manager != null)
        {
            purchaseButton.onClick.RemoveAllListeners();
            purchaseButton.onClick.AddListener(delegate
            {
                ClassDb.levelMessageManager.StartConfirmPurchase(manager.GetGameData().itemStoreSelected);
            });
        }
        else
        {
            purchaseButton.interactable = false;
        }


        //disable interact with button until tutorial is finished
        if (SceneManager.GetActiveScene().buildIndex == StaticDb.tutorialSceneIndex)
        {
            foreach (ItemStore item in itemList)
            {
                item.itemObject.GetComponent <Button>().interactable = false;
            }
        }
        else
        {
            foreach (ItemStore item in itemList)
            {
                CheckItemLevel(item);
            }
        }
    }