public int SendCreateEntityMsg(Vector3 location, Vector3 orientation, EntityType entityType, ForceType forceType = ForceType.DtForceOther)
    {
        int requestId = Random.Range(0, 1000000000);

        while (CreateEntityRequests.ContainsKey(requestId))
        {
            requestId = Random.Range(0, 1000000000);
        }

        CreateEntityInfo info = new CreateEntityInfo()
        {
            Location    = location,
            Orientation = orientation,
            EntityType  = entityType,
            ForceType   = forceType
        };

        CreateEntityRequests[requestId] = info;

        CreateEntityInteraction createEntityInteraction;

        createEntityInteraction.senderId   = InfantryPublishedEntity.MyEntityId;
        createEntityInteraction.requestId  = requestId;
        createEntityInteraction.receiverId = EntityId.NullId;

        ExerciseConnection.SendCreateEntityInteraction(createEntityInteraction);

        if (OnSendCreateEntityMsg != null)
        {
            OnSendCreateEntityMsg();
        }

        return(requestId);
    }
    private IEnumerator SendCreatePersistent(int requestId)
    {
        yield return(new WaitForSeconds(RetryRequestRate));

        while (CreateEntityRequests.ContainsKey(requestId))
        {
            int id = requestId;
            CreateEntityInfo info = CreateEntityRequests[requestId];
            requestId = SendCreateEntityMsg(info.Location, info.Orientation, info.EntityType, info.ForceType);

            CreateEntityRequests.Remove(id);
            yield return(new WaitForSeconds(RetryRequestRate));
        }
    }
    private void AcknowledgeCallback(AcknowledgeInteraction acInteraction)
    {
        if (null == InfantryPublishedEntity || acInteraction.receiverId != InfantryPublishedEntity.MyEntityId)
        {
            return;
        }

        if (acInteraction.acknowledgeFlag == NetStructs.AcknowledgeFlag.DtAckCreate)
        {
            if (!CreateEntityRequests.ContainsKey(acInteraction.requestId))
            {
                return;
            }

            CreateEntityInfo info = CreateEntityRequests[acInteraction.requestId];

            Vector3    newEntityLocation = info.Location;
            Vector3    orientation       = info.Orientation;
            EntityType entityType        = info.EntityType;
            ForceType  ForceType;

            if (info.ForceType == ForceType.DtForceOther)
            {
                ForceType = InfantryPublishedEntity.ForceType;
            }
            else
            {
                ForceType = info.ForceType;
            }

            EntityId senderId   = InfantryPublishedEntity.MyEntityId;
            EntityId recieverId = acInteraction.senderId;
            int      requestId  = acInteraction.requestId;
            XYZ      location;
            location.X = newEntityLocation.x;
            location.Y = newEntityLocation.y;
            location.Z = newEntityLocation.z;

            // x and y values of the orientation are switched in order to preserve the original rotation, don't know the reason why
            ExerciseConnection.SendCreateEntitySetData(senderId, recieverId, requestId, entityType, location, ForceType, orientation.y, orientation.x, orientation.z);

            CreateEntityRequests.Remove(requestId);

            if (OnCreateEntity != null)
            {
                OnCreateEntity(entityType);
            }
        }
        else if (acInteraction.acknowledgeFlag == NetStructs.AcknowledgeFlag.DtAckRemove)
        {
            if (!RemoveEntityRequests.ContainsKey(acInteraction.requestId))
            {
                return;
            }

            if (OnRemoveEntity != null)
            {
                OnRemoveEntity(RemoveEntityRequests[acInteraction.requestId]);
            }

            RemoveEntityRequests.Remove(acInteraction.requestId);
        }
    }