Beispiel #1
0
        private void OnTriggerEnter(Collider2D col)
        {
            var hitPerson = col.gameObject.GetPersonInfo() as IHighFivePerson;

            if (hitPerson == null)
            {
//                Debug.Log("打击人物为空");
                return;
            }
//            else
//            {
//                Debug.Log("打击到”" + hitPerson.CharacterName);
//            }

            switch (damageType)
            {
            case DamageType.PlayerToEnemy:
                if (hitPerson is IHighFiveCharacter)
                {
                    break;
                }
                self.TryAttackSimple(hitPerson);
                break;

            case DamageType.EnemyToPlayer:
                if (hitPerson is IHighFiveCharacter)
                {
                    self.TryAttackSimple(hitPerson);
                }

                break;
            }
        }
Beispiel #2
0
        public void RunTriggerUnit(IHighFivePerson 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.gameObject.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.gameObject != null)
                    {
                        AudioMgr.Instance.PlayEffect(this.audioName.StringValue, self.gameObject.transform.position);
                    }
                    break;

                    #endregion

                    #region Bullet

                case TriggerType.Bullet:
                    var d = new Vector2(self.Dir * Mathf.Abs(this.dir.x), this.dir.y);
                    new DirectLineBullet(GameMath.Damage(self.Attack), d, self.position + new Vector3(0, 1, 0)
                                         , self, this.bulletName.StringValue, 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.position + offset,
                                           self.position, self, this.bulletName.StringValue, 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.position, self, this.bulletName.StringValue, this.maxLife);
                        break;
                    }

                    break;

                    #endregion

                    #region RayDamage

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

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

                    //调整身高偏移
                    p += new Vector2(0, 0.1f * self.gameObject.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 = result.transform.gameObject.GetPersonInfo() as IHighFivePerson;
                        if (hitPerson == null)
                        {
                            Debug.Log(result.transform.gameObject);
                            continue;
                        }
                        self.TryAttackSimple(hitPerson);
                    }
                    break;

                    #endregion

                    #region Trigger2D

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

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

                    break;

                    #endregion
                }
            }, this.startTime);
        }