Beispiel #1
0
 private void Update()
 {
     if (!isPaused)
     {
         dayTimer += Time.deltaTime * timeMultiplier;
         if (dayTimer >= HALF_DAY_IN_SECONDS && isAM)
         {
             isAM = false;
         }
         if (dayTimer >= FULL_DAY_IN_SECONDS && !isAM)
         {
             hasDayEnded   = false;
             hasDayStarted = false;
             isAM          = true;
             dayTimer      = 0.0f;
             ++elapsedDays;
         }
     }
     timeInHours = AdrienUtils.ConvertToTime(dayTimer);
     if (timeToAdd > 0.0f)
     {
         timeToAddInHours = AdrienUtils.ConvertToTime(timeToAdd);
         timeToAdd       -= Time.deltaTime * 7200.0f;
         dayTimer        += Time.deltaTime * 7200.0f;
     }
     if (timeToAdd < 0.0f)
     {
         timeToAdd = 0.0f;
     }
     if (timeToAdd == 0.0f && isPaused)
     {
         isPaused = false;
     }
 }
    private void OnGUI()
    {
        if (!displaySaveUI)
        {
            return;
        }

        if (isMainMenu)
        {
            GUI.Box(new Rect(150.0f, 150.0f, 430.0f, 225.0f), "");
            for (int i = 0; i < 3; ++i)
            {
                string addString = "";
                if (i == 0)
                {
                    addString = (bool)(BinarySerialization.LoadFromPlayerPrefs(SavingKeysContainer.SAVE1_ID)) ? "(Taken)" : "(Empty)";
                }
                else if (i == 1)
                {
                    addString = (bool)(BinarySerialization.LoadFromPlayerPrefs(SavingKeysContainer.SAVE2_ID)) ? "(Taken)" : "(Empty)";
                }
                else if (i == 2)
                {
                    addString = (bool)(BinarySerialization.LoadFromPlayerPrefs(SavingKeysContainer.SAVE3_ID)) ? "(Taken)" : "(Empty)";
                }

                GUI.Box(new Rect(165.0f, 165.0f + i * 70.0f, 270.0f, 55.0f), "Save " + (i + 1).ToString() + addString);
                if (addString.StartsWith("(Taken)"))
                {
                    if (BinarySerialization.LoadFromPlayerPrefs((i + 1).ToString() + "_" + SavingKeysContainer.TIME_ELAPSED) != null)
                    {
                        int[] timeValue = AdrienUtils.ConvertToTime((float)BinarySerialization.LoadFromPlayerPrefs((i + 1).ToString() + "_" + SavingKeysContainer.TIME_ELAPSED));
                        GUI.Label(new Rect(195.0f, 195.0f + i * 70.0f, 270.0f, 55.0f), timeValue[0].ToString() + "h:" + timeValue[1].ToString() + "m:" + timeValue[2].ToString() + "s");
                        MySerializables.GameTime gameTime = ((MySerializables.GameTime)BinarySerialization.LoadFromPlayerPrefs((i + 1).ToString() + "_" + SavingKeysContainer.GAME_TIME_DATA));

                        GUI.Label(new Rect(285.0f, 195.0f + i * 70.0f, 270.0f, 55.0f), "Day " + gameTime.dayCount + ", " + gameTime.currentDayOfTheWeek + " " + gameTime.currentDayState);
                    }

                    if (GUI.Button(new Rect(450.0f, 165.0f + i * 70.0f, 50.0f, 55.0f), "LOAD"))
                    {
                        loadNewGame = (i + 1);
                        Invoke("StartLoadedGame", 0.05f);
                        displaySaveUI = false;
                        isMainMenu    = false;
                        Application.LoadLevel("Scene03_Map01_Peninsula");
                    }
                    if (GUI.Button(new Rect(515.0f, 165.0f + i * 70.0f, 50.0f, 55.0f), "DEL"))
                    {
                        string id = (i + 1).ToString() + "_";
                        SavingKeysContainer.DeleteSave(id);
                    }
                }
                else
                {
                    if (GUI.Button(new Rect(450.0f, 165.0f + i * 70.0f, 115.0f, 55.0f), "NEW"))
                    {
                        loadNewGame   = (i + 1);
                        displaySaveUI = false;
                        isMainMenu    = false;
                        Application.LoadLevel("Scene03_Map01_Peninsula");
                    }
                }
            }
        }
        else
        {
            GUI.Box(new Rect(150.0f, 150.0f, 430.0f, 250.0f), "");
            GUI.Box(new Rect(165.0f, 165.0f, 300.0f, 70.0f), "Save " + loadNewGame.ToString() + ": Current");
            if (GUI.Button(new Rect(482.5f, 165.0f, 80.0f, 70.0f), "OVERRIDE"))
            {
                SavingKeysContainer.SaveEvent(loadNewGame.ToString() + "_");
                displaySaveUI = false;
            }

            if (GUI.Button(new Rect(165.0f, 250.0f, 400.0f, 35.0f), "SAVE AND QUIT"))
            {
                SavingKeysContainer.SaveEvent(loadNewGame.ToString() + "_");
                isMainMenu = true;
                Application.LoadLevel("Scene02_LoadGame");
            }
        }
    }
Beispiel #3
0
    private void OnGUI()
    {
        if (isAM)
        {
            GUI.Box(new Rect(35.0f, 35.0f, 165.0f, 25.0f), "Day " + elapsedDays.ToString() + " -- " + timeInHours[0].ToString() + "h:" + timeInHours[1].ToString() + "m:" + timeInHours[2].ToString() + "s" + (isAM ? " AM" : " PM"));
        }
        else
        {
            GUI.Box(new Rect(35.0f, 35.0f, 165.0f, 25.0f), "Day " + elapsedDays.ToString() + " -- " + (timeInHours[0] - 12).ToString() + "h:" + timeInHours[1].ToString() + "m:" + timeInHours[2].ToString() + "s" + (isAM ? " AM" : " PM"));
        }

        GUI.Box(new Rect(220.0f, 35.0f, 100.0f, 25.0f), currentDayOfTheWeek + " " + currentDayState);

        if (isRestActive)
        {
            GUI.Box(new Rect(35.0f, 75.0f, 285.0f, 500.0f), "END OF DAY");

            float timeToRest = 0.0f;
            if (FULL_DAY_IN_SECONDS - dayTimer < FULL_DAY_IN_SECONDS - endOfDay)
            {
                timeToRest = FULL_DAY_IN_SECONDS - dayTimer + startOfDay;
            }
            else
            {
                timeToRest = startOfDay - dayTimer;
            }

            int[] timeToRestInTime = AdrienUtils.ConvertToTime(timeToRest);

            if (GUI.Button(new Rect(57.5f, 100.0f, 240.0f, 60.0f), "Rest" + "\n" + "\n" + "(" + timeToRestInTime[0] + "h:" + timeToRestInTime[1] + "m" + ")"))
            {
                isRestActive = false;
                TimeLeap(timeToRest);
            }

            GUI.Label(new Rect(150.0f, 175.0f, 100.0f, 25.0f), "Activities");

            for (int i = 0; i < activitiesList.Count; ++i)
            {
                // CHECK FOR ACTIVITY AVAILABILITY

                if (activitiesList[i].availabilityStart < HALF_DAY_IN_SECONDS)
                {
                    if (activitiesList[i].availabilityStart > dayTimer || activitiesList[i].AvailabilityEnd < dayTimer)
                    {
                        GUI.color = Color.gray;
                        activitiesList[i].isAvailable = false;
                    }
                }
                else if (activitiesList[i].availabilityStart > HALF_DAY_IN_SECONDS)
                {
                    if (dayTimer > HALF_DAY_IN_SECONDS)
                    {
                        if (activitiesList[i].availabilityStart > dayTimer)
                        {
                            GUI.color = Color.gray;
                            activitiesList[i].isAvailable = false;
                        }
                        if (activitiesList[i].AvailabilityEnd > HALF_DAY_IN_SECONDS)
                        {
                            if (activitiesList[i].AvailabilityEnd < dayTimer)
                            {
                                GUI.color = Color.gray;
                                activitiesList[i].isAvailable = false;
                            }
                        }
                    }
                    else
                    {
                        if (activitiesList[i].AvailabilityEnd > HALF_DAY_IN_SECONDS)
                        {
                            GUI.color = Color.gray;
                            activitiesList[i].isAvailable = false;
                        }
                        else if (activitiesList[i].AvailabilityEnd < HALF_DAY_IN_SECONDS)
                        {
                            if (activitiesList[i].AvailabilityEnd < dayTimer)
                            {
                                GUI.color = Color.gray;
                                activitiesList[i].isAvailable = false;
                            }
                        }
                    }
                }

                int[] durationInTime = AdrienUtils.ConvertToTime(activitiesList[i].duration);
                int[] startInTime    = AdrienUtils.ConvertToTime(activitiesList[i].availabilityStart);
                int[] endInTime      = AdrienUtils.ConvertToTime(activitiesList[i].AvailabilityEnd);

                string startAmPm = "AM";
                if (startInTime[0] > AdrienUtils.ConvertToTime(startOfDay)[0] + 1)
                {
                    startAmPm       = "PM";
                    startInTime[0] -= 12;
                }
                string endAmPm = "AM";
                if (endInTime[0] > AdrienUtils.ConvertToTime(startOfDay)[0] + 1)
                {
                    endAmPm       = "PM";
                    endInTime[0] -= 12;
                }

                if (GUI.Button(new Rect(75.0f, 220.0f + (i * 75.0f), 200.0f, 55.0f), activitiesList[i].name + "\n" + "(" + durationInTime[0] + "h:" + durationInTime[1] + "m" + ")"
                               + "\n" + startInTime[0] + startAmPm + "  ~  " + endInTime[0] + endAmPm))
                {
                    if (activitiesList[i].isAvailable)
                    {
                        TimeLeap(activitiesList[i].duration);
                    }
                }

                GUI.color = Color.white;
                activitiesList[i].isAvailable = true;
            }
        }

        if (timeToAdd > 0.0f)
        {
            int[] timeToAddInHours = AdrienUtils.ConvertToTime(timeToAdd);
            GUI.Label(new Rect(55.0f, 15.0f, 100.0f, 25.0f), timeToAddInHours[0].ToString() + "h:" + timeToAddInHours[1].ToString() + "m:" + timeToAddInHours[2].ToString() + "s");
        }
    }