コード例 #1
0
 public static void Show(string prefabName, float hitPointDist)
 {
     if (hitPointDist < 6f)
     {
         hitPointDist = Mathf.Clamp(hitPointDist, 1.5f, 6f);
         // 获得距离的比例
         float t = 1f - ((hitPointDist - 1.5f) / 4.5f);
         float x = Mathf.Lerp(0.5f, 1.5f, t) + Random.Range((float)-0.5f, (float)0.5f);
         // 计算位置
         float num3 = ((float)GameMenu.INSTANCE.GetComponent <CanvasScaler>().referenceResolution.x / ((float)Screen.height));
         float num4 = Screen.width * num3;
         float num5 = Screen.height * num3;
         float max  = (num4 * 0.75f) / 3f;
         float num7 = (num5 * 0.75f) / 3f;
         // 实例化
         RectTransform rectTF = Instantiate(PrefabResources.Get(prefabName)) as RectTransform;
         // 放到画布下面
         rectTF.parent = GameMenu.INSTANCE.effectPanelTrans;
         ZombieAttackedBlood attackedBlood = rectTF.GetComponent <ZombieAttackedBlood>();
         // 设置位置,旋转的角度
         rectTF.localPosition = new Vector3(Random.Range(-max, max), Random.Range(-num7, num7), 0);
         attackedBlood.sprite1Trans.localEulerAngles = new Vector3(0f, 0f, Random.Range(0f, 360f));
         attackedBlood.sprite2Trans.localEulerAngles = new Vector3(0f, 0f, Random.Range(0f, 360f));
         rectTF.localScale = new Vector3(0.1f, 0.1f, 0.1f);
         // 开始动画,透明度、尺寸、位置,尺寸根据距离远近变化
         attackedBlood.canvasGroup.DOFade(1f, 0.2f); // 显示
         rectTF.DOScale(new Vector3(x, x, 1f), 0.2f);
         rectTF.DOLocalMoveY((rectTF.localPosition.y - 25f), 1.5f).SetEase(Ease.OutCubic);
         // 可见
         rectTF.gameObject.SetActive(true);
     }
 }
コード例 #2
0
        // 击中僵尸
        protected virtual void ProcessHitZombie()
        {
            string    str           = this.target.tag.ToLower();
            ZombieAbs zombieAbsComp = this.target.transform.root.GetComponent <ZombieAbs>();

            if (zombieAbsComp != null)
            {
                float num = Random.Range(0f, 1f);
                // 僵尸出血,需要位置点产生血
                BloodSequence.Show("Effect/Blood/BloodSplatEffect", this.targetPos);
                // 僵尸的血溅到屏幕上,需要距离判断是否会溅到
                float hitPointDist = Vector3.Distance(this.targetPos, GameCameraController.INSTANCE.MainCameraTrans.position);
                ZombieAttackedBlood.Show("Effect/ZombieAttacked", hitPointDist);
                Vector3 backward     = -zombieAbsComp.transform.forward;
                Vector2 vertBack     = new Vector2(backward.x, backward.y);
                Vector2 normVertBack = vertBack.normalized;
                Vector2 lhs          = new Vector2(-normVertBack.y, normVertBack.x);

                Vector3 targetDir     = this.targetPos - this.originalPos; // 从玩家指向集中目标
                Vector2 vertTargetDir = new Vector2(targetDir.x, targetDir.z);
                Vector2 rhs           = vertTargetDir.normalized;

                Vector2 attackedForce = new Vector2(Vector2.Dot(lhs, rhs), Vector2.Dot(normVertBack, rhs));
                Vector2 zero          = Vector2.zero;
                float   baseDmg       = this.baseDmg;

                if (str.EndsWith("head"))
                {
                    zero = new Vector2(0f, 1f);
                    //baseDmg *= 2f;
                    baseDmg = 100f;
                }
                else if (str.EndsWith("body"))
                {
                    zero             = new Vector2(0f, 0f);
                    attackedForce.y *= 0.7f;
                }
                else if (str.EndsWith("leftarm"))
                {
                    zero             = new Vector2(-1f, 1f);
                    attackedForce.x -= 0.15f;
                    attackedForce   /= 2f;
                }
                else if (str.EndsWith("rightarm"))
                {
                    zero             = new Vector2(1f, 1f);
                    attackedForce.x -= 0.15f;
                    attackedForce   /= 2f;
                }
                else if (str.EndsWith("leftleg"))
                {
                    zero           = new Vector2(-1f, -1f);
                    attackedForce /= 2f;
                }
                else if (str.EndsWith("rightleg"))
                {
                    zero           = new Vector2(1f, -1f);
                    attackedForce /= 2f;
                }
                else if (str.EndsWith("special"))
                {
                    zero           = new Vector2(2f, 0f);
                    attackedForce /= 2f;
                }
                if (((zombieAbsComp.hp <= baseDmg) && (zombieAbsComp.hp > 0f)) && (zombieAbsComp.dangerLevel < 0x3e8))
                {
                    // 计算各种统计信息
                    StgZombieBornDealer.normalKillCount++;
                    if (zero.x == 0 && zero.y == 1)
                    {
                        StgZombieBornDealer.normalHeadshotCount++;
                        AudioManager.INSTANCE.Play("Effect/headshot");
                    }
                }
                attackedForce.y *= this.basePower;
                // attackedForce.y的取值范围为(-∞, -0.3f] && [0.3f, ∞)
                if (attackedForce.y > -0.3f && attackedForce.y < 0.3f)
                {
                    attackedForce.y = (attackedForce.y >= 0f) ? 0.3f : -0.3f;
                }
                zombieAbsComp.Hit(baseDmg, zero, attackedForce, this.basePower);
            }
        }