| New file |
| | |
| | | using DG.Tweening;
|
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.Text;
|
| | | using UnityEngine;
|
| | |
|
| | | //战斗力增加
|
| | | public class PowerAddWin : UIBase
|
| | | {
|
| | | [SerializeField] TextEx txtBase; //提升或降低前的战斗力
|
| | | [SerializeField] TextEx txtChange; //战斗力变化了多少
|
| | | [SerializeField] ImageEx imgArrow; //箭头
|
| | | [SerializeField] Transform transZhanLi; //战力整体框
|
| | | [SerializeField] Transform transZhanLiNumAll; //战力所有变化部分
|
| | | [SerializeField] RectTransform transChange; //箭头和变化数字整体框
|
| | | string uiFrameKey = "zhanli_dt";
|
| | | [SerializeField] UIFrame uiFrame;
|
| | | [SerializeField] List<PowerUpPosition> powerUpPositions;
|
| | |
|
| | | [Header("淡入变大")]
|
| | | [SerializeField] Vector3 startVector; //起始大小
|
| | |
|
| | | [SerializeField] float fadeInToBigDuration; //淡入变大动画完成时间
|
| | | [SerializeField] Ease fadeInToBigEaseType;
|
| | | [SerializeField] Vector3 fadeInToBigVector; //淡入变大目标大小
|
| | |
|
| | | [Header("淡入变小")]
|
| | | [SerializeField] Vector3 fadeInToSmallVector; //淡入变小目标大小
|
| | |
|
| | | [SerializeField] float fadeInToSmallDuration; //淡入变小动画完成时间
|
| | | [SerializeField] Ease fadeInToSmallEaseType;
|
| | |
|
| | | [Header("淡入后移动开始前等待时间/s")]
|
| | | [SerializeField] float moveStartWaitTime;
|
| | |
|
| | | [Header("变化值移动")]
|
| | | [SerializeField] float moveDuration; //变化值移动动画完成时间
|
| | |
|
| | | [SerializeField] Ease moveEaseType;
|
| | |
|
| | | [Header("变化值透明度降到0")]
|
| | | [SerializeField] float textFadeDuration; //变化值透明度降到0的时间
|
| | |
|
| | | [SerializeField] Ease textFadeEaseType;
|
| | |
|
| | | [Header("数字滚动")]
|
| | | [SerializeField] float rollDuration; //数字滚动动画完成时间
|
| | |
|
| | | [SerializeField] float rollCount; //数字滚动次数
|
| | | [SerializeField] Ease rollEaseType;
|
| | |
|
| | | [Header("移动结束后淡出开始前等待时间/s")]
|
| | | [SerializeField] float moveEndWaitTime;
|
| | |
|
| | | [Header("淡出变大")]
|
| | | [SerializeField] Vector3 fadeOutToBigVector; //淡出变大目标大小
|
| | |
|
| | | [SerializeField] float fadeOutToBigDuration; //淡出变大动画完成时间
|
| | | [SerializeField] Ease fadeOutToBigEaseType;
|
| | |
|
| | | [Header("淡出变小")]
|
| | | [SerializeField] float fadeOutToSmallDuration; //淡出变小动画完成时间
|
| | |
|
| | | [SerializeField] Ease fadeOutToSmallEaseType;
|
| | |
|
| | | [Header("战力数字位置计算相关")]
|
| | | [SerializeField] float txtBaseMultiple; //前置的战力数字字母距离倍数
|
| | |
|
| | | [SerializeField] float txtChangeMultiple; //后置的战力数字字母距离倍数
|
| | | [SerializeField] int baseFontWidth; //前置的战力数字字母一个多大
|
| | | [SerializeField] int changeFontWidth; //后置的战力数字字母一个多大
|
| | | [SerializeField] float baseAndChangeInterval; //前置和后置的战力数字中间的间隔大小
|
| | | [SerializeField] float changeAndArrowInterval; //后置的战力数字和箭头之间的间隔大小
|
| | | [SerializeField] float transChangeY; //Change组件的Y值
|
| | | [SerializeField] float intArrowAddInterval; //增加或减少值是整数时,后置的战力数字和箭头之间的间隔增加多少
|
| | | private float fadeInEndTime; // 播完淡入动画后的时间
|
| | | private float moveEndTime; // 播完移动动画后的时间
|
| | | long basePower;
|
| | | long nowPower;
|
| | | long changePower;
|
| | | bool isAdd;
|
| | |
|
| | | private enum AnimeState
|
| | | {
|
| | | FadeIn,
|
| | | WaitMove,
|
| | | Move,
|
| | | WaitFadeOut,
|
| | | FadeOut,
|
| | | }
|
| | |
|
| | | AnimeState nowState;
|
| | |
|
| | | #region Built-in
|
| | |
|
| | |
|
| | | protected override void OnPreOpen()
|
| | | {
|
| | | PlayerMainDate.Instance.AddPowerEvent += ResetToWaitMove;
|
| | | ResetToFadeIn();
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | | protected override void OnPreClose()
|
| | | {
|
| | | PlayerMainDate.Instance.AddPowerEvent -= ResetToWaitMove;
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | | #endregion
|
| | |
|
| | | Sequence sequence;
|
| | | Sequence textChangeSequence;
|
| | | Sequence fadeOutSequence;
|
| | |
|
| | | protected void LateUpdate()
|
| | | {
|
| | | if (nowState == AnimeState.WaitMove)
|
| | | {
|
| | | if (Time.time - fadeInEndTime > moveStartWaitTime)
|
| | | {
|
| | | nowState = AnimeState.Move;
|
| | |
|
| | | sequence = DOTween.Sequence();
|
| | | sequence.Join(transChange.DOMove(new Vector3(txtBase.rectTransform.position.x, transChange.position.y, transChange.position.z) , moveDuration).SetEase(moveEaseType));
|
| | | sequence.Join(txtChange.DOFade(0f, textFadeDuration).SetEase(textFadeEaseType));
|
| | | sequence.Join(imgArrow.DOFade(0f, textFadeDuration).SetEase(textFadeEaseType));
|
| | |
|
| | | textChangeSequence = DOTween.Sequence();
|
| | | float rollTime = rollDuration / rollCount;
|
| | | for (int i = 0; i < rollCount + 1; i++)
|
| | | {
|
| | | long changeValue = changePower / (int)rollCount * (i + 1);
|
| | | long nowValue;
|
| | | if (i == rollCount)
|
| | | {
|
| | | nowValue = nowPower;
|
| | | sequence.Append(txtBase.DOText(DisplayBasePowerNum(nowValue), rollTime).SetEase(rollEaseType).OnComplete(() => { SetInitPosition(nowValue, changePower, isAdd); }));
|
| | | }
|
| | | else
|
| | | {
|
| | | if (isAdd)
|
| | | {
|
| | | nowValue = basePower + changeValue;
|
| | | sequence.Append(txtBase.DOText(DisplayBasePowerNum(nowValue), rollTime).SetEase(rollEaseType).OnComplete(() => { SetInitPosition(nowValue, changePower, isAdd); }));
|
| | | }
|
| | | else
|
| | | {
|
| | | nowValue = basePower - changeValue;
|
| | | sequence.Append(txtBase.DOText(DisplayBasePowerNum(nowValue), rollTime).SetEase(rollEaseType).OnComplete(() => { SetInitPosition(nowValue, changePower, isAdd); }));
|
| | | }
|
| | | }
|
| | | #if UNITY_EDITOR
|
| | | Debug.Log($"count {i} changeValue {changeValue} nowValue {nowValue} isAdd {isAdd} basePower {basePower} changePower {changePower} nowPower {nowPower} rollTime {rollTime}");
|
| | | #endif
|
| | | }
|
| | | sequence.Join(textChangeSequence);
|
| | |
|
| | | sequence.OnComplete(() =>
|
| | | {
|
| | | moveEndTime = Time.time;
|
| | | nowState = AnimeState.WaitFadeOut;
|
| | | });
|
| | | }
|
| | | }
|
| | | else if (nowState == AnimeState.WaitFadeOut)
|
| | | {
|
| | | if (Time.time - moveEndTime > moveEndWaitTime)
|
| | | {
|
| | | nowState = AnimeState.FadeOut;
|
| | | fadeOutSequence = DOTween.Sequence();
|
| | | fadeOutSequence.Append(transZhanLi.DOScale(fadeOutToBigVector, fadeOutToBigDuration).SetEase(fadeOutToBigEaseType));
|
| | | fadeOutSequence.Append(transZhanLi.DOScale(startVector, fadeOutToSmallDuration).SetEase(fadeOutToSmallEaseType).OnComplete(CloseWindow));
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | private void ResetToFadeIn()
|
| | | {
|
| | | sequence.Kill();
|
| | | textChangeSequence.Kill();
|
| | | fadeOutSequence.Kill();
|
| | | uiFrame.SetActive(false);
|
| | | fadeInEndTime = 0;
|
| | | moveEndTime = 0;
|
| | | transZhanLi.transform.localScale = startVector;
|
| | | CheckPosition();
|
| | | SetNum();
|
| | | SetInitPosition(basePower, changePower, isAdd);
|
| | | ResetColorA();
|
| | | DisplayNum();
|
| | | nowState = AnimeState.FadeIn;
|
| | | transZhanLi.DOScale(fadeInToBigVector, fadeInToBigDuration).SetEase(fadeInToBigEaseType).OnComplete(() =>
|
| | | {
|
| | | transZhanLi.DOScale(fadeInToSmallVector, fadeInToSmallDuration).SetEase(fadeInToSmallEaseType).OnComplete(() =>
|
| | | {
|
| | | fadeInEndTime = Time.time;
|
| | | nowState = AnimeState.WaitMove;
|
| | |
|
| | | uiFrame.SetActive(true);
|
| | | uiFrame.SetLoopCount(1);
|
| | | uiFrame.ResetFrame(uiFrameKey);
|
| | | });
|
| | | });
|
| | | }
|
| | |
|
| | | private void ResetToWaitMove()
|
| | | {
|
| | | sequence.Kill();
|
| | | textChangeSequence.Kill();
|
| | | fadeOutSequence.Kill();
|
| | | uiFrame.SetActive(false);
|
| | | fadeInEndTime = Time.time;
|
| | | moveEndTime = 0;
|
| | | transZhanLi.transform.localScale = fadeInToSmallVector;
|
| | | SetNum();
|
| | | SetInitPosition(basePower, changePower, isAdd);
|
| | | ResetColorA();
|
| | | DisplayNum();
|
| | |
|
| | | uiFrame.SetActive(true);
|
| | | uiFrame.SetLoopCount(1);
|
| | | uiFrame.ResetFrame(uiFrameKey);
|
| | | nowState = AnimeState.WaitMove;
|
| | | }
|
| | |
|
| | | private void SetInitPosition(long basePower, long changePower, bool isAdd)
|
| | | {
|
| | | txtBase.rectTransform.anchorMin = new Vector2(0, 0);
|
| | | txtBase.rectTransform.anchorMax = new Vector2(0, 0);
|
| | | txtBase.rectTransform.pivot = new Vector2(0, 0);
|
| | | txtBase.rectTransform.anchoredPosition = new Vector2(0, 0);
|
| | |
|
| | | transChange.anchorMin = new Vector2(0, 0);
|
| | | transChange.anchorMax = new Vector2(0, 0);
|
| | | transChange.pivot = new Vector2(0, 0);
|
| | | string displayBasePowerNum = DisplayBasePowerNum(basePower);
|
| | | int txtBaseTransWidth = GetBaseTransWidth(displayBasePowerNum);
|
| | | float x = txtBaseTransWidth * txtBaseMultiple + baseAndChangeInterval;
|
| | | transChange.anchoredPosition = new Vector2(x, transChangeY);
|
| | |
|
| | | txtChange.rectTransform.anchorMin = new Vector2(0, 0);
|
| | | txtChange.rectTransform.anchorMax = new Vector2(0, 0);
|
| | | txtChange.rectTransform.pivot = new Vector2(0, 0);
|
| | | txtChange.rectTransform.anchoredPosition = new Vector2(0, 0);
|
| | |
|
| | | imgArrow.rectTransform.anchorMin = new Vector2(0, 0);
|
| | | imgArrow.rectTransform.anchorMax = new Vector2(0, 0);
|
| | | imgArrow.rectTransform.pivot = new Vector2(0, 0);
|
| | | string displayChangePowerNum = DisplayChangePowerNum(isAdd, changePower);
|
| | | int txtChangeTransWidth = GetChangeTransWidth(displayChangePowerNum);
|
| | | x = txtChangeTransWidth * txtChangeMultiple + changeAndArrowInterval;
|
| | | if (!IsHasPoint(changePower))
|
| | | {
|
| | | x += intArrowAddInterval;
|
| | | }
|
| | | imgArrow.rectTransform.anchoredPosition = new Vector2(x, 0);
|
| | | }
|
| | |
|
| | | private bool IsHasPoint(long changePower) |
| | | {
|
| | | var chars = UIHelper.ReplaceLargeArtNum(changePower);
|
| | | for (int i = 0; i < chars.Length; i++)
|
| | | {
|
| | | if (chars[i] == '.')
|
| | | {
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | private int GetBaseTransWidth(string numStr)
|
| | | {
|
| | | return Mathf.CeilToInt(numStr.Length * baseFontWidth);
|
| | | }
|
| | |
|
| | | private int GetChangeTransWidth(string numStr)
|
| | | {
|
| | | return Mathf.CeilToInt(numStr.Length * changeFontWidth);
|
| | | }
|
| | |
|
| | | private void SetNum()
|
| | | {
|
| | | nowPower = (long)PlayerMainDate.Instance.prowNum;
|
| | | changePower = (long)PlayerMainDate.Instance.prowNumChange;
|
| | | isAdd = PlayerMainDate.Instance.isAdd;
|
| | | basePower = isAdd ? nowPower - changePower : nowPower + changePower;
|
| | | }
|
| | |
|
| | | private void DisplayNum()
|
| | | {
|
| | | txtBase.text = DisplayBasePowerNum(basePower);
|
| | | txtChange.text = DisplayChangePowerNum(isAdd, changePower);
|
| | | imgArrow.SetSprite(DisplayState(isAdd));
|
| | | }
|
| | |
|
| | | private string DisplayState(bool isAdd)
|
| | | {
|
| | | return StringUtility.Contact(isAdd ? "FightPointUP" : "FightPointDown");
|
| | | }
|
| | |
|
| | | private string DisplayBasePowerNum(long basePower)
|
| | | {
|
| | | StringBuilder stringBuild = new StringBuilder();
|
| | | stringBuild.Append(basePower);
|
| | | return stringBuild.ToString();
|
| | | }
|
| | |
|
| | | private string DisplayChangePowerNum(bool isAdd, long changePower)
|
| | | {
|
| | | var chars = UIHelper.ReplaceLargeArtNum(changePower);
|
| | |
|
| | | StringBuilder stringBuild = new StringBuilder();
|
| | | if (isAdd)
|
| | | {
|
| | | stringBuild.Append("+");
|
| | | }
|
| | | else
|
| | | {
|
| | | stringBuild.Append("-");
|
| | | }
|
| | | stringBuild.Append(chars);
|
| | | return stringBuild.ToString();
|
| | | }
|
| | |
|
| | | |
| | |
|
| | | private void ResetColorA()
|
| | | {
|
| | | Color textColor = txtChange.color;
|
| | | textColor.a = 1f;
|
| | | txtChange.color = textColor;
|
| | | textColor = imgArrow.color;
|
| | | textColor.a = 1f;
|
| | | imgArrow.color = textColor;
|
| | | }
|
| | |
|
| | | private void CheckPosition()
|
| | | {
|
| | | var type = WindowType.None;
|
| | |
|
| | | var _index = powerUpPositions.FindIndex((x) =>
|
| | | {
|
| | | return x.windowType == type;
|
| | | });
|
| | | if (_index != -1)
|
| | | {
|
| | | transZhanLi.transform.localPosition = powerUpPositions[_index].position;
|
| | | }
|
| | | }
|
| | |
|
| | | [Serializable]
|
| | | public struct PowerUpPosition
|
| | | {
|
| | | public WindowType windowType;
|
| | | public Vector3 position;
|
| | | }
|
| | |
|
| | | public enum WindowType
|
| | | {
|
| | | None,
|
| | | }
|
| | | } |