天津23维预案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

53 lines
1.0 KiB

using UnityEngine;
using UnityEngine.UI;
using System;
namespace UIWidgetsSamples {
/// <summary>
/// ChatView test script.
/// </summary>
public class ChatViewTest : MonoBehaviour {
/// <summary>
/// ChatView.
/// </summary>
[SerializeField]
public ChatView Chat;
/// <summary>
/// The message.
/// </summary>
[SerializeField]
public InputField Message;
/// <summary>
/// The name of the user.
/// </summary>
[SerializeField]
public InputField UserName;
/// <summary>
/// Sends the message.
/// </summary>
public void SendMessage()
{
// check username and message
if ((UserName.text.Trim()=="") || Message.text.Trim()=="")
{
return ;
}
// add new message to chat
Chat.DataSource.Add(new ChatLine(){
UserName = UserName.text,
Message = Message.text,
Time = DateTime.Now,
Type = (UserName.text=="System") ? ChatLineType.System : ChatLineType.User,
});
Message.text = "";
// scroll to end
Chat.ScrollRect.verticalNormalizedPosition = 0f;
}
}
}