Exemple #1
0
    public void Upgrade(GameObject item)
    {
        SellableItem    sellItem     = item.GetComponent <SellableItem>();
        XMLVendorReader vendorReader = GameObject.Find("XMLReader").GetComponent <XMLVendorReader>();

        if (sellItem.currentUpgrade < 2)
        {
            if (sellItem.upgradedItem)
            {
                GameObject upgradedItem = ObjectPool.Spawn(sellItem.upgradedItem, sellItem.gameObject.transform.position, sellItem.gameObject.transform.rotation);
                upgradedItem.name = sellItem.upgradedItem.name;
                upgradedItem.GetComponent <Dragable>().enabled   = true;
                upgradedItem.GetComponent <Dragable>().canUpdate = true;
                SellableItem itemToUpgrade = upgradedItem.GetComponent <SellableItem>();
                itemToUpgrade.cost = vendorReader.GetCurrentFortificationCost(itemToUpgrade.cost, itemToUpgrade.itemName, itemToUpgrade.currentUpgrade);
                vendorReader.SetFortData(itemToUpgrade.gameObject);
                vendorReader.UpgradeFortificationData(itemToUpgrade.itemName, itemToUpgrade.currentUpgrade);
                GameController.Instance.DeleteResources(itemToUpgrade.cost);
                UIManager.Instance.SetFortification(upgradedItem);
                //UIManager.Instance.uiState = UIManager.UIState.NONE;
                Destroy(sellItem.gameObject);
            }
            else
            {
                GameController.Instance.DeleteResources(sellItem.cost);
                vendorReader.SetFortData(sellItem.gameObject);
                vendorReader.UpgradeFortificationData(sellItem.itemName, sellItem.currentUpgrade);
                sellItem.currentUpgrade += 1;
                if (sellItem.currentUpgrade < 2)
                {
                    sellItem.cost = vendorReader.GetCurrentFortificationCost(sellItem.cost, sellItem.itemName, sellItem.currentUpgrade);
                }
            }
        }
    }
    void DrawUpgradeScreen(Rect drawRect, GUIStyle style)
    {
        GUI.BeginGroup(drawRect);

        GUI.DrawTexture(new Rect(0, 0, drawRect.width, drawRect.height), backGround);

        XMLVendorReader vendorReader = GameObject.Find("XMLReader").GetComponent <XMLVendorReader>();
        SellableItem    sellItem     = null;

        if (curItem.GetComponent <SellableItem>().upgradedItem)
        {
            sellItem = curItem.GetComponent <SellableItem>().upgradedItem.GetComponent <SellableItem>();
        }
        if (sellItem != null)
        {
            if (sellItem.currentUpgrade <= 2)
            {
                sellItem.cost = vendorReader.GetCurrentFortificationCost(sellItem.cost, sellItem.itemName, sellItem.currentUpgrade);
            }

            if (GameController.Instance.GetResources() >= sellItem.cost)
            {
                if (GUI.Button(new Rect(drawRect.width - 180, drawRect.height - 250, 150, 50), "UPGRADE: " + sellItem.cost, style))
                {
                    itemVendor.Upgrade(curItem);
                }

                GUI.Label(new Rect(drawRect.width - 200, drawRect.height - 200, 200, 100),
                          sellItem.GetComponent <SellableItem>().description, descriptionStyle);
            }
            else
            {
                GUI.Label(new Rect(drawRect.width - 180, drawRect.height - 250, 150, 50), "NOT ENOUGH FUNDS", style);
            }
        }
        else
        {
            GUI.Label(new Rect(drawRect.width - 180, drawRect.height - 250, 150, 50), "FULLY UPGRADED", style);
        }

        if (GUI.Button(new Rect(drawRect.width - 150, drawRect.height - 100, 100, 50), "BACK", style))
        {
            state = State.FORTINFO;
        }

        GUI.EndGroup();
    }
 void Start()
 {
     vendorReader = GameObject.Find("XMLReader").GetComponent <XMLVendorReader>();
 }