Beispiel #1
0
    void OnGUI()
    {
        if (ShopMenu)
        {
            open.fontSize = Screen.width / 23;
            shopStatus    = "Press O to open";
            GUI.Label(new Rect(0, 0, 300, 30), shopStatus, open);
            shopOpen = true;
        }
        if (paused)
        {
            shopStatus = "";
            if (shopAssistantType == "buy")
            {
                buyingStuff();

                moneySize.fontSize = (int)(Screen.height / 30);
                GameObject        objGame  = GameObject.FindGameObjectWithTag("Constant");
                StoredInformation storedIN = objGame.GetComponent <StoredInformation>();
                GUI.Label(new Rect((((Screen.width / 2) - (groupWidth / 2))),
                                   (((Screen.height / 2) - (groupHeight / 2)) - (Screen.height / 23)),
                                   Screen.width, Screen.height), "Total Money : " + storedIN.moneyTotal, moneySize);
                if ((!money.test) && (shopPurchase))
                {
                    boughtOrNOt = "Not enough money to buy";
                }
                else
                {
                    boughtOrNOt = "";
                }
                if ((money.test) && (shopPurchase))
                {
                    boughtOrNOt = "Item Bought";
                }
                else
                {
                    boughtOrNOt = "";
                }
                GUI.Label(new Rect((Screen.width / 2),
                                   (((Screen.height / 2) - (groupHeight / 2)) - (Screen.height / 23)),
                                   Screen.width, Screen.height), boughtOrNOt, moneySize);

                GUI.BeginGroup(new Rect(((Screen.width / 2) - (groupWidth / 2)),
                                        ((Screen.height / 2) - (groupHeight / 2)),
                                        Screen.width, Screen.height));
                int startingPosLeft = 0;
                int StartingPosTop  = 0;
                int itemPrice       = 0;
                ga = GameObject.FindGameObjectsWithTag(shopType);
                string details = "";
                bool   buyingAttempt;
                for (int cnt = 0; cnt < fileReading._name.Length; cnt++)
                {
                    if ((ga[counter].GetComponent <ReadAFile>()._name[cnt] != null) && (ga[counter].GetComponent <ReadAFile>()._name[cnt] != ""))
                    {
                        if (shopType == "Magic")
                        {
                            details = "Ability";
                        }
                        if (shopType == "Weapon")
                        {
                            details = "Power";
                        }
                        if (shopType == "Item")
                        {
                            details = "Recovers";
                        }
                        if (GUI.Button(new Rect(startingPosLeft, StartingPosTop, widthOfButton, buttonHeight),
                                       "Name : " + ga[counter].GetComponent <ReadAFile>()._name[cnt] +
                                       "\r\n " + details + " : " + ga[counter].GetComponent <ReadAFile>()._id[cnt] +
                                       "\r\n Price : " + ga[counter].GetComponent <ReadAFile>()._price[cnt]))
                        {
                            itemPrice = int.Parse(ga[counter].GetComponent <ReadAFile>()._price[cnt]);

                            if ((storedIN.moneyTotal - itemPrice) > -1)
                            {
                                money.processMoney("minus", itemPrice);

                                if (money.test)
                                {
                                    storedIN.moneyTotal -= itemPrice;
                                    info.addItems(ga[counter].GetComponent <ReadAFile>()._name[cnt], ga[counter].GetComponent <ReadAFile>()._id[cnt]);
                                    boughtOrNOt  = "Item Purchased";
                                    shopPurchase = true;
                                }
                                else
                                {
                                    GUI.Label(new Rect(((Screen.width / 2) - (groupWidth / 2)),
                                                       ((Screen.height / 2) - (groupHeight / 2)) - 100,
                                                       Screen.width, Screen.height), " Not enough money  to buy");
                                    shopPurchase = true;
                                }
                            }
                        }
                    }
                    startingPosLeft += widthOfButton;
                    if (startingPosLeft >= groupWidth)
                    {
                        startingPosLeft = 0;
                        StartingPosTop += buttonHeight + 20;
                    }
                }
                GUI.EndGroup();
            }
            if (shopAssistantType == "sell")
            {
                sellBits();
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// Loads the data.
    /// </summary>
    public void LoadData()
    {
        GameObject objGame = GameObject.FindGameObjectWithTag("Constant");

        StoredInformation storedIN = objGame.GetComponent <StoredInformation>();

        characterName          = PlayerPrefs.GetString("Player Name");
        storedIN.characterName = PlayerPrefs.GetString("Player Name");

        moneyTotal = PlayerPrefs.GetInt("Money");

        level      = PlayerPrefs.GetInt("Level");
        experience = PlayerPrefs.GetInt("Experience");

        storedIN.level      = level;
        storedIN.experience = experience;

        if (PlayerPrefs.GetInt("ExperienceTONextLevel") <= 1)
        {
            nextLevelvalue          = experience * 1.2f;
            storedIN.nextLevelvalue = experience * 1.2f;

            storedIN.nextLevel = (int)(experience * 1.2f);
            nextLevel          = (int)(experience * 1.2f);
        }
        else
        {
            nextLevelvalue          = (float)PlayerPrefs.GetInt("ExperienceTONextLevel");
            storedIN.nextLevelvalue = (float)PlayerPrefs.GetInt("ExperienceTONextLevel");
            storedIN.nextLevel      = PlayerPrefs.GetInt("ExperienceTONextLevel");
            nextLevel = PlayerPrefs.GetInt("ExperienceTONextLevel");
        }

        storedIN.positionOnScreen.x = PlayerPrefs.GetFloat("Position - x");
        storedIN.positionOnScreen.y = PlayerPrefs.GetFloat("Position - y");
        storedIN.positionOnScreen.z = PlayerPrefs.GetFloat("Position - z");
        if (Application.loadedLevelName != "Game")
        {
            PlayerPosition pl;

            pl = new PlayerPosition();
            pl.Awake();

            pl.SetPosition(storedIN.positionOnScreen, Application.loadedLevelName);
        }
        #region - modified code region
        ///<summary>
        /// Title: Hack & Slash RPG - A Unity3D Game Engine Tutorial | BurgZerg Arcade. [Online].;
        /// Author: Laliberte P.
        /// Date: 2013 October 24.
        /// Available from: http://www.burgzergarcade.com/hack-slash-rpg-unity3d-game-engine-tutorial
        /// </summary>
        for (int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++)
        {
            storedIN._primaryAttribute[cnt]       = PlayerPrefs.GetString("Attribute Name - " + cnt);
            storedIN._primaryAttributeValues[cnt] = PlayerPrefs.GetInt(((AttributeName)cnt).ToString() + " - Base Value - " + cnt);
        }

        for (int cnt = 0; cnt < Enum.GetValues(typeof(VitalName)).Length; cnt++)
        {
            storedIN._vital[cnt]      = PlayerPrefs.GetString("Vital Name - " + cnt);
            storedIN._vitalValue[cnt] = PlayerPrefs.GetInt(((VitalName)cnt).ToString() + " - Base Value - " + cnt);
        }

        for (int cnt = 0; cnt < Enum.GetValues(typeof(AttackName)).Length; cnt++)
        {
            storedIN._attack[cnt]      = PlayerPrefs.GetString("Attack Name - " + cnt);
            storedIN._attackValue[cnt] = PlayerPrefs.GetInt(((AttackName)cnt).ToString() + " - Base Value - " + cnt);
        }

        for (int cnt = 0; cnt < Enum.GetValues(typeof(ManaName)).Length; cnt++)
        {
            storedIN._mana[cnt]      = PlayerPrefs.GetString("Mana Name - " + cnt);
            storedIN._manaValue[cnt] = PlayerPrefs.GetInt(((ManaName)cnt).ToString() + " - Base Value - " + cnt, 0);
        }

        for (int cnt = 0; cnt < Enum.GetValues(typeof(DefenceName)).Length; cnt++)
        {
            storedIN._defence[cnt]      = PlayerPrefs.GetString("Defence Name - " + cnt);
            storedIN._defenceValue[cnt] = PlayerPrefs.GetInt(((DefenceName)cnt).ToString() + " - Base Value - " + cnt);
        }
        #endregion
        string itemFromSave = string.Empty;
        int    itemCounting = 0;

        do
        {
            itemFromSave = PlayerPrefs.GetString("Items - " + itemCounting);

            string ItemPowerFromSave = PlayerPrefs.GetString("Items Power - " + itemCounting);
            if (itemFromSave != "")
            {
                storedIN.addItems(itemFromSave, ItemPowerFromSave);
            }
            itemCounting++;
        }while(itemFromSave != "");
    }