Esempio n. 1
0
        public static ISayDialog GetSayDialog()
        {
            if (activeSayDialog == null)
            {
                // Use first Say Dialog found in the scene (if any)
                SayDialog sd = GameObject.FindObjectOfType <SayDialog>();
                if (sd != null)
                {
                    activeSayDialog = sd;
                }

                if (activeSayDialog == null)
                {
                    // Auto spawn a say dialog object from the prefab
                    GameObject prefab = Resources.Load <GameObject>("Prefabs/SayDialog");
                    if (prefab != null)
                    {
                        GameObject go = Instantiate(prefab) as GameObject;
                        go.SetActive(false);
                        go.name         = "SayDialog";
                        activeSayDialog = go.GetComponent <ISayDialog>();
                    }
                }
            }

            return(activeSayDialog);
        }
Esempio n. 2
0
        public virtual void HideSayDialog()
        {
            ISayDialog sayDialog = SayDialog.GetSayDialog();

            if (sayDialog != null)
            {
                sayDialog.FadeWhenDone = true;
            }
        }
Esempio n. 3
0
        public override void OnStopExecuting()
        {
            ISayDialog sayDialog = SayDialog.GetSayDialog();

            if (sayDialog == null)
            {
                return;
            }

            sayDialog.Stop();
        }
Esempio n. 4
0
        public override void OnEnter()
        {
            if (!showAlways && executionCount >= showCount)
            {
                Continue();
                return;
            }

            executionCount++;

            // Override the active say dialog if needed
            if (character != null && character.SetSayDialog != null)
            {
                SayDialog.activeSayDialog = character.SetSayDialog;
            }

            if (setSayDialog != null)
            {
                SayDialog.activeSayDialog = setSayDialog;
            }

            ISayDialog sayDialog = SayDialog.GetSayDialog();

            if (sayDialog == null)
            {
                Continue();
                return;
            }

            var flowchart = GetFlowchart();

            sayDialog.SetActive(true);

            sayDialog.SetCharacter(character, flowchart);
            sayDialog.SetCharacterImage(portrait);

            string displayText = storyText;

            foreach (CustomTag ct in CustomTag.activeCustomTags)
            {
                displayText = displayText.Replace(ct.TagStartSymbol, ct.ReplaceTagStartWith);
                if (ct.TagEndSymbol != "" && ct.ReplaceTagEndWith != "")
                {
                    displayText = displayText.Replace(ct.TagEndSymbol, ct.ReplaceTagEndWith);
                }
            }

            string subbedText = flowchart.SubstituteVariables(displayText);

            sayDialog.Say(subbedText, !extendPrevious, waitForClick, fadeWhenDone, stopVoiceover, voiceOverClip, delegate {
                Continue();
            });
        }
Esempio n. 5
0
        protected ISayDialog GetSayDialog(Character character)
        {
            ISayDialog sayDialog = null;

            if (character != null)
            {
                if (character.SetSayDialog != null)
                {
                    sayDialog = character.SetSayDialog;
                }
            }

            if (sayDialog == null)
            {
                sayDialog = SayDialog.GetSayDialog();
            }

            return(sayDialog);
        }
Esempio n. 6
0
        public IEnumerator DoConversation(string conv)
        {
            if (string.IsNullOrEmpty(conv))
            {
                yield break;
            }

            var conversationItems = Parse(conv);

            if (conversationItems.Count == 0)
            {
                yield break;
            }

            // Track the current and previous parameter values
            Character     currentCharacter  = null;
            Sprite        currentPortrait   = null;
            RectTransform currentPosition   = null;
            Character     previousCharacter = null;

            // Play the conversation
            for (int i = 0; i < conversationItems.Count; ++i)
            {
                ConversationItem item = conversationItems[i];

                if (item.Character != null)
                {
                    currentCharacter = item.Character;
                }

                currentPortrait = item.Portrait;
                currentPosition = item.Position;

                ISayDialog sayDialog = GetSayDialog(currentCharacter);

                if (sayDialog == null)
                {
                    // Should never happen
                    yield break;
                }

                sayDialog.SetActive(true);

                if (currentCharacter != null &&
                    currentCharacter != previousCharacter)
                {
                    sayDialog.SetCharacter(currentCharacter);
                }

                var stage = Stage.GetActiveStage();

                if (stage != null && currentCharacter != null &&
                    (currentPortrait != currentCharacter.State.portrait ||
                     currentPosition != currentCharacter.State.position))
                {
                    var portraitOptions = new PortraitOptions(true);
                    portraitOptions.display      = item.Hide ? DisplayType.Hide : DisplayType.Show;
                    portraitOptions.character    = currentCharacter;
                    portraitOptions.fromPosition = currentCharacter.State.position;
                    portraitOptions.toPosition   = currentPosition;
                    portraitOptions.portrait     = currentPortrait;

                    //Flip option - Flip the opposite direction the character is currently facing
                    if (item.Flip)
                    {
                        portraitOptions.facing = item.FacingDirection;
                    }

                    // Do a move tween if the character is already on screen and not yet at the specified position
                    if (currentCharacter.State.onScreen &&
                        currentPosition != currentCharacter.State.position)
                    {
                        portraitOptions.move = true;
                    }

                    if (item.Hide)
                    {
                        stage.Hide(portraitOptions);
                    }
                    else
                    {
                        stage.Show(portraitOptions);
                    }
                }

                if (stage == null &&
                    currentPortrait != null)
                {
                    sayDialog.SetCharacterImage(currentPortrait);
                }

                previousCharacter = currentCharacter;

                if (!string.IsNullOrEmpty(item.Text))
                {
                    exitSayWait = false;
                    sayDialog.Say(item.Text, true, true, true, false, null, () => {
                        exitSayWait = true;
                    });

                    while (!exitSayWait)
                    {
                        yield return(null);
                    }
                    exitSayWait = false;
                }
            }
        }
Esempio n. 7
0
 public void SetSayDialog(ISayDialog sayDialog)
 {
     SayDialog.activeSayDialog = sayDialog;
 }