Exemplo n.º 1
0
    void SubscribeToEnterence(PortalEnterence enterence)
    {
        var otherEnterence = OtherEnterence(enterence);

        Observable.FromEvent <GameObject>(
            h => enterence.ProjectilePenetration += h,
            h => enterence.ProjectilePenetration -= h)
        .ObserveOnMainThread()
        .Do(x => {
            otherEnterence.GetComponent <CircleCollider2D>().enabled = false;
            var rigidBody          = x.GetComponent <Rigidbody2D>();
            this.enterenceSize     = x.transform.localScale;
            this.enterenceVelocity = rigidBody.velocity;

            rigidBody.constraints = RigidbodyConstraints2D.FreezeAll;
            x.transform.DOScale(0.01f, PortalEnteranceDuration);
            x.transform.DOMove(enterence.transform.position, PortalEnteranceDuration);
        })
        .Delay(TimeSpan.FromSeconds(PortalEnteranceDuration))
        .Do(x => {
            var spriteRenderer     = x.GetComponent <SpriteRenderer>();
            spriteRenderer.enabled = false;
        })
        .Delay(TimeSpan.FromSeconds(TransportationDelay))
        .Subscribe(x => {
            var rigidBody      = x.GetComponent <Rigidbody2D>();
            var spriteRenderer = x.GetComponent <SpriteRenderer>();
            AllowedEnterenceCount.Value--;

            x.transform.position = otherEnterence.transform.position;
            x.transform.DOScale(enterenceSize, PortalExitDuration);

            spriteRenderer.enabled = true;
            rigidBody.constraints  = RigidbodyConstraints2D.None;
            rigidBody.velocity     = enterenceVelocity;
        })
        .AddTo(disposables);

        AllowedEnterenceCount.AsObservable()
        .Where(x => x == 0)
        .Delay(TimeSpan.FromSeconds(MinimumDestoryTime))
        .Do(_ => {
            firstEnterence.PrepareToDestroy(PortalDestroyDuration);
            secondEnterence.PrepareToDestroy(PortalDestroyDuration);
        })
        .Delay(TimeSpan.FromSeconds(PortalDestroyDuration))
        .Subscribe(x => {
            Destroy(gameObject);
        })
        .AddTo(disposables);
    }
Exemplo n.º 2
0
 PortalEnterence OtherEnterence(PortalEnterence enterence)
 {
     return(enterence == firstEnterence ? secondEnterence : firstEnterence);
 }