Beispiel #1
0
    private bool _switchLights;                        // Activator for the lights switcher
    #endregion

    // Use this for initialization
    void Awake()
    {
        #region set initialization  variables
        // Find our time control
        GameObject Tc = GameObject.FindGameObjectWithTag("Time");

        // If Day night control no exist
        if (Tc == null)
        {
            // Set Light Component true
            GetComponent <Light>().enabled = true;
            // Turns Off the lights switcher
            _switchLights = false;
            // Set initial light switch state
            _light = true;
            // Send an advice
            Debug.Log("Day/Night control is not present");
        }

        else
        {
            // Set Light Component
            GetComponent <Light>().enabled = false;
            // Set reference for the DayTame script
            _DayNightControl = Tc.GetComponent <DayNightControl>();
            // Turns On the lights switcher
            _switchLights = true;
            // Set initial light switch state
            _light = !_DayNightControl._IsDay;
        }
        #endregion
    }
    public static IEnumerator StartAction(string nameOfAction, string playerName, string itemName, string timer)
    {
        yield return(PlayerClass.CheckConn());

        if (PlayerClass.conOk)
        {
            WWWForm form = new WWWForm();
            form.AddField("playername", playerName);
            form.AddField("itemname", itemName);
            UnityWebRequest www = UnityWebRequest.Post(URLs.Link("UpgradeItem"), form);
            yield return(www.SendWebRequest());

            Debug.Log(www.downloadHandler.text);
            string[] answer = www.downloadHandler.text.Split('^');
            if (!www.isNetworkError)
            {
                for (int i = 0; i < answer.Length; i++)
                {
                    if (answer[i] == "Upgrade payed")
                    {
                        if (UpgradeTimer == null)
                        {
                            UpgradeTimer = GameObject.CreatePrimitive(PrimitiveType.Cube);
                        }
                        UpgradeTimer.name = string.Format("{0}Timer", nameOfAction);
                        UpgradeTimer.AddComponent <TimerWithSpan>();
                        UpgradeTimer.GetComponent <TimerWithSpan>().zavTime = new int[]
                        {
                            int.Parse(timer.Substring(0, 2)),
                            int.Parse(timer.Substring(5, 2)),
                            int.Parse(timer.Substring(10, 2))
                        };
                        UpgradeTimer.GetComponent <TimerWithSpan>().targTime = new int[] { 00, 00, 00 };
                        UpgradeTimer.GetComponent <TimerWithSpan>().Reset    = false;
                        UpgradeTimer.GetComponent <TimerWithSpan>().zvon.AddListener(() =>
                        {
                            FinishUpgrade.Invoke();
                        });
                        UpgradeTimer.GetComponent <TimerWithSpan>().runTimer = true;

                        yield return(DayNightControl.GetTime());

                        PlayerPrefs.SetString("SelectedItemToUpgrade", itemName);
                        PlayerPrefs.SetString("IsUpgradingTimerDate",
                                              "true" +
                                              string.Format("{0:00}{1:00}{2:00}",
                                                            int.Parse(timer.Substring(0, 2)),
                                                            int.Parse(timer.Substring(5, 2)),
                                                            int.Parse(timer.Substring(10, 2))) +
                                              string.Format("{0,4}{1:00}{2:00}{3:00}{4:00}{5:00}",
                                                            DayNightControl.timY,
                                                            DayNightControl.timMo,
                                                            DayNightControl.timD,
                                                            DayNightControl.timH,
                                                            DayNightControl.timMi,
                                                            DayNightControl.timS));
                        PlayerPrefs.Save();
                    }
                }
                yield return(PlayerClass.GetPlayerData("Items"));
            }
        }
        else
        {
            GameStateManager.Message(Localize.LocalizeMessage("ConnectionError"));
            yield return(GameStateManager.ClearMessage());
        }
    }