Exemple #1
0
    public DialogueLine StringToDialogueLine(string rawText)
    {
        string lineText             = "";
        string speaker              = null;
        float  speed                = 0.01f;
        List <DialogueImage> images = new List <DialogueImage>();


        while (rawText.Length > 0)
        {
            rawText = rawText.Trim();


            if (rawText[0] == '@')
            {
                rawText  = rawText.Remove(0, 1);
                lineText = rawText;
                break;
            }
            else if (rawText[0] == '[')
            {
                rawText = rawText.Remove(0, 1);
                speaker = rawText.Substring(0, rawText.IndexOf(']'));
                rawText = rawText.Remove(0, rawText.IndexOf(']'));
            }
            else if (rawText[0] == '{')
            {
                rawText = rawText.Remove(0, 1);
                speed   = float.Parse(rawText.Substring(0, rawText.IndexOf('}')));
                rawText = rawText.Remove(0, rawText.IndexOf('}'));
            }
            else if (rawText[0] == '(')
            {
                rawText = rawText.Remove(0, 1);

                Sprite sprite;
                if (rawText.Substring(0, rawText.IndexOf(',')).ToUpper() == "NONE")
                {
                    sprite = null;
                }
                else
                {
                    sprite = Resources.Load("Graphics/UI/Dialogue Sprites/" + rawText.Substring(0, rawText.IndexOf(',')), typeof(Sprite)) as Sprite;
                }



                rawText = rawText.Remove(0, rawText.IndexOf(',') + 1);
                rawText = rawText.Trim();

                DialogueImagePosition position = (DialogueImagePosition)Enum.Parse(typeof(DialogueImagePosition), rawText.Substring(0, rawText.IndexOf(',')));

                rawText = rawText.Remove(0, rawText.IndexOf(',') + 1);
                rawText = rawText.Trim();

                bool disabled = false;
                if (rawText.Substring(0, rawText.IndexOf(')')).ToUpper() == "D")
                {
                    disabled = true;
                }

                images.Add(new DialogueImage(sprite, position, disabled));
                rawText = rawText.Remove(0, rawText.IndexOf(')'));
            }
            else
            {
                rawText = rawText.Remove(0, 1);
            }
        }


        return(new DialogueLine(lineText, speaker, speed, images));
    }
 public DialogueImage(Sprite spriteSetter, DialogueImagePosition positionSetter, bool disableSetter = false)
 {
     sprite   = spriteSetter;
     position = positionSetter;
     disabled = disableSetter;
 }