Пример #1
0
    //helper function to display the SimChat
    public void displayChat(Rect area, SimChat sc, Vector2 sp, string sender)
    {
        sp.y = Mathf.Infinity;
        GUILayout.BeginArea(area);
        GUILayout.BeginHorizontal("box");
        GUILayout.Label("Name: " + sender);
        GUILayout.EndHorizontal();
        GUILayout.BeginVertical("box");
        sp = GUILayout.BeginScrollView(sp);
        Color c = GUI.contentColor;

        //loop through each of the messages contained in allMessages
        GUI.skin.label.wordWrap = true;
        foreach (SimpleMessage sm in sc.allMessages)
        {
            GUILayout.BeginHorizontal();
            //check if the sender had the same name as me, and change the color
            if (sm.sender == sender)
            {
                GUI.contentColor = Color.red;
                GUILayout.FlexibleSpace();
                GUILayout.Label(sm.message);
            }
            else
            {
                GUI.contentColor = Color.green;
                GUILayout.Label(sm.sender + ": " + sm.message);
                GUILayout.FlexibleSpace();
            }
            GUILayout.EndHorizontal();
        }
        GUI.contentColor = c;
        GUILayout.EndScrollView();
        GUILayout.BeginHorizontal();
        //send a new message
        sc.message = GUILayout.TextField(sc.message);
        if (GUILayout.Button("Send"))
        {
            //filter words from the string
            wf.cleanString(ref sc.message);
            sc.sendMessage();
            sc.message = "";
        }
        GUILayout.EndHorizontal();
        GUILayout.EndVertical();
        GUILayout.EndArea();
    }
Пример #2
0
 void OnGUI()
 {
     GUILayout.BeginArea(new Rect(10, 10, Screen.width - 20, Screen.height - 20));
     GUILayout.BeginHorizontal("box");
     GUILayout.FlexibleSpace();
     GUILayout.BeginVertical();
     GUILayout.FlexibleSpace();
     if (hasLoadedWords)
     {
         if (isFilteringString)
         {
             GUILayout.Label("Filtering " + dots(startTime, 4));
         }
         else
         {
             if (replacements)
             {
                 GUILayout.Label(clean);
                 dirty = GUILayout.TextArea(dirty, GUILayout.MinWidth(Screen.width / 2));
                 if (GUILayout.Button("Filter"))
                 {
                     clean = wf.cleanString(dirty);
                 }
                 if (GUILayout.Button("Filter in Separate Thread"))
                 {
                     isFilteringString = true;
                     wf.startCleanString(dirty);
                 }
             }
             else                   //if replacements are not used, actively replace the input text
             {
                 dirty = GUILayout.TextArea(dirty, GUILayout.MinWidth(Screen.width / 2));
                 wf.cleanString(ref dirty);
                 GUILayout.Label("Words are automatically replaced");
             }
         }
     }
     else
     {
         if (isloadingFile)
         {
             GUILayout.Label("Downloading File " + dots(startTime, 4));
         }
         else
         {
             //determines if the replacement words will be used
             replacements = GUILayout.Toggle(replacements, "Use Replacement Words");
             if (GUILayout.Button("Read Resource File"))
             {
                 getRescourceFile(replacements);
             }
             if (GUILayout.Button("Download Word File"))
             {
                 startTime     = Time.time;
                 isloadingFile = true;
                 downloadWords(replacements);
             }
         }
     }
     GUILayout.FlexibleSpace();
     GUILayout.EndVertical();
     GUILayout.FlexibleSpace();
     GUILayout.EndHorizontal();
     GUILayout.EndArea();
 }
Пример #3
0
    public void draw()
    {
        //display new message
        if (Time.time - rt < messageTime && allMessages.Count > 0)
        {
            GUILayout.Label("New Message: " + allMessages[allMessages.Count - 1].sender + ": " + allMessages[allMessages.Count - 1].message);
        }

        //show chat area
        if (show)
        {
            GUI.skin.label.wordWrap = true;
            GUILayout.BeginArea(chatRect);
            GUILayout.BeginVertical("box");

            GUILayout.BeginVertical("box");
            sp = GUILayout.BeginScrollView(sp);
            GUILayout.FlexibleSpace();
            c = GUI.contentColor;
            //loop through each of the messages contained in allMessages
            foreach (SimpleMessage sm in allMessages)
            {
                GUILayout.BeginHorizontal(GUILayout.Width(chatRect.width - 25));                              //GUILayout.MaxWidth(chatRect.width-10)
                if (sm.sender == senderName)
                {
                    GUI.contentColor = myColor;
                    GUILayout.FlexibleSpace();
                    GUILayout.Label(sm.message);
                }
                else
                {
                    GUI.contentColor = theirColor;
                    GUILayout.Label(sm.sender + ": " + sm.message);
                    GUILayout.FlexibleSpace();
                }
                GUILayout.EndHorizontal();
            }
            //display the pending messages
            GUI.contentColor = myColor;
            foreach (string p in pending)
            {
                GUILayout.BeginHorizontal(GUILayout.Width(chatRect.width - 25));
                GUILayout.FlexibleSpace();
                GUILayout.Label(p);
                GUILayout.EndHorizontal();
            }
            GUI.contentColor = c;
            GUILayout.EndScrollView();
            GUILayout.EndVertical();

            GUILayout.BeginHorizontal();
            //send a new message
            message = GUILayout.TextField(message);
            if (GUILayout.Button("Send", GUILayout.MaxWidth(100)) || (Event.current.isKey && Event.current.keyCode == KeyCode.Return))
            {
                wf.cleanString(ref message);
                sendMessage();
                pending.Add(message);
                message = "";
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
            GUILayout.EndArea();
        }
    }