SentimentEffectWidget.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System.Collections.Generic;
  2. using Core.Language;
  3. using Excel2Json;
  4. using Fort23.UTool;
  5. using UnityEngine;
  6. namespace Fort23.Mono
  7. {
  8. [UIBinding(prefab = "SentimentEffectWidget")]
  9. public partial class SentimentEffectWidget : ItemWidgetBasic
  10. {
  11. public AccountFileInfo.SentimentProperty sentimentProperty;
  12. public SentimentEffectConfig sentimentEffectConfig;
  13. public SentimentEffectWidget lastSentimentWidget;
  14. List<SentimentXianWidget> _sentimentXianWidgets = new List<SentimentXianWidget>();
  15. private void Init()
  16. {
  17. }
  18. public override void AddEvent()
  19. {
  20. }
  21. public override void DelEvent()
  22. {
  23. }
  24. public override void AddButtonEvent()
  25. {
  26. base.AddButtonEvent();
  27. }
  28. public void CustomInit(AccountFileInfo.SentimentProperty sentimentProperty)
  29. {
  30. this.sentimentProperty = sentimentProperty;
  31. int level = sentimentProperty.level <= 0 ? 1 : sentimentProperty.level;
  32. int conFigId = sentimentProperty.groupId * 10 + level;
  33. sentimentEffectConfig = ConfigComponent.Instance.Get<SentimentEffectConfig>(conFigId);
  34. Text_Name.text = LanguageManager.Instance.Text(sentimentEffectConfig.name);
  35. if (sentimentProperty.level == 0)
  36. {
  37. Text_Level.text = "未激活";
  38. }
  39. else
  40. {
  41. Text_Level.text = "lv." + level;
  42. }
  43. }
  44. public async void CreatXian(RectTransform root, SentimentEffectWidget lastSentimentWidget)
  45. {
  46. this.lastSentimentWidget = lastSentimentWidget;
  47. SentimentXianWidget sentimentXianWidget = await UIManager.Instance.CreateGComponent<SentimentXianWidget>(null, root);
  48. _sentimentXianWidgets.Add(sentimentXianWidget);
  49. var lineRect = sentimentXianWidget.transform;
  50. Vector2 localPointA = root.worldToLocalMatrix.MultiplyPoint3x4(lastSentimentWidget.own.transform.position);
  51. Vector2 localPointB = root.worldToLocalMatrix.MultiplyPoint3x4(this.transform.position);
  52. lineRect.anchoredPosition = localPointB;
  53. // 计算长度
  54. float distance = Vector2.Distance(localPointA, localPointB);
  55. lineRect.sizeDelta = new Vector2(lineRect.sizeDelta.x, distance);
  56. //计算角度
  57. Vector2 direction = localPointB - localPointA;
  58. Quaternion q = Quaternion.identity;
  59. q.SetFromToRotation(Vector3.up, direction);
  60. lineRect.eulerAngles = new Vector3(q.eulerAngles.x, 0, q.eulerAngles.z);
  61. UpdateXian();
  62. }
  63. public void UpdateXian()
  64. {
  65. if (lastSentimentWidget.sentimentProperty.level >= sentimentEffectConfig.unlockLevel)
  66. {
  67. foreach (var sentimentXianWidget in _sentimentXianWidgets)
  68. {
  69. sentimentXianWidget.own.transform.RecoverColor();
  70. }
  71. }
  72. else
  73. {
  74. foreach (var sentimentXianWidget in _sentimentXianWidgets)
  75. {
  76. sentimentXianWidget.own.transform.Gray();
  77. }
  78. }
  79. }
  80. }
  81. }