Forum rules - please read before posting.

[Feature request] Split multiline Dialogue Actions

Hi Chris,

while revising my game I come across many Dialogue Actions, that have multiple lines of text in it (sometimes up to 15 or more sentences). I'm currently inserting camera changes and animations in between these sentences and that is a huge amount of work, because I not only have to create new Actions and copy the text over, but most of these passages are already translated and the speech ids get lost doing this.

A feature to split a multiline Dialogue Action into seperate Dialogue Actions with one line of text each (with keeping the speaker and the speach line id) would be a life saver. And I guess a function for doing this in reverse could be useful to combine several Dialogue Actions (that are connected to each other and have the same speaker) and could help with improving the readability of Action Lists.

Maybe there is already a way to do this and I haven't found it yet?

Regards
Marcus

Comments

  • There's no way to do this, currently.

    I can't offer any promises, but I will look into it.

  • There's not really a tidy way to do this, but it is possible to have a custom script search a given ActionList for such lines, separate them, and re-assign the IDs:

    #if UNITY_EDITOR
    
    using UnityEngine;
    using AC;
    
    public class SeparateSplitActions : MonoBehaviour
    {
    
        public ActionList actionList;
    
        [ContextMenu ("Split actions")]
        public void SplitActions ()
        {
            if (actionList == null) return;
    
            int numSplit = 0;
            for (int i = 0; i < actionList.actions.Count; i++)
            {
                if (!(actionList.actions[i] is ActionSpeech)) continue;
    
                ActionSpeech actionSpeech = (ActionSpeech) actionList.actions[i];
                if (actionSpeech.GetNumTranslatables () <= 1) continue;
    
                string _text = actionSpeech.messageText.Replace ("\\n", "\n");
                string[] textArray = _text.Split (ActionSpeech.stringSeparators, System.StringSplitOptions.None);
    
                int[] idArray = actionSpeech.multiLineIDs;
    
                actionSpeech.messageText = textArray[0];
                actionSpeech.multiLineIDs = new int[0];
    
                for (int t = 1; t < textArray.Length; t++)
                {
                    int lineID = -1;
                    if ((t-1) < idArray.Length)
                    {
                        lineID = idArray[t-1];
                    }
    
                    ActionSpeech newSpeech = ActionSpeech.CreateNew (actionSpeech.speaker, textArray[t], lineID, actionSpeech.willWait);
                    newSpeech.isPlayer = actionSpeech.isPlayer;
                    newSpeech.isBackground = actionSpeech.isBackground;
                    newSpeech.waitTimeOffset = actionSpeech.waitTimeOffset;
                    newSpeech.NodeRect = new Rect (actionSpeech.NodeRect.x + 200 + (t * 20), actionSpeech.NodeRect.y + (t * 20), actionSpeech.NodeRect.width, actionSpeech.NodeRect.height);
                    newSpeech.endings = new System.Collections.Generic.List<ActionEnd> () { Action.GenerateStopActionEnd () };
                    actionList.actions.Add (newSpeech);
                }
    
                numSplit ++;
            }
    
            if (numSplit > 0)
            {
                Debug.Log ("Separated " + numSplit + " Actions");
                UnityEditor.EditorUtility.SetDirty (actionList);
            }
        }
    
    }
    
    #endif
    

    To use it, copy/paste into a C# file named SeparateSplitActions, put in the scene, fill in its Inspector, and use the context menu to run "Split actions".

    It won't fix the connections for the new Actions, but it should at least generate new Actions and assign them their old speech line ID values.

  • Thank you very much for the code. I had no time yet to test it, but will ASAP.

  • I tested the code and it works great. I just added the parameterID atttribute and the connections of the new Actions:

    #if UNITY_EDITOR
    
    using UnityEngine;
    using AC;
    
    public class SeparateSplitActions : MonoBehaviour
    {
    
        public ActionList actionList;
    
        [ContextMenu ("Split actions")]
        public void SplitActions ()
        {
            if (actionList == null) return;
    
            int numSplit = 0;
            for (int i = 0; i < actionList.actions.Count; i++)
            {
                if (!(actionList.actions[i] is ActionSpeech)) continue;
    
                ActionSpeech actionSpeech = (ActionSpeech) actionList.actions[i];
                if (actionSpeech.GetNumTranslatables () <= 1) continue;
    
                string _text = actionSpeech.messageText.Replace ("\\n", "\n");
                string[] textArray = _text.Split (ActionSpeech.stringSeparators, System.StringSplitOptions.None);
    
                int[] idArray = actionSpeech.multiLineIDs;
    
                actionSpeech.messageText = textArray[0];
                actionSpeech.multiLineIDs = new int[0];
    
                Action lastActionSpeech = actionSpeech;
                ActionEnd originalActionEnd = lastActionSpeech.endings[0];
    
                for (int t = 1; t < textArray.Length; t++)
                {
                    int lineID = -1;
                    if ((t-1) < idArray.Length)
                    {
                        lineID = idArray[t-1];
                    }
    
                    ActionSpeech newSpeech = ActionSpeech.CreateNew (actionSpeech.speaker, textArray[t], lineID, actionSpeech.willWait);
                    newSpeech.speaker = actionSpeech.speaker;
                    newSpeech.parameterID = actionSpeech.parameterID;
                    newSpeech.isPlayer = actionSpeech.isPlayer;
                    newSpeech.isBackground = actionSpeech.isBackground;
                    newSpeech.waitTimeOffset = actionSpeech.waitTimeOffset;
                    newSpeech.NodeRect = new Rect (actionSpeech.NodeRect.x + 200 + (t * 20), actionSpeech.NodeRect.y + (t * 20), actionSpeech.NodeRect.width, actionSpeech.NodeRect.height);
                    newSpeech.endings = new System.Collections.Generic.List<ActionEnd> () { Action.GenerateStopActionEnd () };
                    actionList.actions.Add (newSpeech);
    
                    // Reconnect Actions
                    lastActionSpeech.SetOutput(new ActionEnd(actionList.actions.IndexOf(newSpeech)));
                    lastActionSpeech = (ActionSpeech) actionList.actions[actionList.actions.IndexOf(newSpeech)];
                }
                lastActionSpeech.SetOutput(originalActionEnd);
    
                numSplit ++;
            }
    
            if (numSplit > 0)
            {
                Debug.Log ("Separated " + numSplit + " Actions");
                UnityEditor.EditorUtility.SetDirty (actionList);
            }
        }
    
    }
    
    #endif
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.