예제 #1
0
        protected override void HandleTransformUpdateMessage(TransformUpdateMessage transformUpdateMessage)
        {
            _logger.Debug("Received transform update");
            GameObject toBeUpdated = _networkManager.GetGameObjectById(transformUpdateMessage.entityId)?.gameObject;

            if (toBeUpdated != null)
            {
                NetworkMonoBehaviour networkMonoBehaviour;
                if (toBeUpdated.TryGetComponent(out networkMonoBehaviour))
                {
                    if (transformUpdateMessage.subTransformIndex >= 0)
                    {
                        networkMonoBehaviour.UpdateChildTransform(transformUpdateMessage.subTransformIndex, NetworkHelper.ConvertToVector3(transformUpdateMessage.position), NetworkHelper.ConvertToVector3(transformUpdateMessage.rotation));
                    }
                    else
                    {
                        networkMonoBehaviour.SetNextTransform(NetworkHelper.ConvertToVector3(transformUpdateMessage.position), NetworkHelper.ConvertToVector3(transformUpdateMessage.rotation));
                    }
                }
                else
                {
                    throw new Exception("The Network object with id: " + transformUpdateMessage.entityId + " has no NetworkMonoBehaviour component on it, thus it can't be updated!");
                }
            }
            else
            {
                throw new Exception("Network object with id: " + transformUpdateMessage.entityId + " could not be found!");
            }
        }