Пример #1
0
        private void AddDashTele()
        {
            ParticleSystem.MainModule main = _trail.main;
            var psr = _trail.GetComponent<ParticleSystemRenderer>();

            bool tele = false;

            IEnumerator TeleOut()
            {
                tele = false;

                // After Tele can transition here if the Tele fails so I want to reset the trail regardless.
                if (main.startColor.color == Color.black)
                {
                    psr.material.shader = Shader.Find("Legacy Shaders/Particles/Additive");
                    main.startColor = Color.white;
                    _trail.Play();
                }

                if (_hm.hp > HP * 2 / 3) yield break;
                if (_rand.Next(0, 2) == 0) yield break;

                tele = true;

                psr.material.shader = Shader.Find("Legacy Shaders/Particles/Multiply");
                main.startColor = Color.black;

                yield return new WaitForSeconds(.20f);

                _anim.Stop();

                _trail.Pause();

                _control.SetState("Tele Out Dash");
            }

            _control.CreateState("Dash Wall");

            // ReSharper disable once ImplicitlyCapturedClosure
            void ConditionalEvent()
            {
                if (tele)
                {
                    _control.SetState("Tele Out Dash");
                }
            }

            FsmState dashWall = _control.GetState("Dash Wall");
            FsmState dash = _control.GetState("Dash");

            dashWall.AddMethod(ConditionalEvent);

            _control.ChangeTransition("Dash", "WALL", "Dash Wall");

            dashWall.AddTransition(FsmEvent.Finished, "Dash Recover");

            dash.AddCoroutine(TeleOut);

            _control.CopyState("Tele Out", "Tele Out Dash");
            _control.CopyState("TelePos Slash", "TelePos DashOut");
            _control.CopyState("Tele In", "Tele In Dash");
            
            dash.AddTransition("TELE", "Tele Out Dash");
            
            var dashCont = _control.CreateState("Dash Continue");
            
            _control.ChangeTransition("Tele Out Dash", "FINISHED", "TelePos DashOut");
            _control.ChangeTransition("TelePos DashOut", "FINISHED", "Tele In Dash");
            _control.ChangeTransition("Tele In Dash", "FINISHED", "Dash Continue");

            _control.GetAction<SetStringValue>("TelePos DashOut").stringValue = "DASH";

            IEnumerator ResumeDash()
            {
                psr.material.shader = Shader.Find("Legacy Shaders/Particles/Additive");
                main.startColor = Color.white;

                _trail.Play();

                Vector3 scale = transform.localScale;

                scale.x =
                (
                    Math.Abs(transform.localScale.x) *
                    Math.Sign(HeroController.instance.transform.position.x - transform.position.x)
                );
                
                transform.localScale = scale;

                gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(60 * Math.Sign(transform.localScale.x), 0);

                _anim.Play("Dash");

                yield return new WaitForSeconds(.15f);

                _anim.Stop();
            }

            dashCont.InsertCoroutine(0, ResumeDash);

            dashCont.AddTransition(FsmEvent.Finished, "Dash Recover");
        }