12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- 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<SentimentEffectConfig>(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<SentimentXianWidget>(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<SentimentXianWidget>(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);
- }
- }
- }
|