SentimentEffectWidget.cs 3.9 KB

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