using System.Collections.Generic; 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; public SentimentEffectWidget lastSentimentWidget; List _sentimentXianWidgets = new List(); 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; SentimentXianWidget sentimentXianWidget = await UIManager.Instance.CreateGComponent(null, root); _sentimentXianWidgets.Add(sentimentXianWidget); var lineRect = sentimentXianWidget.transform; Vector2 localPointA = root.worldToLocalMatrix.MultiplyPoint3x4(lastSentimentWidget.own.transform.position); Vector2 localPointB = root.worldToLocalMatrix.MultiplyPoint3x4(this.transform.position); lineRect.anchoredPosition = localPointB; // 计算长度 float distance = Vector2.Distance(localPointA, localPointB); lineRect.sizeDelta = new Vector2(lineRect.sizeDelta.x, distance); //计算角度 Vector2 direction = localPointB - localPointA; Quaternion q = Quaternion.identity; q.SetFromToRotation(Vector3.up, direction); lineRect.eulerAngles = new Vector3(q.eulerAngles.x, 0, q.eulerAngles.z); UpdateXian(); } public void UpdateXian() { if (lastSentimentWidget.sentimentProperty.level >= sentimentEffectConfig.unlockLevel) { foreach (var sentimentXianWidget in _sentimentXianWidgets) { sentimentXianWidget.own.transform.RecoverColor(); } } else { foreach (var sentimentXianWidget in _sentimentXianWidgets) { sentimentXianWidget.own.transform.Gray(); } } } } }