Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by D3m0nE · Feb 27, 2013 at 01:59 AM · guiguilayoutlabelchat

GUILayout Sort Problem

Hello Everyone I Was Doing a C# Game Chat [All - Team - Whisper] and its work fine. but there is problem with the Sorting

Lemme Show You The Picture i Will Explain More alt text

Here We Go :

The [All] Chat Togather And The Team Chat Togather and Whisper Chat Togather

its not sorted by Newest!

Its Shows This Way 2 To All , 5 To All , 3 To Team , 4 To Team

It Should Be : 2 To All , 3 To Team , 4 To Team , 5 To All

i hope You Got It

And Here is the Code i Use

     myStyle.normal.textColor = Color.magenta;
     GUILayout.Label(communicationWhisper,myStyle);
     
     myStyle.normal.textColor = Color.cyan;
     GUILayout.Label(communicationTeam,myStyle);
         
     myStyle.normal.textColor = Color.white;
     GUILayout.Label(communication,myStyle);
 
achat problem.png (33.3 kB)
Comment
Add comment · Show 2
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 D3m0nE · Feb 28, 2013 at 11:30 PM 0
Share

The TeamChat have communicationWhisper,, and the Whisper have communicationTeam and ToAll > communicationAll ,,,

avatar image Chronos-L · Mar 02, 2013 at 01:04 AM 0
Share

What is stored in the communicationWhisper when you add it the chat? It is a single line of message, or you are still appending all your whisper messages to it?

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Chronos-L · Feb 27, 2013 at 08:01 AM

I am just going to give this a shot as I do not fully understand your explanation.

From your code fragment, you are just outputting the 3 sets of communication separately. From what I can see, I think that in your current script, you just append the latest message to a string variable or gui content ( communicationWhisper, communicationTeam, communication ). By doing so, you can only sort them by separately, not as a whole chat.

What you need to do is to create a new class to store the message.

 public enum CommType{ NORMAL, WHISPER, TEAM };
 
 public class Message {
    public string content;
    public CommType commType;
 
    public Message( string cont, CommType ct ) {
        //Standard constructor
    }
 }

Then, in your chat script

 List <Message> chat = new List<Message>();



All message will go to this chat variable. Whenever there is a new piece coming in:

 chat.Add( new Message("My Message", CommType.WHISPER ) );

On output, do this:

 //We are iterating the list in reverse order, as the newest message starts from the back
 for(int i = chat.Count - 1; i >= 0; --i ) {       
    //Use either a function or a if-else structure to determine the textColor, 
    //I am using a function in this example
    myStyle.normal.textColor = CommColor( chat[i].commType );
    GUILayout.Label( chat[i].content, myStyle );
 } 

Hope that this is what you are looking for.


Code Test

This is what I got after implementing the codes. By the way, I wrote a test class that send messages to the chatControl object by detecting different Input.GetKeyDown(KeyCode.??)

I hope that this code is what you are looking for.

alt text

alt text


screenshot.4.png (12.2 kB)
screenshot.2.png (11.1 kB)
Comment
Add comment · Show 7 · 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
avatar image D3m0nE · Feb 27, 2013 at 11:52 AM 0
Share

i added this codes and no error shows :)

but also no chat shows xDD

so its didnt work

thanks anyway .........

There is Easier Way By $$anonymous$$ake all Chat in string "communicationChat"

its works fine. but the problem in Color

If I made Team Chat. all Chat will be in blue If I $$anonymous$$ade Whisper , all Chat will be in Red because it going to be in 1 label

avatar image Chronos-L · Feb 28, 2013 at 04:08 AM 0
Share

$$anonymous$$y script foreach(int i = chat.Count - 1; i >= 0; --i ) {...} is outputting each individual chat item, so it should be colored according to their type.

To mix color, you have to use different label for each individual message.

I don't understand why no chat message is shown when you run the script? Do you insert each new messages using chat.Add( new $$anonymous$$essage( ... ) );?

avatar image D3m0nE · Feb 28, 2013 at 07:58 AM 0
Share

yes

chat.Add(new $$anonymous$$essage(communicationTeam, CommType.Team));

In TeamChat RPC . and

chat.Add(new $$anonymous$$essage(communicationWhisper, CommType.Whisper));

in WhisperChat Rpc ..

Etc

avatar image Chronos-L · Feb 28, 2013 at 10:43 AM 0
Share

Does TeamChat RPC and WhisperChat RPC refers to the same chat variable? There should be one and just one chat variable, otherwise, messages of different CommType will not mixed together.

avatar image Chronos-L · Mar 01, 2013 at 02:57 AM 1
Share

I am talking about the chat variable, are your RPC (I assumed that this is a class) uses the same chat variable?

Up to this point, it would be better if you post the communication codes here (Don't do it in the comment section, edit your question and add the codes there)

Show more comments

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.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

How to destroy a chat message (GUI label)? 1 Answer

Fade out GUILayout Area? 1 Answer

Change Color For One Line? 1 Answer

Why does old text in GUILayout not disappear? 1 Answer

GUILayout Icon + Text 3 Answers


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