Beispiel #1
0
    // Use this for initialization
    protected override void Awake()
    {
        base.Awake();

        var hinf = new RaycastHit();

        Grounded = Observable.EveryFixedUpdate()
                   .Select(_ => Physics.Raycast(RaycastOrigin, Vector3.down, out hinf, Level.Instance.DistBetweenAnchors, LayerMask.GetMask("Bounds", "Blocks", "Characters")))
                   .ToReadOnlyReactiveProperty(true);

        Grounded.AddTo(this);

        Grounded.Subscribe(x => Anim.SetBool("Falling", !x));

        ObservableHP = this.ObserveEveryValueChanged(x => x.CurHp)
                       .ToReadOnlyReactiveProperty(CurHp);

        IsDead = ObservableHP
                 .Select(x => x <= 0)
                 .ToReadOnlyReactiveProperty(false);

        Rb.OnCollisionEnterAsObservable()
        .Select(c => c.collider.GetComponentInParent <GameCharacter>())
        .Where(gc => gc && (gc.transform.position - transform.position).y < -Level.Instance.DistBetweenAnchors * .5f)
        .TakeUntil(IsDead.Where(x => x))
        .Subscribe(gc =>
        {
            target.Value = gc;
            gc.GetHit();
            Rb.AddForce(Vector3.up * 3.5f, ForceMode.Impulse);
        })
        .AddTo(this);
    }
Beispiel #2
0
    private void Start()
    {
        var blockInput = false;

        SwipeControl.Direction
        .Where(_ => !blockInput)
        .SelectMany(dir =>
        {
            blockInput = true;

            if (CanMoveTo(dir))
            {
                return(Move(dir, .5f));
            }

            SoundController.Play("swing");
            return(Attack(dir, .2f, .2f));
        })
        .TakeUntil(IsDead.Where(x => x))
        .Subscribe(_ => blockInput = false)
        .AddTo(this);

        Rb.OnCollisionEnterAsObservable()
        .Select(x => x.collider.GetComponent <ICollisionTriggerable>())
        .Where(x => x != null)
        .Subscribe(ctr => ctr.Trigger())
        .AddTo(this);

        //botkill reward and sound
        var botkillObs = target
                         .Where(x => x)
                         .Select(tgt => tgt.IsDead.Where(x => x).Take(1))
                         .Switch()
                         .Do(_ =>
        {
            Money.Current += GameController.Instance.botKillReward;
        })
                         .Publish();

        var thr = botkillObs.Throttle(TimeSpan.FromSeconds(1.4f));

        botkillObs.Buffer(thr)
        .Where(x => x.Count > 1)
        .Subscribe(_ => SoundController.Play("botkill"))
        .AddTo(this);

        botkillObs.Connect().AddTo(this);
    }