Ejemplo n.º 1
0
    /// <summary>
    /// Swapes secondary message with the removed main message.
    /// </summary>
    /// <param name="nextMessage">Secondary message that should be swapped.</param>
    private void SwapSecondaryToMain(ChatMessage nextMessage)
    {
        /// Instantiate new main message
        ChatMessage newMainMessage = InstantiateMainMessage(nextMessage.Data, nextMessage.Data.sender);

        /// Change data that new message will not be animated
        MessageData newData = nextMessage.Data;

        newData.animate = false;

        /// Setup new message
        newMainMessage.Setup(new ChatItemData(newData, remover, avatarLoader, newData.sender));
        /// Set sibling of the new message to the removed main message
        newMainMessage.transform.SetSiblingIndex(nextMessage.transform.GetSiblingIndex());

        /// If new message is last in the chat, add to end of the list, else insert by removed main message index
        if (nextMessage.transform.GetSiblingIndex() >= messages.Count)
        {
            messages.Add(newMainMessage);
        }
        else
        {
            messages.Insert(nextMessage.transform.GetSiblingIndex(), newMainMessage);
        }

        nextMessage.DestroyMessage();

        messages.Remove(nextMessage);
    }