Beispiel #1
0
    void Start()
    {
        //scirpt references
        hInGameScriptCS = (InGameScriptCS)GameObject.Find("Player").GetComponent(typeof(InGameScriptCS));
        hNGUIHUDScript  = (NGUIHUDScript)this.transform.Find("Camera/Anchor/HUDGroup").GetComponent(typeof(NGUIHUDScript));

        //get the total number of menus used
        iMenuCount = System.Enum.GetValues(typeof(NGUIMenus)).Length;

        goHUDGroup = GameObject.Find("Camera/Anchor/HUDGroup");        //gameobject of the HUD Group

        //get the gameobjects of all menus used for later access
        goNGUIMenus = new GameObject[iMenuCount];
        goNGUIMenus[(int)NGUIMenus.MainMenu]         = GameObject.Find("Camera/Anchor/MainMenu");
        goNGUIMenus[(int)NGUIMenus.PauseMenu]        = GameObject.Find("Camera/Anchor/PauseMenu");
        goNGUIMenus[(int)NGUIMenus.GameOverMenu]     = GameObject.Find("Camera/Anchor/GameOverMenu");
        goNGUIMenus[(int)NGUIMenus.InstructionsMenu] = GameObject.Find("Camera/Anchor/InstructionsMenu");
        goNGUIMenus[(int)NGUIMenus.SettingsMenu]     = GameObject.Find("Camera/Anchor/SettingsMenu");
        goNGUIMenus[(int)NGUIMenus.MissionsMenu]     = GameObject.Find("Camera/Anchor/MissionsMenu");
        goNGUIMenus[(int)NGUIMenus.AchievementsMenu] = GameObject.Find("Camera/Anchor/AchievementsMenu");

        goNGUIMenus[(int)NGUIMenus.ShopHome]      = GameObject.Find("Camera/Anchor/Shop/ShopHome");
        goNGUIMenus[(int)NGUIMenus.ShopCostumes]  = GameObject.Find("Camera/Anchor/Shop/ShopCostumes");
        goNGUIMenus[(int)NGUIMenus.ShopIAPs]      = GameObject.Find("Camera/Anchor/Shop/ShopIAPs");
        goNGUIMenus[(int)NGUIMenus.ShopPowerups]  = GameObject.Find("Camera/Anchor/Shop/ShopPowerups");
        goNGUIMenus[(int)NGUIMenus.ShopUtilities] = GameObject.Find("Camera/Anchor/Shop/ShopUtilities");

        for (int i = 0; i < iMenuCount; i++)    //disable all menu groups when game starts
        {
            NGUITools.SetActive(goNGUIMenus[i], false);
        }

        uilAchievementsText = (UILabel)goNGUIMenus[(int)NGUIMenus.AchievementsMenu].transform.
                              Find("Text_Achievements").GetComponent(typeof(UILabel));
        uilPauseCounter = (UILabel)this.transform.Find("Camera/Anchor/Text_PauseCounter").GetComponent(typeof(UILabel));
        NGUITools.SetActive(uilPauseCounter.gameObject, false);

        uilMissionPauseMenuText   = (UILabel)goNGUIMenus[(int)NGUIMenus.PauseMenu].transform.Find("Text_Missions").GetComponent(typeof(UILabel));
        uilMissionMissionMenuText = (UILabel)goNGUIMenus[(int)NGUIMenus.MissionsMenu].transform.Find("Text_Missions").GetComponent(typeof(UILabel));

        ShowMenu(NGUIMenus.MainMenu); //display main menu when game starts
        toggleHUDGroupState(false);
    }                                 //end of Start function
Beispiel #2
0
    void Start()
    {
        iActiveMissionCount = 3;        //three missions active at a time by deafult
        missionsProgress    = new int[System.Enum.GetValues(typeof(MissionTypes)).Length];

        //set the next mission index
        if (PlayerPrefs.HasKey("NextMissionIndex"))
        {
            iNextMission = PlayerPrefs.GetInt("NextMissionIndex");
        }
        else
        {
            iNextMission = 0;
            PlayerPrefs.SetInt("NextMissionIndex", iNextMission);
        }

        hInGameScriptCS = (InGameScriptCS)this.GetComponent(typeof(InGameScriptCS));

        if (hInGameScriptCS.isCustomMenuEnabled())
        {
            hMenuScriptCS    = (MenuScriptCS)GameObject.Find("MenuGroup").GetComponent(typeof(MenuScriptCS));
            hHUDControllerCS = (HUDControllerCS)GameObject.Find("HUDMainGroup").GetComponent(typeof(HUDControllerCS));
        }
        else
        {
            hNGUIMenuScript = (NGUIMenuScript)GameObject.Find("UI Root (2D)").GetComponent(typeof(NGUIMenuScript));
            hNGUIHUDScript  = hNGUIMenuScript.getNGUIHUDScriptReference();
        }

        //get the MissionList file from the resources folder
        TextAsset taFile = (TextAsset)Resources.Load("MissionsList");

        string[] lines = taFile.text.Split('\n');

        if (lines.Length == 0)        //if the file was empty
        {
            Debug.Log("No missions found in file");
            this.enabled = false;
        }
        else        //read file and extract mission detail
        {
            int lineIndex  = 0;
            int arrayIndex = 0;
            iTotalMissionCount = lines.Length / 3;
            missions           = new MissionDetail[iTotalMissionCount];  //allocate memory according to the number of missions
            for (int i = 0; i < iTotalMissionCount; i++)
            {
                missions[i] = new MissionDetail();
            }

            while (lineIndex < lines.Length)            //store the file content in mission array
            {
                missions[arrayIndex].missionDescription = lines[lineIndex++];
                missions[arrayIndex].missionCount       = int.Parse(lines[lineIndex++]);
                missions[arrayIndex].missionType        = (MissionTypes)System.Enum.Parse(typeof(MissionTypes), lines[lineIndex++]);

                arrayIndex++;
            }            //end of while

            iActiveMissions = new int[iActiveMissionCount];
            for (int i = 0; i < iActiveMissionCount; i++)        //set the currently active missions
            {
                if (PlayerPrefs.HasKey("ActiveMission_" + i.ToString()))
                {
                    iActiveMissions[i] = PlayerPrefs.GetInt("ActiveMission_" + i.ToString());
                }
                else
                {
                    iActiveMissions[i] = getNextMission();
                    PlayerPrefs.SetInt("ActiveMission_" + i.ToString(), iActiveMissions[i]);
                }
            }            //end of for

            updateMenuDescriptions();
        }        //end of else

        PlayerPrefs.Save();
    }