示例#1
0
        protected override void OnInitialize()
        {
            base.OnInitialize();

            Camera   = Camera ?? GetViewport().GetCamera();
            Distance = InitialDistance;

            OnActiveStateChange
            .Do(v => _viewInput.Active = v)
            .Do(v => _zoomInput.Active = v)
            .Subscribe()
            .AddTo(this);

            ViewInput
            .Select(v => v * 0.05f)
            .Subscribe(v => Rotation -= v)
            .AddTo(this);

            ZoomInput
            .Subscribe(v => Distance -= v * 0.05f)
            .AddTo(this);

            OnActiveStateChange
            .Where(v => v)
            .Skip(Active ? 1 : 0)
            .Subscribe(_ => Distance = DistanceRange.Min + 0.1f)
            .AddTo(this);
        }
示例#2
0
        protected override void PostConstruct()
        {
            base.PostConstruct();

            RotationInput
            .Select(v => v * 0.02f)
            .TakeUntil(Disposed.Where(identity))
            .Subscribe(v => Rotation -= v, this);
            ZoomInput
            .TakeUntil(Disposed.Where(identity))
            .Subscribe(v => Distance -= v * 0.15f, this);

            OnActiveStateChange
            .Do(v => _rotationInput.Iter(i => i.Active = v))
            .Do(v => _zoomInput.Iter(i => i.Active     = v))
            .TakeUntil(Disposed.Where(identity))
            .Subscribe(this);
        }
示例#3
0
        protected override void OnInitialize()
        {
            base.OnInitialize();

            Input.SetMouseMode(Input.MouseMode.Visible);

            OnActiveStateChange
            .Do(v => _viewInput.Active     = v)
            .Do(v => _movementInput.Active = v)
            .Subscribe()
            .AddTo(this);

            MovementInput
            .Where(_ => _modifierPressed)
            .Select(v => v * 0.05f)
            .Subscribe(v => _offset.y += v)
            .AddTo(this);

            this.OnInput()
            .Where(e => Active && !e.IsEcho())
            .Select(e =>
                    e.IsActionPressed(_controlModifier) ||
                    !e.IsActionReleased(_controlModifier) && _modifierPressed)
            .Subscribe(v => _modifierPressed = v)
            .AddTo(this);

            if (Pivot is IBounded bounded)
            {
                var bounds = bounded.Bounds;

                var fov    = (Target as Camera)?.Fov ?? 70f;
                var height = bounds.GetLongestAxisSize();

                var distance = height / 2f / Math.Tan(Mathf.Deg2Rad(fov / 2f));

                Distance = (float)distance + 0.2f;
            }
        }