using Core.Language; using Excel2Json; using Fort23.UTool; using UnityEngine; namespace Fort23.Mono { [UIBinding(prefab = "SentimentEffectWidget")] public partial class SentimentEffectWidget : ItemWidgetBasic { public AccountFileInfo.SentimentProperty sentimentProperty; public SentimentEffectConfig sentimentEffectConfig; private SentimentEffectWidget lastSentimentWidget; private void Init() { } public override void AddEvent() { } public override void DelEvent() { } public override void AddButtonEvent() { base.AddButtonEvent(); } public void CustomInit(AccountFileInfo.SentimentProperty sentimentProperty) { this.sentimentProperty = sentimentProperty; int level = sentimentProperty.level <= 0 ? 1 : sentimentProperty.level; int conFigId = sentimentProperty.groupId * 10 + level; sentimentEffectConfig = ConfigComponent.Instance.Get(conFigId); Text_Name.text = LanguageManager.Instance.Text(sentimentEffectConfig.name); if (sentimentProperty.level == 0) { Text_Level.text = "未激活"; } else { Text_Level.text = "lv." + level; } } public async void CreatXian(RectTransform root, SentimentEffectWidget lastSentimentWidget) { this.lastSentimentWidget = lastSentimentWidget; // Vector2 localPointA = root.worldToLocalMatrix * lastSentimentWidget.own.transform.position; // Vector2 localPointB = root.worldToLocalMatrix * transform.position; // SentimentXianWidget sentimentXianWidget = await UIManager.Instance.CreateGComponent(null, root); // sentimentXianWidget.own.name = lastSentimentWidget.sentimentEffectConfig.groupId.ToString(); // // // sentimentXianWidget.transform.anchoredPosition = localPointB; // 使用 worldToLocalMatrix 转换世界坐标到 Canvas 本地坐标 Vector2 localPointA = root.worldToLocalMatrix.MultiplyPoint3x4(lastSentimentWidget.own.transform.position); Vector2 localPointB = root.worldToLocalMatrix.MultiplyPoint3x4(transform.position); SentimentXianWidget sentimentXianWidget = await UIManager.Instance.CreateGComponent(null, root); sentimentXianWidget.transform.anchoredPosition = root.worldToLocalMatrix * transform.position; // // 计算 Image 的长度(两点之间的距离) float distance = Vector2.Distance(localPointA, localPointB); sentimentXianWidget.transform.sizeDelta = new Vector2(sentimentXianWidget.transform.sizeDelta.x,distance); // // // 计算 Image 的旋转角度 Vector2 direction = transform.position - lastSentimentWidget.own.transform.position; float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; sentimentXianWidget.transform.rotation = Quaternion.Euler(0, 0, angle); } } }