コード例 #1
0
        private void _Execute(AbstractPerson self)
        {
            //临时数据
            var mainc = self.obj.GetComponent <MainCharacter>();
            //面对方向
            var position = self.obj.transform.position;
            var p        = new Vector2(position.x, position.y);
            var target   = new Vector2(this.dir.x * self.Dir, this.dir.y) * this.len * self.Scanler;

            //调整身高偏移
            p += new Vector2(0, 0.1f * self.obj.transform.localScale.y);
            Debug.DrawLine(p, p + target, Color.red);
            var rescult = Physics2D.LinecastAll(p, p + target, this.layer);

            if (rescult.Length == 0)
            {
                return;
            }


            foreach (var r in rescult)
            {
                //对打击到的目标进行操作,添加各种效果
                var hitPerson = AbstractPerson.GetInstance(r.transform.gameObject);
                if (hitPerson == null)
                {
                    Debug.Log(r.transform.gameObject);
                    continue;
                }


                self.OnCauseDamage(GameMath.Damage(self.Attack));
                hitPerson.TakeBattleEffect(self.AttackEffect);


                //                hitPerson.TakeBattleEffect(new LockFrame());
            }
        }
コード例 #2
0
        public void RunTriggerUnit(AbstractPerson self)
        {
            if (!enable)
            {
                return;
            }
            this.self = self;
            MainLoop.Instance.ExecuteLater(() =>
            {
//                Debug.Log("运行Trigger单元:" + this.type);
                switch (type)
                {
                    #region Effect

                case TriggerType.Effect:
                    Debug.Log("技能系统——TriggerType.Effect");
                    self.PlayAttackEffects(attackEffects);
                    break;

                    #endregion

                    #region Animation

                case TriggerType.Animation:
                    if (self == null)
                    {
                        throw new Exception("SkillCore为空");
                    }

                    var animator = GameAnimator.GetInstance(self.obj.GetComponent <Animator>());

                    if (animator == null)
                    {
                        throw new Exception(self.CharacterName + "没有Animator组件");
                    }

                    animator.speed = this.animationSpeed * self.AttackSpeed;


                    animator.Play(Animator.StringToHash(this.animationName.StringValue), AnimationWeight.High);


                    break;


                    #endregion

                    #region Audio

                case TriggerType.Audio:
                    if (self.obj != null)
                    {
                        AudioMgr.Instance.PlayEffect(this.audioName.Path, self.obj.transform.position);
                    }
                    break;

                    #endregion

                    #region Bullet

                case TriggerType.Bullet:
                    this.dir = new Vector2(self.Dir * Mathf.Abs(this.dir.x), this.dir.y);
                    new DirectLineBullet(GameMath.Damage(self.BaseAttack), this.dir, self.Pos + new Vector3(0, 0.3f * self.Scanler, 0)
                                         , self, this.bulletName.Path, speed: this.bulletSpeed, maxLife: this.maxLife);
                    break;

                    #endregion

                    #region Parabloa


                case TriggerType.Parabloa:
                    switch (targetType)
                    {
                    case TargetType.Vector3Offset:
                        new ParabloaBullet(this.damage, this.bulletSpeed, this.timeToTarget, self.Pos + offset,
                                           self.Pos, self, this.bulletName.Path, this.maxLife);
                        break;

                    case TargetType.GetFromCache:
//                                Debug.Log($"SkillAsset【{skillAsset.skillName.StringValue}】.Vector3Cache:"+skillAsset.Vector3Cache);
                        new ParabloaBullet(this.damage, this.bulletSpeed, this.timeToTarget, skillAsset.Vector3Cache,
                                           self.Pos, self, this.bulletName.Path, this.maxLife);
                        break;
                    }

                    break;

                    #endregion

                    #region RayDamage

                case TriggerType.RayDamage:
                    //面对方向
                    var position = self.obj.transform.position;
                    var p        = new Vector2(position.x, position.y);

                    var target = this.rayLength * self.Scanler * new Vector2(this.dir.x * self.Dir, this.dir.y);

                    //调整身高偏移
                    p += new Vector2(0, 0.1f * self.obj.transform.localScale.y);
                    Debug.DrawLine(p, p + target, Color.red);
                    var results = Physics2D.LinecastAll(p, p + target, this.rayTestLayer);

                    if (results.Length == 0)
                    {
                        return;
                    }

                    foreach (var result in results)
                    {
                        //对打击到的目标进行操作,添加各种效果
                        var hitPerson = AbstractPerson.GetInstance(result.transform.gameObject);
                        if (hitPerson == null)
                        {
                            Debug.Log(result.transform.gameObject);
                            continue;
                        }
                        self.OnCauseDamage(GameMath.Damage(self.BaseAttack));
                        hitPerson.PlayAcceptEffects(self);
                    }
                    break;

                    #endregion

                    #region Trigger2D

                case TriggerType.Trigger2D:
                    if (Mathf.Abs(preLastTime) < 0.01f)
                    {
                        preLastTime = lastTime;
                    }
                    lastTime /= self.AttackSpeed;
                    if (self.obj == null)
                    {
                        break;
                    }
                    var sword   = self.obj.transform.Find(triggerPath);
                    var trigger = (sword.GetComponent <TriggerInputer>() ??
                                   sword.gameObject.AddComponent <TriggerInputer>());

                    trigger.onTriggerEnterEvent += this.OnTriggerEnter;
//                        Debug.Log("添加监听");
                    MainLoop.Instance.ExecuteLater(() =>
                    {
//                            Debug.Log("移除监听");
                        trigger.onTriggerEnterEvent -= this.OnTriggerEnter;
                    }, lastTime);

                    break;

                    #endregion
                }
            }, this.startTime);
        }