/// <summary>
        /// Display ChatLine.
        /// </summary>
        /// <param name="item">Item.</param>
        public void SetData(ChatLine item)
        {
            Item = item;

            UserName.text = item.UserName;
            Message.text  = item.Message;
            Time.text     = item.Time.ToString("[HH:mm:ss]");

            if (Image != null)
            {
                Image.gameObject.SetActive(item.Image != null);
                Image.sprite = item.Image;
            }

            if (Audio != null)
            {
                Audio.gameObject.SetActive(item.Audio != null);
                Audio.SetAudioClip(item.Audio);
            }
        }
Example #2
0
        /// <summary>
        /// Sends the message.
        /// </summary>
        public void SendMessage()
        {
            if (string.IsNullOrEmpty(UserName.text.Trim()))
            {
                return;
            }

            if (string.IsNullOrEmpty(Message.text.Trim()) && !AttachImage.IsOn && !AttachAudio.IsOn)
            {
                return;
            }

            // add new message to chat
            var line = new ChatLine()
            {
                UserName = UserName.text,
                Message  = Message.text,
                Time     = DateTime.Now,
                Type     = Type.IsOn ? ChatLineType.Outgoing : ChatLineType.Incoming,
            };

            if (AttachImage.IsOn)
            {
                line.Image = TestImage;
            }

            if (AttachAudio.IsOn)
            {
                line.Audio = TestAudio;
            }

            Chat.DataSource.Add(line);

            Message.text = string.Empty;

            // scroll to end
            Chat.ScrollRect.verticalNormalizedPosition = 0f;
        }