示例#1
0
    // Start is called before the first frame update
    void Start()
    {
        this.boidImpl = this.gameObject.GetComponent <BoidsImpl>();

        DisolveSpriteAnimation animation = this.GetComponent <DisolveSpriteAnimation>();

        this.initialColor = animation.GetColor();
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        switch (this.state)
        {
        case State.Leaf:
        {
            if (this.boidImpl.hasLeader)
            {
                this.currentFramesWithLeader++;
            }
            else
            {
                this.currentFramesWithLeader--;
                if (this.currentFramesWithLeader < 0)
                {
                    this.currentFramesWithLeader = 0;
                }
            }

            float ratio = (float)this.currentFramesWithLeader / (float)this.framesToFlower;

            DisolveSpriteAnimation animation = this.GetComponent <DisolveSpriteAnimation>();
            Color color     = animation.GetColor();
            float baseAlpha = color.a;
            color   = this.initialColor + (this.sublimateColor - this.initialColor) * ratio;
            color.a = baseAlpha;
            animation.SetColor(color);


            if (this.currentFramesWithLeader >= this.framesToFlower)
            {
                this.state = State.Sublimating;
                AudioSource audioSource = this.GetComponent <AudioSource>();
                audioSource.pitch = Random.Range(0.8f, 1.0f);
                audioSource.Play();
            }
            break;
        }

        case State.Sublimating:
        {
            if (this.currentFramesSublimating >= this.sublimateFrames)
            {
                this.state = State.Leaving;
                if (this.gameController != null)
                {
                    this.gameController.OnLeafLeaving(this);
                }
                break;
            }
            DisolveSpriteAnimation animation = this.GetComponent <DisolveSpriteAnimation>();
            animation.animate = false;
            animation.SetAlpha(((float)this.currentFramesSublimating / (float)this.sublimateFrames));

            this.currentFramesSublimating++;
            break;
        }

        case State.Leaving: break;
        }
    }