Example #1
0
        // Update is called once per frame
        void Update()
        {
            if (Time.timeSinceLevelLoad - lastClockUpdate > 0.5f)
            {
                UpdateTime();
                lastClockUpdate = Time.timeSinceLevelLoad;
            }

            // Hide help after duration
            if ((Time.timeSinceLevelLoad - showHelpTime) > showHelpDuration &&
                !TWGameManager.instance.IsPaused)
            {
                helpMenu.SetActive(false);
                helpHint.SetActive(false);
            }

            // Truncate level text after duration
            if ((Time.timeSinceLevelLoad - levelLoadTime) > fullLevelTextDuration)
            {
                TruncateLevelText();
            }

            // Invoke any commands from the user
            commands.ForEach(delegate(UIMenuCommand c)
            {
                UIMenuCommand command = c;
                if (Input.GetKeyDown(command.keyCode))
                {
                    Debug.Log("Command: " + command.keyCode.ToString() + ", " + command.description);
                    command.commandCallback();
                }
            });
        }
Example #2
0
        void Awake()
        {
            locationText  = GameObject.Find("Location").GetComponent <Text>();
            dateText      = GameObject.Find("Date").GetComponent <Text>();
            timeText      = GameObject.Find("Time").GetComponent <Text>();
            helpHint      = GameObject.Find("HelpHint");
            helpHintText  = helpHint.GetComponent <Text>();
            helpMenu      = GameObject.Find("Menu");
            slider        = GameObject.Find("Slider");
            track         = GameObject.Find("Track");
            handle        = GameObject.Find("Handle");
            fullLevelText = GameObject.Find("FullLevelText").GetComponent <Text>();

            // Add commands
            commands = new List <UIMenuCommand> {
                new UIMenuCommand(KeyCode.Y, "Change Year", ChangeYear),
                new UIMenuCommand(KeyCode.N, "Night/Day", ToggleNightDay),
                new UIMenuCommand(KeyCode.B, "Black & White", ToggleColor),
                new UIMenuCommand(KeyCode.C, "See Comments", ToggleComments),
                new UIMenuCommand(KeyCode.H, "Help", ToggleHelp),
                new UIMenuCommand(KeyCode.R, "Restart", Restart),
                new UIMenuCommand(KeyCode.Q, "Quit", Quit)
            };

            commands.ForEach(delegate(UIMenuCommand c)
            {
                UIMenuCommand command = c;

                // Create menu item
                Button item = Instantiate(commandMenuItemTextPrefab, helpMenu.transform).GetComponent <Button>();

                item.GetComponent <Text>().text = command.description + " (" + command.keyCode.ToString() + ")";

                // TODO Add support for menu clicks and/or menu modal (see menu example in SampleScenes)
                //item.onClick.AddListener(delegate {
                //    UIMenuCommand thisCommand = command;
                //    Debug.Log("Command: " + thisCommand.keyCode.ToString() + ", " + thisCommand.description);
                //    thisCommand.commandCallback();
                //});
            });

            // TODO Snap slider to levels
            // Disable slider for now
            slider.GetComponent <Slider>().enabled = false;
        }