Exemple #1
0
    public override void OnBehaviourPlay(Playable playable, FrameData info)
    {
        if (!m_TrackBinding)
        {
            return;
        }

        if (!m_FirstFrameHappened)
        {
            //on the firs frame, set the defaults to recover after
            m_txtToParse      = m_TrackBinding.txtToParse;
            m_lineToBreak     = m_TrackBinding.lineToBreak;
            m_lineToStart     = m_TrackBinding.lineToStart;
            m_textSpeed       = m_TrackBinding.textSpeed;
            m_enableQuickSkip = m_TrackBinding.enableQuickSkip;
            m_enablePass      = m_TrackBinding.enablePass;

            //change the rpgTalk parameters
            if (txtToParse != null)
            {
                m_TrackBinding.txtToParse = txtToParse;
            }

            //If we won't wait for player action to finish, only one line (line to start) will be allowed.
            if (!pauseUntilTalkEnd)
            {
                m_TrackBinding.lineToBreak = lineToStart;
                m_TrackBinding.enablePass  = false;
            }
            else
            {
                m_TrackBinding.enablePass  = true;
                m_TrackBinding.lineToBreak = lineToBreak;
            }
            m_TrackBinding.lineToStart     = lineToStart;
            m_TrackBinding.textSpeed       = textSpeed;
            m_TrackBinding.enableQuickSkip = false;

            m_FirstFrameHappened = true;
            m_TrackBinding.NewTalk();

            //Put an event for the end of the talk
            m_TrackBinding.OnEndTalk += OnEndTalk;

            if (m_TrackBinding.GetComponent <RPGTalkTimeline> ())
            {
                rpgTime = m_TrackBinding.GetComponent <RPGTalkTimeline> ();
            }
        }
    }
Exemple #2
0
    /// <summary>
    /// Check the rules and put it into rpgtalkTarget, initializing a new talk.
    /// </summary>
    protected virtual void NewTalk()
    {
        if (rpgtalkTarget == null || (happenOnlyOnce && alreadyHappened) || (forbidPlayIfRpgtalkIsPlaying && rpgtalkTarget.isPlaying))
        {
            return;
        }

        alreadyHappened = true;
        if (saveAlreadyHappened)
        {
            if (rpgtalkTarget.saveInstance)
            {
                rpgtalkTarget.saveInstance.SaveData(name, 1);
            }
        }


        callbackBeforeTalk.Invoke();
        TextAsset newTxt = rpgtalkTarget.txtToParse;

        if (txtToParse != null)
        {
            newTxt = txtToParse;
        }

        rpgtalkTarget.shouldStayOnScreen = shouldStayOnScreen;
        rpgtalkTarget.autoPass           = autoPass;
        rpgtalkTarget.secondsAutoPass    = secondsAutoPass;

        RPGTalkFollowCharacter followCharacter = rpgtalkTarget.GetComponent <RPGTalkFollowCharacter>();

        if (followCharacter)
        {
            followCharacter.containInsideScreen = containInsideScreen;
        }

        rpgtalkTarget.NewTalk(lineToStart, lineToBreak, newTxt, overwriteCallbackAfterTalk);
    }
Exemple #3
0
    override public void OnInspectorGUI()
    {
        serializedObject.Update();

        //Instance of our RPGTalk class
        RPGTalk rpgTalk = (RPGTalk)target;

        EditorGUI.BeginChangeCheck();

        EditorGUILayout.LabelField("Put below the Text file to be parsed and become the talks!");
        EditorGUILayout.PropertyField(serializedObject.FindProperty("txtToParse"), GUIContent.none);
        if (serializedObject.FindProperty("txtToParse").objectReferenceValue == null)
        {
            EditorGUILayout.HelpBox("RPGTalk needs a TXT file to retrieve the lines from", MessageType.Error, true);
        }

        EditorGUILayout.Space();
        EditorGUILayout.LabelField("What line of the text should the Talk start? And in what line shoult it end?");
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PropertyField(serializedObject.FindProperty("lineToStart"), GUIContent.none);
        EditorGUILayout.PropertyField(serializedObject.FindProperty("lineToBreak"), GUIContent.none);
        EditorGUILayout.EndHorizontal();
        string lineToStart       = serializedObject.FindProperty("lineToStart").stringValue;
        int    actualLinaToStart = -2;

        if (int.TryParse(lineToStart, out actualLinaToStart) && actualLinaToStart < 1)
        {
            EditorGUILayout.HelpBox("The line that the Text should start must be 1 or greater!", MessageType.Error, true);
        }
        string lineToBreak       = serializedObject.FindProperty("lineToBreak").stringValue;
        int    actualLinaToBreak = -2;

        if (int.TryParse(lineToBreak, out actualLinaToBreak) && actualLinaToBreak != -1 &&
            actualLinaToBreak < actualLinaToStart)
        {
            EditorGUILayout.HelpBox("The line of the Text to stop the Talk comes before the line of the Text to start the Talk? " +
                                    "That makes no sense! If you want to read the Text file until the end, leave the line to break as '-1'", MessageType.Error, true);
        }
        EditorGUILayout.HelpBox("The line to start or to end might be set as strings! For instance, you can set lineToStart as 'MyString' and in your text, RPGTalk will start reading the line just after the tag [title=MyString].", MessageType.Info, true);


        EditorGUILayout.PropertyField(serializedObject.FindProperty("showWithDialog"), true);
        if (serializedObject.FindProperty("showWithDialog").arraySize == 0)
        {
            EditorGUILayout.HelpBox("Not a single element to be shown with the Talk? Not even the Canvas?" +
                                    "Are you sure that is the correct bahaviour?", MessageType.Warning, true);
        }

        EditorGUILayout.BeginVertical((GUIStyle)"HelpBox");

        EditorGUILayout.LabelField("Regular Options:", EditorStyles.boldLabel);
        rpgTalk.startOnAwake       = GUILayout.Toggle(rpgTalk.startOnAwake, "Start On Awake?");
        rpgTalk.dialoger           = GUILayout.Toggle(rpgTalk.dialoger, "Should try to read the name of the talker?");
        rpgTalk.shouldUsePhotos    = GUILayout.Toggle(rpgTalk.shouldUsePhotos, "Should there be the photo of the talker?");
        rpgTalk.shouldStayOnScreen = GUILayout.Toggle(rpgTalk.shouldStayOnScreen, "Should the canvas stay on screen after the talk ended?");


        rpgTalk.enableQuickSkip = GUILayout.Toggle(rpgTalk.enableQuickSkip, "Enable QuickStep (the player can jump the animation)?");
        EditorGUILayout.PropertyField(serializedObject.FindProperty("textSpeed"));

        rpgTalk.passWithMouse = GUILayout.Toggle(rpgTalk.passWithMouse, "Pass the Talk with Mouse Click?");
        EditorGUILayout.LabelField("The Talk can also be passed with some button set on Project Settings > Input:");
        EditorGUILayout.PropertyField(serializedObject.FindProperty("passWithInputButton"), GUIContent.none);
        EditorGUILayout.LabelField("The Talk can also be passed with some key:");
        rpgTalk.passWithKey = (KeyCode)EditorGUILayout.EnumPopup(rpgTalk.passWithKey);
        rpgTalk.autoPass    = GUILayout.Toggle(rpgTalk.autoPass, "Automatically Pass the Talk?");
        if (rpgTalk.autoPass)
        {
            EditorGUILayout.PropertyField(serializedObject.FindProperty("secondsAutoPass"));
        }
        if (!rpgTalk.passWithMouse && serializedObject.FindProperty("passWithInputButton").stringValue == "" && !rpgTalk.autoPass)
        {
            EditorGUILayout.HelpBox("There is no condition to pass the Talk. Is it really the expected behaviour?", MessageType.Warning, true);
        }

        EditorGUILayout.Space();
        EditorGUILayout.LabelField("RPGTalk can try to make a Word Wrap for long texts in the same line.");
        rpgTalk.wordWrap = GUILayout.Toggle(rpgTalk.wordWrap, "Word Wrap?");
        if (rpgTalk.wordWrap)
        {
            EditorGUILayout.LabelField("Set manually the maximum chars in Width/Height that fit in the screen:");
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(serializedObject.FindProperty("maxCharInWidth"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("maxCharInHeight"));
            EditorGUI.indentLevel--;
        }
        EditorGUILayout.LabelField("If lines to start and break were changed during the talk:");
        rpgTalk.goBackToOriginalStartAndBreak = GUILayout.Toggle(rpgTalk.goBackToOriginalStartAndBreak, "They should be changed back when it finish");

        EditorGUILayout.EndVertical();


        if (rpgTalk.dialoger)
        {
            //create a nice box with round edges.
            EditorGUILayout.BeginVertical((GUIStyle)"HelpBox");

            EditorGUILayout.LabelField("Characters Settings:", EditorStyles.boldLabel);

            rpgTalk.shouldFollow = GUILayout.Toggle(rpgTalk.shouldFollow, "Should the canvas follow someone?");
            if (rpgTalk.shouldFollow && !rpgTalk.GetComponent <RPGTALK.Snippets.RPGTalkFollowCharacter>())
            {
                EditorGUILayout.HelpBox("There should be a RPGtalkFollowCharacter Snippet on this object to make the follow work the way it should", MessageType.Error, true);

                /*EditorGUI.indentLevel++;
                *  EditorGUILayout.LabelField("The object that follows should be Billboard? Based on which camera?");
                *  EditorGUILayout.BeginHorizontal();
                *  rpgTalk.billboard = GUILayout.Toggle(rpgTalk.billboard, "Billboard?");
                *  if (rpgTalk.billboard)
                *  {
                *   rpgTalk.mainCamera = GUILayout.Toggle(rpgTalk.mainCamera, "Based on Main Camera?");
                *  }
                *  EditorGUILayout.EndHorizontal();
                *  if (rpgTalk.billboard && !rpgTalk.mainCamera)
                *  {
                *   EditorGUILayout.LabelField("What camera should the Billboard be based on?");
                *   EditorGUILayout.PropertyField(serializedObject.FindProperty("otherCamera"), GUIContent.none);
                *  }
                *  EditorGUI.indentLevel--;*/
            }


            EditorGUILayout.LabelField("Who are the characters that may appear on that conversation?");
            EditorGUI.indentLevel++;
            if (!hideCharacters)
            {
                if (rpgTalk.characters != null)
                {
                    for (int i = 0; i < rpgTalk.characters.Length; i++)
                    {
                        EditorGUILayout.LabelField("Who is this character?");
                        EditorGUILayout.BeginHorizontal();
                        rpgTalk.characters[i].character = (RPGTalkCharacter)EditorGUILayout.ObjectField(rpgTalk.characters[i].character, typeof(RPGTalkCharacter), false);
                        if (GUILayout.Button(" - "))
                        {
                            serializedObject.FindProperty("characters").DeleteArrayElementAtIndex(i);
                        }
                        EditorGUILayout.EndHorizontal();
                        EditorGUI.indentLevel += 2;
                        EditorGUILayout.LabelField("Should an different Animator be set for it?");
                        rpgTalk.characters[i].animatorOverwrite = (Animator)EditorGUILayout.ObjectField(rpgTalk.characters[i].animatorOverwrite, typeof(Animator), true);
                        if (rpgTalk.shouldFollow)
                        {
                            EditorGUILayout.LabelField("What Transform should the canvas follow? Should there be an offset?");
                            EditorGUILayout.BeginHorizontal();
                            rpgTalk.characters[i].follow       = (Transform)EditorGUILayout.ObjectField(rpgTalk.characters[i].follow, typeof(Transform), true);
                            rpgTalk.characters[i].followOffset = EditorGUILayout.Vector3Field(GUIContent.none, rpgTalk.characters[i].followOffset);
                            EditorGUILayout.EndHorizontal();
                        }
                        EditorGUI.indentLevel -= 2;
                        EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
                    }
                }
            }
            EditorGUILayout.BeginHorizontal();
            if (!hideCharacters)
            {
                if (GUILayout.Button(" + "))
                {
                    serializedObject.FindProperty("characters").InsertArrayElementAtIndex(serializedObject.FindProperty("characters").arraySize);
                }
            }
            if (GUILayout.Button(hideCharacters ? "Show " + rpgTalk.characters.Length + " characters" : "Hide Characters"))
            {
                hideCharacters = !hideCharacters;
            }
            EditorGUILayout.EndHorizontal();

            if (rpgTalk.shouldFollow && rpgTalk.characters.Length == 0)
            {
                EditorGUILayout.HelpBox("You need to set a Character and its Transform so that the Canvas can follow someone", MessageType.Error, true);
            }


            EditorGUI.indentLevel--;



            EditorGUILayout.EndVertical();
        }


        //create a nice box with round edges.
        EditorGUILayout.BeginVertical((GUIStyle)"HelpBox");
        EditorGUILayout.LabelField("Interface:", EditorStyles.boldLabel);
        EditorGUILayout.LabelField("Put below the UI for the text itself:");
        EditorGUILayout.PropertyField(serializedObject.FindProperty("textUIObj"));

        if (serializedObject.FindProperty("textUIObj").objectReferenceValue == null)
        {
            EditorGUILayout.HelpBox("There should be a Text, inside of a Canvas, to show the Talk.", MessageType.Error, true);
        }
        else if (!TMP_Translator.IsValidType(serializedObject.FindProperty("textUIObj").objectReferenceValue as GameObject))
        {
            EditorGUILayout.HelpBox("The object must be a Text or a Text Mesh Pro UGUI Type", MessageType.Error, true);
        }
        if (rpgTalk.dialoger)
        {
            EditorGUILayout.LabelField("Put below the UI for the name of the talker:");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("dialogerObj"));
            if (serializedObject.FindProperty("dialogerObj").objectReferenceValue == null)
            {
                EditorGUILayout.HelpBox("There should be a Text, inside of a Canvas, to show the name of the talker.", MessageType.Warning, true);
            }
            else if (!TMP_Translator.IsValidType(serializedObject.FindProperty("dialogerObj").objectReferenceValue as GameObject))
            {
                EditorGUILayout.HelpBox("The object must be a Text or a Text Mesh Pro UGUI Type", MessageType.Error, true);
            }
        }
        if (rpgTalk.shouldUsePhotos)
        {
            EditorGUILayout.LabelField("Put below the UI for the photo of the talker:");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("UIPhoto"));
            if (serializedObject.FindProperty("UIPhoto").objectReferenceValue == null)
            {
                EditorGUILayout.HelpBox("There should be a Image, inside of a Canvas, to show the talker's photo.", MessageType.Warning, true);
            }
        }
        EditorGUILayout.EndVertical();


        EditorGUILayout.BeginVertical((GUIStyle)"HelpBox");
        EditorGUILayout.LabelField("Callback & Variables:", EditorStyles.boldLabel);
        EditorGUILayout.LabelField("Any script should be called when the Talk is done?");
        EditorGUILayout.PropertyField(serializedObject.FindProperty("callback"), GUIContent.none);


        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Variables can be set to change some word in the text");
        EditorGUI.indentLevel++;
        EditorGUILayout.PropertyField(serializedObject.FindProperty("variables"), true);
        EditorGUI.indentLevel--;

        EditorGUILayout.EndVertical();

        EditorGUILayout.BeginVertical((GUIStyle)"HelpBox");
        EditorGUILayout.LabelField("Photos and Sprites:", EditorStyles.boldLabel);


        if (rpgTalk.textUIObj != null && TMP_Translator.IsText(rpgTalk.textUIObj))
        {
            EditorGUILayout.LabelField("Add sprites that can be used inside the text:");
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(serializedObject.FindProperty("sprites"), true);
            EditorGUI.indentLevel--;
            if (rpgTalk.sprites != null && rpgTalk.sprites.Count > 0)
            {
                EditorGUILayout.HelpBox("To use sprites inside the text, write the tag [sprite=X] and RPGTalk will replace it with the corresponding sprite above", MessageType.Info, true);
            }
        }
        else if (rpgTalk.textUIObj != null)
        {
            EditorGUILayout.LabelField("Write below the name of the Sprite Atlas Asset you want Text Mesh Pro to use:");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("tmpSpriteAtlas"), true);
            EditorGUILayout.HelpBox("To use sprites inside the text, write the tag [sprite=X] in your TXT and RPGTalk will replace it with the  Text Mesh Pro tag", MessageType.Info, true);
        }



        EditorGUILayout.EndVertical();

        EditorGUILayout.BeginVertical((GUIStyle)"HelpBox");
        EditorGUILayout.LabelField("Animation:", EditorStyles.boldLabel);
        EditorGUILayout.LabelField("A Animator can be manipulated when talking:");
        EditorGUILayout.PropertyField(serializedObject.FindProperty("animatorWhenTalking"), GUIContent.none);
        if (serializedObject.FindProperty("animatorWhenTalking").objectReferenceValue != null)
        {
            EditorGUILayout.LabelField("A Boolean to be set true when the character is talking:");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("animatorBooleanName"), GUIContent.none);
            EditorGUILayout.LabelField("A int can be set with the number of the talker, based on the list of photos:");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("animatorIntName"), GUIContent.none);
        }
        EditorGUILayout.EndVertical();

        EditorGUILayout.BeginVertical((GUIStyle)"HelpBox");
        EditorGUILayout.LabelField("Audio:", EditorStyles.boldLabel);
        EditorGUILayout.LabelField("The audio to be played by each letter:");
        EditorGUILayout.PropertyField(serializedObject.FindProperty("textAudio"), GUIContent.none);
        EditorGUILayout.LabelField("The audio to be played when the player passes the Talk:");
        EditorGUILayout.PropertyField(serializedObject.FindProperty("passAudio"), GUIContent.none);
        EditorGUILayout.EndVertical();

        EditorGUILayout.BeginVertical((GUIStyle)"HelpBox");
        EditorGUILayout.LabelField("Choices:", EditorStyles.boldLabel);
        EditorGUILayout.LabelField("Put below a Button prefab that will be instantiated when the player has choices");
        EditorGUILayout.PropertyField(serializedObject.FindProperty("choicePrefab"), GUIContent.none);
        EditorGUILayout.LabelField("Put below a object that the choice buttons will be instantiated to:");
        EditorGUILayout.PropertyField(serializedObject.FindProperty("choicesParent"), GUIContent.none);
        if (serializedObject.FindProperty("choicePrefab").objectReferenceValue != null && serializedObject.FindProperty("choicesParent").objectReferenceValue == null)
        {
            EditorGUILayout.HelpBox("There should be a parent to instantiate the choices to. Usually, it as an object inside the dialog box with a 'Layout Group' element.", MessageType.Warning, true);
        }
        EditorGUILayout.EndVertical();

        EditorGUILayout.Separator();

        EditorGUILayout.BeginVertical((GUIStyle)"HelpBox");
        EditorGUILayout.LabelField("So, I heard you like free stuff, hum?", EditorStyles.boldLabel);
        GUIStyle style = new GUIStyle();

        style.richText = true;
        string color = "#cc0000";

        GUILayout.Label(string.Format("Be sure to show your support by following <b><color={0}>Seize Studios</color></b> on social medias!", color), style);
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Like our page on Facebook!"))
        {
            Application.OpenURL(@"https://www.facebook.com/seizestudios/");
        }
        if (GUILayout.Button("Follow us on Twitter!"))
        {
            Application.OpenURL(@"https://twitter.com/seizestudios");
        }
        EditorGUILayout.EndHorizontal();
        GUIStyle centeredStyle = GUI.skin.GetStyle("Label");

        centeredStyle.alignment = TextAnchor.UpperCenter;
        EditorGUILayout.LabelField("www.seizestudios.com", centeredStyle);
        EditorGUILayout.EndVertical();



        if (EditorGUI.EndChangeCheck())
        {
            serializedObject.ApplyModifiedProperties();
        }
        //EditorGUIUtility.LookLikeControls();
    }
    public override void OnBehaviourPlay(Playable playable, FrameData info)
    {
        if (!m_TrackBinding)
        {
            return;
        }

        if (!m_FirstFrameHappened)
        {
            //on the first frame, set the defaults to recover after
            m_txtToParse      = m_TrackBinding.txtToParse;
            m_lineToBreak     = m_TrackBinding.lineToBreak;
            m_lineToStart     = m_TrackBinding.lineToStart;
            m_textSpeed       = m_TrackBinding.textSpeed;
            m_enableQuickSkip = m_TrackBinding.enableQuickSkip;
            m_enablePass      = m_TrackBinding.enablePass;

            //change the rpgTalk parameters
            if (txtToParse != null)
            {
                m_TrackBinding.txtToParse = txtToParse;
            }

            //If we won't wait for player action to finish, only one line (line to start) will be allowed.
            if (!pauseUntilTalkEnd)
            {
                //If we didn't set neither pauseUntilTalkEnd or autoPass, then we can't have lineToBreak.
                if (!autoPass)
                {
                    m_TrackBinding.lineToBreak = lineToStart;
                }
                else
                {
                    m_TrackBinding.lineToBreak = lineToBreak;
                }
                m_TrackBinding.enablePass = false;
            }
            else
            {
                m_TrackBinding.enablePass  = true;
                m_TrackBinding.lineToBreak = lineToBreak;
            }
            m_TrackBinding.lineToStart     = lineToStart;
            m_TrackBinding.textSpeed       = textSpeed;
            m_TrackBinding.enableQuickSkip = false;

            m_FirstFrameHappened = true;
            m_TrackBinding.NewTalk();

            startTime = new double[m_TrackBinding.rpgtalkElements.Count];
            for (int i = 0; i < m_TrackBinding.rpgtalkElements.Count; i++)
            {
                if (i == 0)
                {
                    startTime[i] = 0;
                }
                else
                {
                    startTime[i] = (m_TrackBinding.rpgtalkElements[i - 1].dialogText.Length
                                    / m_TrackBinding.actualTextSpeed) + secondsAutoPass;
                }
            }


            //Put an event for the end of the talk
            m_TrackBinding.OnEndTalk += OnEndTalk;

            if (m_TrackBinding.GetComponent <RPGTalkTimeline> ())
            {
                rpgTime = m_TrackBinding.GetComponent <RPGTalkTimeline> ();
            }

            // playableObj = playable;
        }
    }