public static TabUpdateMessage Send(GameObject recipient, GameObject provider, NetTabType type, TabAction tabAction, GameObject changedBy = null,
                                        ElementValue[] values = null)
    {
//		if ( changedBy ) {
//			//body = human_33, hands, uniform, suit
//		}
        var msg = new TabUpdateMessage {
            Provider      = provider.NetId(),
            Type          = type,
            Action        = tabAction,
            ElementValues = values,
            Touched       = changedBy != null
        };

        switch (tabAction)
        {
        case TabAction.Open:
            NetworkTabManager.Instance.Add(provider, type, recipient);
            //!! resetting ElementValues
            msg.ElementValues = NetworkTabManager.Instance.Get(provider, type).ElementValues;
            //!!
            break;

        case TabAction.Close:
            NetworkTabManager.Instance.Remove(provider, type, recipient);
            break;

        case TabAction.Update:
            var playerScript = recipient.Player()?.Script;

            //fixme: duplication of NetTab.ValidatePeepers
            //Not sending updates and closing tab for players that don't pass the validation anymore
            bool validate = playerScript && !playerScript.canNotInteract() && playerScript.IsInReach(provider, true);
            if (!validate)
            {
                Send(recipient, provider, type, TabAction.Close);
                return(msg);
            }
            break;
        }
        msg.SendTo(recipient);
        Logger.LogTrace(msg.ToString(), Category.NetUI);
        return(msg);
    }
    public static TabUpdateMessage Send(GameObject recipient, GameObject provider, NetTabType type, TabAction tabAction,
                                        GameObject changedBy  = null,
                                        ElementValue[] values = null)
    {
        var msg = new TabUpdateMessage
        {
            Provider      = provider.NetId(),
            Type          = type,
            Action        = tabAction,
            ElementValues = values,
            Touched       = changedBy != null
        };

        switch (tabAction)
        {
        case TabAction.Open:
            NetworkTabManager.Instance.Add(provider, type, recipient);
            //!! resetting ElementValues
            msg.ElementValues = NetworkTabManager.Instance.Get(provider, type).ElementValues;
            //!!
            break;

        case TabAction.Close:
            NetworkTabManager.Instance.Remove(provider, type, recipient);
            break;

        case TabAction.Update:

            //fixme: duplication of NetTab.ValidatePeepers
            //Not sending updates and closing tab for players that don't pass the validation anymore
            var validate = Validations.CanApply(recipient, provider, NetworkSide.Server);
            if (!validate)
            {
                Send(recipient, provider, type, TabAction.Close);
                return(msg);
            }

            break;
        }

        msg.SendTo(recipient);
        Logger.LogTraceFormat("{0}", Category.NetUI, msg);
        return(msg);
    }
    public static TabUpdateMessage Send(GameObject recipient, GameObject provider, NetTabType type, TabAction tabAction,
                                        GameObject changedBy  = null,
                                        ElementValue[] values = null)
    {
        switch (tabAction)
        {
        case TabAction.Open:
            NetworkTabManager.Instance.Add(provider, type, recipient);
            values = NetworkTabManager.Instance.Get(provider, type).ElementValues;
            break;

        case TabAction.Close:
            NetworkTabManager.Instance.Remove(provider, type, recipient);
            break;

        case TabAction.Update:
            //fixme: duplication of NetTab.ValidatePeepers
            //Not sending updates and closing tab for players that don't pass the validation anymore
            var validate = Validations.CanApply(recipient, provider, NetworkSide.Server);
            if (!validate)
            {
                Send(recipient, provider, type, TabAction.Close);
                return(null);
            }
            break;
        }

        // SingleMessage, MoreIncoming, EndOfMessage
        var id = TabMessageType.SingleMessage;

        Counter++;
        var uniqueID = Counter;

        if (Counter > 10000)
        {
            Counter = 0;
        }

        var elementValuesLists = new Dictionary <List <ElementValue>, TabMessageType>();

        if (values != null && tabAction != TabAction.Close)
        {
            // get max possible packet size from current transform
            var maxPacketSize = Transport.activeTransport.GetMaxPacketSize(0);

            // set currentSize start value to max TCP header size (60b)
            var currentSize = 100;

            //Stores the current cycle of ElementValues
            var elementValues = new List <ElementValue>();

            //How many values are being sent
            var length = values.Length;

            //Total packet size if all values sent together
            var totalSize = 0;

            //Work out totalSize
            foreach (var value in values)
            {
                var size = value.GetSize();

                //If a single value is bigger than max packet size cannot proceed
                if (size + 60 >= maxPacketSize)
                {
                    Debug.LogError($"This value is above the max mirror packet limit, and cannot be split. Is {size + 60} bytes");
                    return(null);
                }

                totalSize += size;
            }

            //Rounds up to the max number of divisions of the max packet size will be needed for values
            var divisions = (int)Math.Ceiling((float)totalSize / maxPacketSize);

            //Counter for which division is currently being made
            var currentDivision = 0;

            //The loop for making the messages from the values
            for (var i = 0; i < length; i++)
            {
                //Keep adding values until bigger than packet size
                currentSize += values[i].GetSize();

                if (currentSize > maxPacketSize)
                {
                    currentDivision++;
                    currentSize = 100;

                    //Id MoreIncoming, means it is a multimessage but not the end.
                    id = TabMessageType.MoreIncoming;

                    //If last division then this will be the end, set to end Id of EndOfMessage
                    if (currentDivision == divisions)
                    {
                        id = TabMessageType.EndOfMessage;
                    }

                    //Add value list to the message list
                    elementValuesLists.Add(elementValues, id);
                    elementValues = new List <ElementValue>();
                }

                elementValues.Add(values[i]);
            }

            //Single message
            if (elementValuesLists.Count == 0)
            {
                values = elementValues.ToArray();
            }
            //Multimessage, if end division hasnt been reached yet then this last list must be end.
            else if (currentDivision != divisions)
            {
                elementValuesLists.Add(elementValues, TabMessageType.EndOfMessage);
            }
        }

        var count = elementValuesLists.Count;

        //Single message
        if (count == 0)
        {
            var msg = new TabUpdateMessage
            {
                Provider      = provider.NetId(),
                Type          = type,
                Action        = tabAction,
                ElementValues = values,
                Touched       = changedBy != null,
                ID            = id,
                UniqueID      = uniqueID
            };

            msg.SendTo(recipient);
            Logger.LogTraceFormat("{0}", Category.NetUI, msg);
            return(null);
        }

        foreach (var value in elementValuesLists)
        {
            var msg = new TabUpdateMessage
            {
                Provider      = provider.NetId(),
                Type          = type,
                Action        = tabAction,
                ElementValues = value.Key.ToArray(),
                Touched       = changedBy != null,
                ID            = value.Value,
                UniqueID      = uniqueID,
                NumOfMessages = count
            };

            msg.SendTo(recipient);
            Logger.LogTraceFormat("{0}", Category.NetUI, msg);
        }

        return(null);
    }