hch
2025-10-30 dc7922d80c1d133b6261b8af1d521567d2c0a35d
Main/System/Battle/UIComp/BattleHeroInfoBar.cs
@@ -12,6 +12,11 @@
        public string message;
        public bool useArtText;
        public bool followCharacter;
        public float scaleRatio;
        public Color textColor = Color.white;
        public bool showBackground = false;
    }
    protected BattleObject battleObject;
@@ -87,14 +92,20 @@
        }
        tipsList.Clear();
    }
    public void ShowTips(string message, bool useArtText = false, bool followCharacter = false)
    public void ShowTips(string message, bool useArtText = false, bool followCharacter = true, float scaleRatio = 1f)
    {
        messages.Add(new TipsInfo
        {
            message = message,
            useArtText = useArtText,
            followCharacter = followCharacter
            followCharacter = followCharacter,
            scaleRatio = scaleRatio
        });
    }
    public void ShowTips(TipsInfo tipsInfo)
    {
        messages.Add(tipsInfo);
    }
    public void SetActive(bool active)
@@ -102,28 +113,45 @@
        gameObject.SetActive(active);
    }
    public void PopUpTipsDirectly(string message, bool useArtText = false, bool followCharacter = false)
    public void PopUpTipsDirectly(TipsInfo tipsInfo)
    {
        GameObject prefab = textTips.gameObject;
        GameObject go = GameObject.Instantiate(prefab, followCharacter ? transform : battleObject.battleField.battleRootNode.transform);
        GameObject go = GameObject.Instantiate(prefab, tipsInfo.followCharacter ? transform : battleObject.battleField.battleRootNode.transform);
        BattleTips tips = go.GetComponent<BattleTips>();
        if (!followCharacter)
        if (!tipsInfo.followCharacter)
        {
            go.transform.position = prefab.transform.position;
            tips.beginPos = go.transform.localPosition;
            tips.endPos = tips.endPos + new Vector2(go.transform.localPosition.x, go.transform.localPosition.y);
            var contentRect = go.GetComponent<RectTransform>();
            var contentParentRect = contentRect.parent as RectTransform;
            var infoBarRect = GetComponent<RectTransform>();
            Vector3 worldTargetPos = infoBarRect.transform.TransformPoint(infoBarRect.rect.center);
            Vector2 anchoredPos;
            RectTransformUtility.ScreenPointToLocalPointInRectangle(
                contentParentRect,
                RectTransformUtility.WorldToScreenPoint(null, worldTargetPos),
                null,
                out anchoredPos);
            tips.UpdatePositions(anchoredPos, anchoredPos + new Vector2(0, 150));
            // 同时更新缩放
            Vector3 newBeginScale = tips.normalBeginScale * tipsInfo.scaleRatio;
            Vector3 newEndScale = tips.normalEndScale * tipsInfo.scaleRatio;
            tips.UpdateScales(newBeginScale, newEndScale);
        }
        tips.SetSpeedRatio(battleObject.battleField.speedRatio);
        tips.SetRatio(battleObject.battleField.speedRatio, 1f);
        tips.SetText(message, useArtText);
        tips.SetText(tipsInfo.message, tipsInfo.useArtText, false, tipsInfo.textColor);
        tips.ShowBackground(tipsInfo.showBackground);
        tips.OnFinish = () =>
        {
            //  TODO YYL 考虑池化
            tipsList.Remove(tips);
            GameObject.DestroyImmediate(tips.gameObject);
        };
@@ -189,12 +217,20 @@
        if (messages.Count > 0 && timer >= PopUpInterval)
        {
            // 播放飘字
            TipsInfo message = messages[0];
            TipsInfo tipsInfo = messages[0];
            messages.RemoveAt(0);
            PopUpTipsDirectly(message.message, message.useArtText, message.followCharacter);
            PopUpTipsDirectly(tipsInfo);
            timer = 0f;
        }
    }
    public void SetSpeedRatio(float ratio)
    {
        for (int i = 0; i < tipsList.Count; i++)
        {
            tipsList[i].SetRatio(ratio, 1f);
        }
    }
}