• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
-1
Question by KuPAfoo · Aug 28, 2013 at 12:59 AM · ordering

Chat order

When chatting in my chat bar it stacks the inputs. I would like to put them into a queue rather.

Meaning that the items display:

0(new chat message) 1 2 3 4 5th chat message

Here's the stack code for (int i = messages.Count - 1; i >= 0; i--) { GUILayout.Label(messages[i]); }

I can't wrap the logic around my mind to get the items to display like this:

5th (chat message) 4 3 2 1 0 (new chat message)

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image getyour411 · Aug 28, 2013 at 01:13 AM 0
Share

Here's what I use, if this doesn't match up with what you were asking I'll convert it to a comment:

(Globals)

 // PlayerLog
 private int _maxLines = 8;
 private Queue<string> _queue = new Queue<string>();
 private string $$anonymous$$ytext = "";

($$anonymous$$ethods)

 public void NewActivity(string activity) {
 if (_queue.Count >= _maxLines)
     _queue.Dequeue();
 
 _queue.Enqueue(activity);
 
 $$anonymous$$ytext = "";
 foreach (string st in _queue)
     $$anonymous$$ytext = $$anonymous$$ytext + st + "\n";
 }

in OnGUI

 // display playerLog
     GUI.Label(new Rect(2,                             // x, left offset
             (Screen.height - 150),                    // y, bottom offset
             300f,                                    // width
             150f), $$anonymous$$ytext,plogStyle);    // height, text, Skin features

and my other scripts pass messages to plog.NewActivity();

avatar image KuPAfoo getyour411 · Aug 28, 2013 at 03:44 AM 0
Share

I don't ever see Plog declared :\

is this the monobehavior you reference as class.NewActivity();?

avatar image getyour411 getyour411 · Aug 28, 2013 at 03:49 AM 0
Share

Yes, "Plog" is just what I declare in my other scripts like Plog = GameObject.Getcomponent().NewActivity("this is a new message")

avatar image getyour411 getyour411 · Aug 28, 2013 at 03:51 AM 0
Share

Oi, you are using Photon and networking stuff and honestly I don't know if my method plays nicely with that, so I'll change this to a comment/unanswered.

avatar image KuPAfoo · Aug 28, 2013 at 04:25 AM 0
Share

okay, well thanks for your help! I think your on the right track...

I've narrowed it down to a few lines of code making this print: scrollPos = GUILayout.BeginScrollView(scrollPos);

         GUI.color = Color.white;
         for (int i = messages.Count - 1; i >= 0; i--)
         {
         //    if(i>1)
             //GUILayout.Label.Remove (messages[0]);
             GUILayout.Label(messages[i]);
             
         }
         GUILayout.EndScrollView();

I was attempting to see if i could constantly print Only one message.

Then, i could hold all these items in a string array and queue them up to re-print on the GUILayout.Label after clearing it.

So, u know...

fill array[0] with msg 0 queue.push(msg 0) Print msg 0

while(queue.count!=chatmax) { fill array[1] with msg 1 queue.push(msg 1) while(queue.count>0) queue.pop(); print msg 1 print msg 2 }

I can code this, i just need to get the logic straight

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by KuPAfoo · Aug 28, 2013 at 02:19 AM

I don't quite understand what your saying here... Kind of new to unity still, but i'm a quick learner.

The chat i have set up is half backwards! It starts in the top of the window when it should begin at the bottom when I send a new message it should appear above my send bar, with the next message appearing underneath, oldest message should be pushed upwards until out of sight and maybe deletion (15 messages currently)

lemme sample you some code:

  void OnGUI()
     {        
         GUILayout.BeginArea(new Rect(0, Screen.height - chatHeight, Screen.width-400, chatHeight));
         
         GUI.color = Color.gray;
         windowRect = GUI.Window (0, windowRect, WindowFunction, "");//draw chat window
         if (Event.current.type == EventType.keyDown && Event.current.character == '\n'){
             if (GUI.GetNameOfFocusedControl() == "ChatField")
             {                
                 SendChat(PhotonTargets.All);
                 lastUnfocusTime = Time.time;
                 GUI.FocusControl("");
                 GUI.UnfocusWindow();
             }
             else
             {
                 //if (lastUnfocusTime < Time.time - 0.1f)
                 //{
                     GUI.FocusControl("ChatField");
                 //}
             }
         }
         
          GUILayout.EndArea();
         
     }
 
     public static void AddMessage(string text)
     {
         SP.messages.Add(text);
         if (SP.messages.Count > 15)
             SP.messages.RemoveAt(0);
     }
 
 
     [RPC]
     void SendChatMessage(string text, PhotonMessageInfo info)
     {
         AddMessage("[" + info.sender + "] " + text);//display player name+msg
     }
 
     void SendChat(PhotonTargets target)
     {
         if (chatInput != "")
         {
             photonView.RPC("SendChatMessage", target, chatInput);
             chatInput = "";
         }
     }
 
     void SendChat(PhotonPlayer target)
     {
         if (chatInput != "")
         {
             chatInput = "[PM] " + chatInput;
             photonView.RPC("SendChatMessage", target, chatInput);
             chatInput = "";
         }
     }
 
     void OnLeftRoom()
     {
         this.enabled = false;
     }
 
     void OnJoinedRoom()
     {
         this.enabled = true;
     }
     void OnCreatedRoom()
     {
         this.enabled = true;
     }
     void WindowFunction (int windowID) {
         // Draw any Controls inside the window here
         GUI.BringWindowToBack(0);
         GUI.SetNextControlName("");
         
         
         //Show scroll list of chat messages
         scrollPos = GUILayout.BeginScrollView(scrollPos);
         
         GUI.color = Color.white;
         for (int i = messages.Count - 1; i >= 0; i--)
         {
             GUILayout.Label(messages[i]);
         }
         GUILayout.EndScrollView();
         //GUI.EndGroup();
         GUI.color = Color.white;
 
         //Chat input
        GUILayout.BeginHorizontal(); //Send button
         GUI.SetNextControlName("ChatField");
     chatInput = GUILayout.TextField(chatInput, GUILayout.MinWidth(200));
        
         
 
         if (GUILayout.Button("SEND", GUILayout.Height(17)))
            SendChat(PhotonTargets.All);
         GUILayout.FlexibleSpace();
         GUILayout.EndHorizontal();
 
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Using SetPixel in Update() 1 Answer

Sort arrays using OrderBy and ThenBy Linq 1 Answer

Sort list of Vector3s by 2 distances 1 Answer

How to rearange the order of a list after an item was removed? 0 Answers

Editor Reorderable List - Properties 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges