コード例 #1
0
        public void Display(Dialog dialog, DialogPartner initiator, DialogPartner initiated, int startingPage = 0)
        {
            if (animatingOpenClose)
            {
                return;
            }

            forceFacing = false;

            BaseActor actor = null;

            if (initiator != null)
            {
                actor = initiator.GetComponent <BaseActor>();
                if (actor != null)
                {
                    actor.Move(Vector2.zero);
                }
            }
            if (initiated != null)
            {
                actor = initiated.GetComponent <BaseActor>();
                if (actor != null)
                {
                    actor.Move(Vector2.zero);
                }
            }

            this.dialog = dialog;
            SetVisibility(true);
            this.initiated = initiated;
            this.initiator = initiator;
            DisplayPage(startingPage);
        }
コード例 #2
0
        public void Advance(float seconds)
        {
            animationTime += seconds;
            if (currentAnimationId < 0 || currentAnimationFrameCount == 0)
            {
                return;
            }

            int   frame = 0;
            var   anim  = currentCollection[currentAnimationId];
            float d     = anim.Duration;

            if (d <= 0f)
            {
                anim.CalculateDuration();
                d = anim.Duration;
            }
            float t             = animationTime % d;
            float frameDuration = 0f;


            while ((frameDuration = anim.frames[frame].durationMultiplier / anim.fps) < t)
            {
                t -= frameDuration;
                frame++;
                if (frame >= currentAnimationFrameCount)
                {
                    frame %= currentAnimationFrameCount;
                }
            }


            if (anim.frames[frame] != currentFrame)
            {
                if (currentFrame != null)
                {
                    if (currentFrame.frameEvent != null)
                    {
                        currentFrame.frameEvent.OnFrameExit(this, currentFrame);
                    }
                }
                currentFrame = anim.frames[frame];
                if (currentFrame.frameEvent != null)
                {
                    currentFrame.frameEvent.OnFrameEnter(this, currentFrame);
                }
            }

            var s = currentFrame[actor.facing];

            if (spriteRenderer.sprite != s)
            {
                spriteRenderer.sprite = s;

                var collider = spriteRenderer.GetComponent <PolygonCollider2D>();
                if (collider != null)
                {
                    Destroy(collider);
                    spriteRenderer.gameObject.AddComponent <PolygonCollider2D>().isTrigger = true;
                }
                frameChanged = true;
                if (currentFrame.flags.HasFlag(FrameFlags.SWAP_FACING))
                {
                    actor.SetFacing(BaseActor.InvertFacing(actor.facing));
                    actor.Move(-actor.movementDirection);
                }
            }

            if (currentFrame.flags.HasFlag(FrameFlags.IGNORE_ACTOR_COLLISIONS))
            {
                if (actor.gameObject.layer == Engine.actorLayer)
                {
                    actor.gameObject.layer = Engine.airborneActorLayer;
                }
            }
            else if (actor.gameObject.layer == Engine.airborneActorLayer)
            {
                actor.gameObject.layer = Engine.actorLayer;
            }

            float frameTime = currentFrame.durationMultiplier / anim.fps;
            float prog      = t / frameTime;

            currentAnimationFrameProgress = prog;
        }