/// <inheritdoc/>
        protected override void OnMessageReceived(IncomingMessage msg)
        {
            var key  = msg.ReadString();
            var type = msg.ReadInt32();

            if ((int)EnvironmentDataTypes.Float == type)
            {
                var value = msg.ReadFloat32();

                m_Parameters[key] = () => value;

                Action <float> action;
                m_RegisteredActions.TryGetValue(key, out action);
                action?.Invoke(value);
            }
            else if ((int)EnvironmentDataTypes.Sampler == type)
            {
                int          seed        = msg.ReadInt32();
                int          samplerType = msg.ReadInt32();
                Func <float> sampler     = () => 0.0f;
                if ((int)SamplerType.Uniform == samplerType)
                {
                    float min = msg.ReadFloat32();
                    float max = msg.ReadFloat32();
                    sampler = SamplerFactory.CreateUniformSampler(min, max, seed);
                }
                else if ((int)SamplerType.Gaussian == samplerType)
                {
                    float mean   = msg.ReadFloat32();
                    float stddev = msg.ReadFloat32();

                    sampler = SamplerFactory.CreateGaussianSampler(mean, stddev, seed);
                }
                else if ((int)SamplerType.MultiRangeUniform == samplerType)
                {
                    IList <float> intervals = msg.ReadFloatList();
                    sampler = SamplerFactory.CreateMultiRangeUniformSampler(intervals, seed);
                }
                else
                {
                    Debug.LogWarning("EnvironmentParametersChannel received an unknown data type.");
                }
                m_Parameters[key] = sampler;
            }
            else
            {
                Debug.LogWarning("EnvironmentParametersChannel received an unknown data type.");
            }
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        protected override void OnMessageReceived(IncomingMessage msg)
        {
            var key  = msg.ReadString();
            var type = msg.ReadInt32();

            if ((int)EnvironmentDataTypes.Float == type)
            {
                var value = msg.ReadFloat32();

                m_Parameters[key] = value;

                Action <float> action;
                m_RegisteredActions.TryGetValue(key, out action);
                action?.Invoke(value);
            }
            else
            {
                Debug.LogWarning("EnvironmentParametersChannel received an unknown data type.");
            }
        }
        /// <inheritdoc/>
        protected override void OnMessageReceived(IncomingMessage msg)
        {
            var messageType = (ConfigurationType)msg.ReadInt32();

            switch (messageType)
            {
            case ConfigurationType.ScreenResolution:
                var width  = msg.ReadInt32();
                var height = msg.ReadInt32();
                Screen.SetResolution(width, height, false);
                break;

            case ConfigurationType.QualityLevel:
                var qualityLevel = msg.ReadInt32();
                QualitySettings.SetQualityLevel(qualityLevel, true);
                break;

            case ConfigurationType.TimeScale:
                var timeScale = msg.ReadFloat32();

                // There's an upper limit for the timeScale in the editor (but not in the player)
                // Always ensure that timeScale >= 1 also,
#if UNITY_EDITOR
                const float maxTimeScale = 100f;
#else
                const float maxTimeScale = float.PositiveInfinity;
#endif
                timeScale      = Mathf.Clamp(timeScale, 1, maxTimeScale);
                Time.timeScale = timeScale;
                break;

            case ConfigurationType.TargetFrameRate:
                var targetFrameRate = msg.ReadInt32();
                Application.targetFrameRate = targetFrameRate;
                break;

            case ConfigurationType.CaptureFrameRate:
                var captureFrameRate = msg.ReadInt32();
                Time.captureFramerate = captureFrameRate;
                break;

            default:
                Debug.LogWarning(
                    "Unknown engine configuration received from Python. Make sure" +
                    " your Unity and Python versions are compatible.");
                break;
            }
        }
        /// <inheritdoc/>
        protected override void OnMessageReceived(IncomingMessage msg)
        {
            var messageType = (ConfigurationType)msg.ReadInt32();

            switch (messageType)
            {
            case ConfigurationType.ScreenResolution:
                var width  = msg.ReadInt32();
                var height = msg.ReadInt32();
                Screen.SetResolution(width, height, false);
                break;

            case ConfigurationType.QualityLevel:
                var qualityLevel = msg.ReadInt32();
                QualitySettings.SetQualityLevel(qualityLevel, true);
                break;

            case ConfigurationType.TimeScale:
                var timeScale = msg.ReadFloat32();
                timeScale      = Mathf.Clamp(timeScale, 1, 100);
                Time.timeScale = timeScale;
                break;

            case ConfigurationType.TargetFrameRate:
                var targetFrameRate = msg.ReadInt32();
                Application.targetFrameRate = targetFrameRate;
                break;

            case ConfigurationType.CaptureFrameRate:
                var captureFrameRate = msg.ReadInt32();
                Time.captureFramerate = captureFrameRate;
                break;

            default:
                Debug.LogWarning(
                    "Unknown engine configuration received from Python. Make sure" +
                    " your Unity and Python versions are compatible.");
                break;
            }
        }