Ejemplo n.º 1
0
    //Change the current merchant tab
    public void ChangeTab(uGUIMerchantTab tab)
    {
        //If the selected tab is of type repair then hide the repair window
        if (selectedTab.tabType == TabType.repair)
        {
            repair.SetActive(false);
        }

        //Set the selected tabs color to inactive
        selectedTab.GetComponent <Image>().color = tabInactiveColor;

        //Assign the clicked tab to the selected tab
        selectedTab = tab;
        //Set the color of the newly selected tab to active
        selectedTab.GetComponent <Image>().color = tabActiveColor;

        //If the selected tab isn't of type repair
        if (tab.tabType != TabType.repair)
        {
            //Run through all the tabs and the reset the items in them
            ResetTabs();
        }
        //Else if it is of type repair then show the repair tab
        else
        {
            repair.SetActive(true);
        }
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        //If the player right clicks
        if (Input.GetMouseButtonDown(1))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            //Send a ray to the position of the mouse
            if (Physics.Raycast(ray, out hit, Mathf.Infinity))
            {
                //If the ray hits the merchant
                if (hit.transform.CompareTag("MerchantController") && hit.transform == transform)
                {
                    //Set the selected merchant to be this one
                    merchant.selectedMerchant = this;

                    //Open the merchant
                    merchant.OpenCloseMerchant(true);

                    //remove all the tabs of the merchant
                    foreach (uGUIMerchantTab t in merchant.tabsObj.GetComponentsInChildren <uGUIMerchantTab>())
                    {
                        merchant.tabs.Remove(t);
                        Destroy(t.gameObject);
                    }

                    //instantiate the tabs that this merchant has
                    for (int i = 0; i < tabs.Count; i++)
                    {
                        if (tabs[i].tabType != TabType.buyBack || (tabs[i].tabType == TabType.buyBack && tabs[i].items.Count != 0))
                        {
                            GameObject tempTab = Instantiate(merchant.tabPrefab) as GameObject;
                            tempTab.transform.SetParent(merchant.tabsObj.transform);
                            tempTab.transform.localScale         = Vector3.one;
                            tempTab.GetComponent <Image>().color = merchant.tabInactiveColor;
                            uGUIMerchantTab tab = tempTab.AddComponent <uGUIMerchantTab>();
                            tab.tabType = tabs[i].tabType;
                            tab.items   = tabs[i].items;
                            tempTab.GetComponent <Image>().sprite = tabs[i].tabSprite;
                            merchant.tabs.Add(tab);
                        }
                    }

                    //If the merchant can repair then add the repair tab
                    if (canRepair)
                    {
                        GameObject tempTab = Instantiate(merchant.tabPrefab) as GameObject;
                        tempTab.transform.SetParent(merchant.tabsObj.transform);

                        tempTab.transform.localScale         = Vector3.one;
                        tempTab.GetComponent <Image>().color = merchant.tabInactiveColor;
                        uGUIMerchantTab tab = tempTab.AddComponent <uGUIMerchantTab>();
                        tab.tabType = TabType.repair;
                        tab.items   = new List <ItemClass>();
                        tempTab.GetComponent <Image>().sprite = repairSprite;
                        merchant.tabs.Add(tab);
                    }

                    //Set the seleted tab of the merchant to be equal to the first of this merchants tabs
                    merchant.selectedTab = merchant.tabs[0];
                    merchant.selectedTab.GetComponent <Image>().color = merchant.tabActiveColor;
                    merchant.ChangeTab(merchant.selectedTab);

                    merchant.tabsObj.GetComponent <RectTransform>().sizeDelta = new Vector2(merchant.tabWidth, merchant.tabHeight * merchant.tabs.Count);

                    //set the items of the merchant's tabs
                    for (int i = 0; i < merchant.tabs.Count; i++)
                    {
                        for (int j = 0; j < tabs.Count; j++)
                        {
                            if (merchant.tabs[i].tabType == tabs[j].tabType)
                            {
                                merchant.tabs[i].items = tabs[j].items;
                            }
                        }
                    }
                }
            }
        }
        //If the player is further away from the merchant than the interaction range of the merchant then close the merchant window
        if (Vector3.Distance(player.transform.position, transform.position) > interactionRange && merchant.selectedMerchant == this)
        {
            merchant.OpenCloseMerchant(false);
        }
    }