Example #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);
        }
Example #2
0
        protected override void OnInitialize()
        {
            base.OnInitialize();

            _boneIndex = Skeleton.FindBone(PositionBone);

            Debug.Assert(_boneIndex != -1, $"Failed to find a bone named '{PositionBone}'.");

            _initialTransform = Skeleton.GetBoneTransform(_boneIndex);

            AnimationManager.OnBeforeAdvance
            .Where(_ => Valid)
            .Subscribe(_ => OnBeforeAnimation())
            .AddTo(this);

            AnimationManager.OnAdvance
            .Subscribe(OnAnimation)
            .AddTo(this);

            OnActiveStateChange
            .Where(v => !v && Valid)
            .Subscribe(_ => ResetAnimations())
            .AddTo(this);

            AnimationManager.Player
            .GetAnimationList()
            .Select(AnimationManager.Player.GetAnimation)
            .Where(a => a.Loop)
            .ToList()
            .ForEach(AddTrack);

            Reset();
        }
        protected override void PostConstruct()
        {
            base.PostConstruct();

            OnActiveStateChange
            .Where(v => !v && Valid)
            .TakeUntil(Disposed.Where(identity))
            .Subscribe(_ => ResetAnimations(), this);
        }
Example #4
0
        protected override void OnInitialized()
        {
            base.OnInitialized();

            OnInitialize
            .Subscribe(_ => Activate(), Debug.LogError)
            .AddTo(this);
            OnActiveStateChange
            .Subscribe(_ => Reset(), Debug.LogError)
            .AddTo(this);
        }
Example #5
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);
        }
Example #6
0
        protected override void OnInitialize()
        {
            base.OnInitialize();

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

            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)
            .Subscribe(_ => Distance = InitialDistance)
            .AddTo(this);
        }
Example #7
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;
            }
        }