/// <summary> /// 横向跳动文本动画(用于显示伤害文本动画) /// </summary> /// <param name="hurtString">Hurt string.</param> public void PlayHurtTextAnim(ExploreText et) { // 从缓存池获取文本模型 Text hurtText = exploreTextPool.GetInstance <Text> (exploreTextModel.gameObject, exploreTextContainer); // 伤害文本的原始位置 Vector3 originHurtPos = Vector3.zero; // 伤害文本的第一次跳动终点 Vector3 firstHurtPos = Vector3.zero; // 伤害文本的第二次跳动终点 Vector3 secondHurtPos = Vector3.zero; // 提示文本的原始位置【伤害可能附带暴击,闪避等提示文字】 Vector3 originTintPos = Vector3.zero; // 提示文本的终点位置【伤害可能附带暴击,闪避等提示文字】 Vector3 finalTintPos = Vector3.zero; // 下面设置文本的动画路径 switch (et.towards) { case MyTowards.Left: case MyTowards.Up: originHurtPos = et.basePosition + new Vector3(-50f, 50f, 0); firstHurtPos = originHurtPos + new Vector3(-Random.Range(80, 100), Random.Range(0, 10), 0); secondHurtPos = firstHurtPos + new Vector3(-Random.Range(20, 30), Random.Range(0, 2), 0); originTintPos = originHurtPos + new Vector3(-100f, 100f, 0); break; case MyTowards.Right: case MyTowards.Down: originHurtPos = et.basePosition + new Vector3(50f, 50f, 0); firstHurtPos = originHurtPos + new Vector3(Random.Range(80, 100), Random.Range(0, 10), 0); secondHurtPos = firstHurtPos + new Vector3(Random.Range(20, 30), Random.Range(0, 2), 0); originTintPos = originHurtPos + new Vector3(100f, 100f, 0); break; } hurtText.transform.localPosition = originHurtPos; hurtText.text = et.text; hurtText.GetComponentInChildren <Image>().enabled = false; hurtText.gameObject.SetActive(true); float firstJumpPower = Random.Range(100f, 120f); // 伤害文本跳跃动画 hurtText.transform.DOLocalJump(firstHurtPos, firstJumpPower, 1, 0.4f).OnComplete(() => { float secondJumpPower = Random.Range(20f, 30f); // 伤害文本二次跳跃 hurtText.transform.DOLocalJump(secondHurtPos, secondJumpPower, 1, 0.15f).OnComplete(() => { hurtText.text = ""; hurtText.gameObject.SetActive(false); exploreTextPool.AddInstanceToPool(hurtText.gameObject); }); }); }
/// <summary> /// 添加纵向屏幕文字到显示队列中 /// </summary> /// <param name="exploreText">Explore text.</param> public void AddHintText(ExploreText exploreText) { exploreText.indexInList = hintTextList.Count; hintTextList.Add(exploreText); IEnumerator showNewHintTextCoroutine = ShowANewTintText(exploreText); StartCoroutine(showNewHintTextCoroutine); }
/// <summary> /// 添加纵向提示文字动画到队列 /// </summary> /// <param name="text">Text.</param> public void AddTintTextToQueue(string text) { // 角色的世界位置转化为在画布中的位置 Vector3 basePosition = MyTool.ToPointInCanvas(transform.position); // 根据分辨率不同调整屏幕位置 basePosition = new Vector3(basePosition.x * CommonData.scalerToPresetHW, basePosition.y, 0); // 生成探索文本 ExploreText ft = new ExploreText(text, MyTowards.Left, basePosition); // 将探索文本加入提示文本队列 agentUICtr.exploreTextManager.AddHintText(ft); }
/// <summary> /// 纵向提示文本动画(用于显示血量提升,特殊攻击结果(暴击,闪避),其他屏幕提示) /// </summary> /// <param name="tintStr">Tint string.</param> /// <param name="originPos">Origin position.</param> private void PlayTintTextAnim(ExploreText et) { Text tintText = exploreTextPool.GetInstance <Text> (exploreTextModel.gameObject, exploreTextContainer); tintText.transform.localPosition = et.basePosition + new Vector3(0, 260, 0); tintText.text = string.Format("<size=35>{0}</size>", et.text); tintText.gameObject.SetActive(true); // 提示文本做一次缩放 tintText.transform.DOScale(new Vector3(1.2f, 1.2f, 1f), 0.3f).OnComplete(() => { tintText.text = ""; tintText.transform.localScale = Vector3.one; tintText.gameObject.SetActive(false); exploreTextPool.AddInstanceToPool(tintText.gameObject); }); }
private IEnumerator ShowANewHurtText(ExploreText exploreText) { // 如果 exploreText 不在显示队列的队首,则一直等待 while (exploreText.indexInList > 0) { yield return(null); } // exploreText现在在显示队列的队首,则等待显示间隔事件后显示 yield return(new WaitForSeconds(hurtTextInterval)); PlayHurtTextAnim(exploreText); // 将exploreText从显示队列中移除 hurtTextList.RemoveAt(0); // 显示队列中的其他 exploreText 在队列中整体左移(由于exploreText的队列序号是在exploreText内部存储,所以需要手动移动整个队列中的exploreText) for (int i = 0; i < hurtTextList.Count; i++) { hurtTextList [i].indexInList--; } }