SentimentEffectWidget.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using Core.Language;
  2. using Excel2Json;
  3. using Fort23.UTool;
  4. using UnityEngine;
  5. namespace Fort23.Mono
  6. {
  7. [UIBinding(prefab = "SentimentEffectWidget")]
  8. public partial class SentimentEffectWidget : ItemWidgetBasic
  9. {
  10. public AccountFileInfo.SentimentProperty sentimentProperty;
  11. public SentimentEffectConfig sentimentEffectConfig;
  12. private SentimentEffectWidget lastSentimentWidget;
  13. private void Init()
  14. {
  15. }
  16. public override void AddEvent()
  17. {
  18. }
  19. public override void DelEvent()
  20. {
  21. }
  22. public override void AddButtonEvent()
  23. {
  24. base.AddButtonEvent();
  25. }
  26. public void CustomInit(AccountFileInfo.SentimentProperty sentimentProperty)
  27. {
  28. this.sentimentProperty = sentimentProperty;
  29. int level = sentimentProperty.level <= 0 ? 1 : sentimentProperty.level;
  30. int conFigId = sentimentProperty.groupId * 10 + level;
  31. sentimentEffectConfig = ConfigComponent.Instance.Get<SentimentEffectConfig>(conFigId);
  32. Text_Name.text = LanguageManager.Instance.Text(sentimentEffectConfig.name);
  33. if (sentimentProperty.level == 0)
  34. {
  35. Text_Level.text = "未激活";
  36. }
  37. else
  38. {
  39. Text_Level.text = "lv." + level;
  40. }
  41. }
  42. public async void CreatXian(RectTransform root, SentimentEffectWidget lastSentimentWidget)
  43. {
  44. this.lastSentimentWidget = lastSentimentWidget;
  45. // Vector2 localPointA = root.worldToLocalMatrix * lastSentimentWidget.own.transform.position;
  46. // Vector2 localPointB = root.worldToLocalMatrix * transform.position;
  47. // SentimentXianWidget sentimentXianWidget = await UIManager.Instance.CreateGComponent<SentimentXianWidget>(null, root);
  48. // sentimentXianWidget.own.name = lastSentimentWidget.sentimentEffectConfig.groupId.ToString();
  49. //
  50. //
  51. // sentimentXianWidget.transform.anchoredPosition = localPointB;
  52. // 使用 worldToLocalMatrix 转换世界坐标到 Canvas 本地坐标
  53. Vector2 localPointA = root.worldToLocalMatrix.MultiplyPoint3x4(lastSentimentWidget.own.transform.position);
  54. Vector2 localPointB = root.worldToLocalMatrix.MultiplyPoint3x4(transform.position);
  55. SentimentXianWidget sentimentXianWidget = await UIManager.Instance.CreateGComponent<SentimentXianWidget>(null, root);
  56. sentimentXianWidget.transform.anchoredPosition = root.worldToLocalMatrix * transform.position;
  57. // // 计算 Image 的长度(两点之间的距离)
  58. float distance = Vector2.Distance(localPointA, localPointB);
  59. sentimentXianWidget.transform.sizeDelta = new Vector2(sentimentXianWidget.transform.sizeDelta.x,distance);
  60. //
  61. // // 计算 Image 的旋转角度
  62. Vector2 direction = transform.position - lastSentimentWidget.own.transform.position;
  63. float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
  64. sentimentXianWidget.transform.rotation = Quaternion.Euler(0, 0, angle);
  65. }
  66. }
  67. }