Beispiel #1
0
        public void Say(string sayText, Action sayAction)
        {
            mode = Mode.Say;
            StringTable stringTable = Game.GetInstance().stringTable;
            string      subbedText  = stringTable.SubstituteStrings(sayText);

            continueAction = sayAction;
            WriteStory(subbedText);
        }
Beispiel #2
0
        /**
         * Handler method for animation events.
         * The string event parameter is used to call a named method on the active room class
         */
        void CallRoomMethod(string methodName)
        {
            Room room = Game.GetInstance().activeRoom;

            if (room == null)
            {
                return;
            }

            CommandQueue commandQueue = Game.GetInstance().commandQueue;

            commandQueue.CallCommandMethod(room.gameObject, methodName);
        }
Beispiel #3
0
        // Coroutine to write story text out over a period of time
        IEnumerator WriteStoryInternal()
        {
            int charactersPerSecond = Game.GetInstance().charactersPerSecond;

            // Zero CPS means write instantly
            if (charactersPerSecond == 0)
            {
                displayedStoryText = originalStoryText;
                yield break;
            }

            displayedStoryText = "";

            // Make one character visible at a time
            float writeDelay      = (1f / (float)charactersPerSecond);
            float timeAccumulator = 0f;
            int   i = 0;

            while (true)
            {
                timeAccumulator += Time.deltaTime;

                while (timeAccumulator > writeDelay)
                {
                    i++;
                    timeAccumulator -= writeDelay;
                }

                if (i >= originalStoryText.Length)
                {
                    displayedStoryText = originalStoryText;
                    break;
                }
                else
                {
                    string left  = originalStoryText.Substring(0, i + 1);
                    string right = originalStoryText.Substring(i + 1);

                    displayedStoryText  = left;
                    displayedStoryText += "<color=#FFFFFF00>";
                    displayedStoryText += right;
                    displayedStoryText += "</color>";
                }

                yield return(null);
            }
        }
Beispiel #4
0
        // Called by Game when player enters the room
        void Enter()
        {
            Game             game             = Game.GetInstance();
            CameraController cameraController = game.gameObject.GetComponent <CameraController>();

            // Pick first view found in the room and snap to camera to this view.
            // It is allowed for a room to not have any views.
            // In this case the camera will attempt to snap to the room sprite.
            View view = gameObject.GetComponentInChildren <View>();

            if (view == null)
            {
                // No view defined for this room, try to center on room sprite
                SpriteRenderer spriteRenderer = GetComponent <SpriteRenderer>();
                if (spriteRenderer != null)
                {
                    cameraController.CenterOnSprite(spriteRenderer);
                }
                else
                {
                    Debug.LogError("Failed to set camera view when entering room.");
                }
            }
            else
            {
                // Snap to new view
                cameraController.PanToPosition(view.transform.position, view.viewSize, 0, null);
            }

            // Hide all buttons in the room before entering
            // Buttons must always be made visible using a ShowButton() command
            Button[] buttons = game.activeRoom.GetComponentsInChildren <Button>();
            foreach (Button button in buttons)
            {
                button.SetAlpha(0f);
            }

            // Reset Page layout to default setting specified in Game object
            game.pageController.SetDefaultPageLayout();

            // Rooms may have multiple child views and page.
            // It is the responsibility of the client room script to set the desired active view & page in the OnEnter method.
            game.commandQueue.CallCommandMethod(game.activeRoom.gameObject, "OnEnter");

            visitCount++;
        }
Beispiel #5
0
        float CalcFooterHeight(float boxWidth)
        {
            PageStyle pageStyle = Game.GetInstance().activePageStyle;

            if (pageStyle == null ||
                mode == Mode.Idle ||
                footerText.Length == 0)
            {
                return(0);
            }

            GUIStyle footerStyle = pageStyle.GetScaledFooterStyle();

            GUIContent headerContent = new GUIContent(headerText);

            return(footerStyle.CalcHeight(headerContent, boxWidth));
        }
Beispiel #6
0
        float CalcStoryHeight(float boxWidth)
        {
            PageStyle pageStyle = Game.GetInstance().activePageStyle;
            GUIStyle  sayStyle  = pageStyle.GetScaledSayStyle();

            if (pageStyle == null ||
                mode == Mode.Idle ||
                originalStoryText.Length == 0)
            {
                // Allow a space for story even if there's no text
                return(sayStyle.lineHeight);
            }

            GUIContent storyContent = new GUIContent(originalStoryText + "\n");

            return(sayStyle.CalcHeight(storyContent, boxWidth));
        }
Beispiel #7
0
        // Returns smaller internal box rect with padding style applied
        Rect CalcInnerRect(Rect outerRect)
        {
            PageStyle pageStyle = Game.GetInstance().activePageStyle;

            if (pageStyle == null)
            {
                return(new Rect());
            }

            GUIStyle boxStyle = pageStyle.boxStyle;

            Rect innerRect = new Rect(outerRect.x + boxStyle.padding.left,
                                      outerRect.y + boxStyle.padding.top,
                                      outerRect.width - (boxStyle.padding.left + boxStyle.padding.right),
                                      outerRect.height - (boxStyle.padding.top + boxStyle.padding.bottom));

            return(innerRect);
        }
Beispiel #8
0
        void Update()
        {
            UpdateTargetAlpha();

            SpriteRenderer spriteRenderer = renderer as SpriteRenderer;
            float          fadeSpeed      = (1f / Game.GetInstance().buttonFadeDuration);

            float alpha = Mathf.MoveTowards(spriteRenderer.color.a, targetAlpha, Time.deltaTime * fadeSpeed);;

            // Set alpha for this sprite and any child sprites
            SpriteRenderer[] children = spriteRenderer.gameObject.GetComponentsInChildren <SpriteRenderer>();
            foreach (SpriteRenderer child in children)
            {
                Color color = child.color;
                color.a     = alpha;
                child.color = color;
            }
        }
Beispiel #9
0
        void OnMouseUpAsButton()
        {
            SpriteRenderer spriteRenderer = renderer as SpriteRenderer;

            // Ignore button press if sprite is not fully visible or
            // if the game is not in an idle state
            if (spriteRenderer.color.a != 1f ||
                !Game.GetInstance().GetShowAutoButtons())
            {
                return;
            }

            // Sound effect
            Game.GetInstance().PlayButtonClick();

            CommandQueue commandQueue = Game.GetInstance().commandQueue;

            commandQueue.CallCommandMethod(buttonAction);
        }
Beispiel #10
0
        void Update()
        {
            if (parentRoom == null)
            {
                // Don't apply offset if the sprite is not a child of a Room
                return;
            }

            if (Game.GetInstance().activeRoom != parentRoom)
            {
                // Early out if this sprite is not in the currently active Room
                return;
            }

            Vector3 offset = Game.GetInstance().GetParallaxOffset(parallaxScale);

            // Set new position for sprite
            transform.position = startPosition + offset;
        }
Beispiel #11
0
        /**
         * Reset to the default page layout based on properties in Game class.
         */
        public void SetDefaultPageLayout()
        {
            Game       game       = Game.GetInstance();
            ScreenRect screenRect = CalcScreenRect(game.defaultPageScale, game.defaultPagePosition);

            pageRect = CalcPageRect(screenRect);
            switch (game.defaultPagePosition)
            {
            case PageController.PagePosition.Top:
                game.pageController.layout = PageController.Layout.FullSize;
                break;

            case PageController.PagePosition.Middle:
                game.pageController.layout = PageController.Layout.FitToMiddle;
                break;

            case PageController.PagePosition.Bottom:
                game.pageController.layout = PageController.Layout.FullSize;
                break;
            }
        }
Beispiel #12
0
        IEnumerator FadeInternal(float targetAlpha, float fadeDuration, Action fadeAction)
        {
            float startAlpha = Game.GetInstance().fadeAlpha;
            float timer      = 0;

            while (timer < fadeDuration)
            {
                float t = timer / fadeDuration;
                timer += Time.deltaTime;

                t = Mathf.Clamp01(t);

                Game.GetInstance().fadeAlpha = Mathf.Lerp(startAlpha, targetAlpha, t);
                yield return(null);
            }

            Game.GetInstance().fadeAlpha = targetAlpha;

            if (fadeAction != null)
            {
                fadeAction();
            }
        }
Beispiel #13
0
        void UpdateTargetAlpha()
        {
            // Automatically display button when game is in idle state (not displaying story text/options or waiting)
            if (autoHide)
            {
                if (showButton &&
                    Game.GetInstance().GetShowAutoButtons())
                {
                    targetAlpha = 1f;
                }
                else
                {
                    targetAlpha = 0f;
                }
            }

            // Hide the button if the specified game value is non-zero
            if (hideOnSetValue.Length > 0 &&
                Game.GetInstance().GetGameValue(hideOnSetValue) != 0)
            {
                targetAlpha = 0f;
            }
        }
Beispiel #14
0
        /**
         * Plays game music using an audio clip.
         * One music clip may be played at a time.
         * @param audioClip The music clip to play
         */
        public static void PlayMusic(AudioClip audioClip)
        {
            CommandQueue commandQueue = Game.GetInstance().commandQueue;

            commandQueue.AddCommand(new Command.PlayMusic(audioClip));
        }
Beispiel #15
0
        /**
         * Stops playing game music.
         */
        public static void StopMusic()
        {
            CommandQueue commandQueue = Game.GetInstance().commandQueue;

            commandQueue.AddCommand(new Command.StopMusic());
        }
Beispiel #16
0
        /**
         * Hides the button sprite and makes it stop behaving as a clickable button.
         * This method returns immediately but it queues an asynchronous command for later execution.
         * @param spriteRenderer The sprite to be made non-clickable
         */
        public static void HideButton(Button button)
        {
            CommandQueue commandQueue = Game.GetInstance().commandQueue;

            commandQueue.AddCommand(new Command.ShowButton(button, false, null));
        }
Beispiel #17
0
        /**
         * Sets an animator trigger to change the animation state for an animated sprite.
         * This is the primary method of controlling Unity animations from a Fungus command sequence.
         * This method returns immediately but it queues an asynchronous command for later execution.
         * @param animator The sprite to be made non-clickable
         * @param triggerName Name of a trigger parameter in the animator controller
         */
        public static void SetAnimatorTrigger(Animator animator, string triggerName)
        {
            CommandQueue commandQueue = Game.GetInstance().commandQueue;

            commandQueue.AddCommand(new Command.SetAnimatorTrigger(animator, triggerName));
        }
Beispiel #18
0
        /**
         * Displays a button sprite object and sets the action callback method for the button.
         * If no Collider2D already exists on the object, then a BoxCollider2D is automatically added.
         * Use HideButton() to make the sprite invisible and non-clickable again.
         * This method returns immediately but it queues an asynchronous command for later execution.
         * @param button The button component of the sprite object to be shown.
         * @param buttonAction The Action delegate method to be called when the player clicks on the button
         */
        public static void ShowButton(Button button, Action buttonAction)
        {
            CommandQueue commandQueue = Game.GetInstance().commandQueue;

            commandQueue.AddCommand(new Command.ShowButton(button, true, buttonAction));
        }
Beispiel #19
0
        /**
         * Wait until player taps, clicks or presses a key before executing the next command.
         * This method returns immediately but it queues an asynchronous command for later execution.
         */
        public static void WaitForInput()
        {
            CommandQueue commandQueue = Game.GetInstance().commandQueue;

            commandQueue.AddCommand(new Command.WaitForInput());
        }
Beispiel #20
0
        /**
         * Wait for a period of time before executing the next command.
         * This method returns immediately but it queues an asynchronous command for later execution.
         * @param duration The wait duration in seconds
         */
        public static void Wait(float duration)
        {
            CommandQueue commandQueue = Game.GetInstance().commandQueue;

            commandQueue.AddCommand(new Command.Wait(duration));
        }
Beispiel #21
0
 /**
  * Gets a globally accessible string value.
  * @param key The name of the value
  * @return The string value for this key, or the empty string if not previously set.
  */
 public static string GetString(string key)
 {
     return(Game.GetInstance().stringTable.GetString(key));
 }
Beispiel #22
0
        /**
         * Writes story text to the page.
         * A 'continue' button is displayed when the text has fully appeared.
         * Command execution halts until the user chooses to continue.
         * This method returns immediately but it queues an asynchronous command for later execution.
         * @param storyText The text to be written to the page.
         */
        public static void Say(string storyText)
        {
            CommandQueue commandQueue = Game.GetInstance().commandQueue;

            commandQueue.AddCommand(new Command.Say(storyText));
        }
Beispiel #23
0
        /**
         * Call a delegate method provided by the client.
         * Used to queue the execution of arbitrary code as part of a command sequeunce.
         * This method returns immediately but it queues an asynchronous command for later execution.
         * @param callAction The Action delegate method to be called when the command executes.
         */
        public static void Call(Action callAction)
        {
            CommandQueue commandQueue = Game.GetInstance().commandQueue;

            commandQueue.AddCommand(new Command.Call(callAction));
        }
Beispiel #24
0
        /**
         * Fades the game music volume to required level over a period of time.
         * @param musicVolume The new music volume value [0..1]
         * @param duration The length of time in seconds needed to complete the volume change.
         */
        public static void SetMusicVolume(float musicVolume, float duration)
        {
            CommandQueue commandQueue = Game.GetInstance().commandQueue;

            commandQueue.AddCommand(new Command.SetMusicVolume(musicVolume, duration));
        }
Beispiel #25
0
        /**
         * Adds an option with no action to the current list of player options.
         * This method returns immediately but it queues an asynchronous command for later execution.
         * @param optionText The text to be displayed for this option
         * @param optionAction The Action delegate method to be called when the player selects the option
         */
        public static void AddOption(string optionText)
        {
            CommandQueue commandQueue = Game.GetInstance().commandQueue;

            commandQueue.AddCommand(new Command.AddOption(optionText, delegate {}));
        }
Beispiel #26
0
        /**
         * Adds an option to the current list of player options.
         * Use the Choose() method to display previously added options.
         * This method returns immediately but it queues an asynchronous command for later execution.
         * @param optionText The text to be displayed for this option
         * @param optionAction The Action delegate method to be called when the player selects the option
         */
        public static void AddOption(string optionText, Action optionAction)
        {
            CommandQueue commandQueue = Game.GetInstance().commandQueue;

            commandQueue.AddCommand(new Command.AddOption(optionText, optionAction));
        }
Beispiel #27
0
        /**
         * Plays a sound effect once, at the specified volume.
         * Multiple sound effects can be played at the same time.
         * @param audioClip The sound effect clip to play
         * @param volume The volume level of the sound effect
         */
        public static void PlaySound(AudioClip audioClip, float volume)
        {
            CommandQueue commandQueue = Game.GetInstance().commandQueue;

            commandQueue.AddCommand(new Command.PlaySound(audioClip, volume));
        }
Beispiel #28
0
 /**
  * Gets a globally accessible integer value.
  * Returns zero if the value has not previously been set.
  * @param key The name of the value
  * @return The integer value for this key, or 0 if not previously set.
  */
 public static int GetValue(string key)
 {
     return(Game.GetInstance().GetGameValue(key));
 }
Beispiel #29
0
        /**
         * Displays a story text prompt, followed by all previously added options.
         * This method returns immediately but it queues an asynchronous command for later execution.
         * @param chooseText The story text to be written above the list of options
         */
        public static void Choose(string chooseText)
        {
            CommandQueue commandQueue = Game.GetInstance().commandQueue;

            commandQueue.AddCommand(new Command.Choose(chooseText));
        }
Beispiel #30
0
        /**
         * Sets a globally accessible string value.
         * This method returns immediately but it queues an asynchronous command for later execution.
         * @param key The name of the value to set
         * @param value The string value to set
         */
        public static void SetString(string key, string value)
        {
            CommandQueue commandQueue = Game.GetInstance().commandQueue;

            commandQueue.AddCommand(new Command.SetString(key, value));
        }