SentimentEffectWidget.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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.Where(se => se.groupId == sentimentEffectConfig.groupId).ToList();
  38. if (sentimentProperty.level == 0)
  39. {
  40. Text_Level.text = "未激活";
  41. }
  42. else
  43. {
  44. Text_Level.text = level + "/" + currentGroupSentimentEffectConfigs.Count;
  45. }
  46. }
  47. public async void CreatXian(RectTransform root, SentimentEffectWidget lastSentimentWidget)
  48. {
  49. this.lastSentimentWidget = lastSentimentWidget;
  50. SentimentXianWidget sentimentXianWidget = await UIManager.Instance.CreateGComponent<SentimentXianWidget>(null, root);
  51. _sentimentXianWidgets.Add(sentimentXianWidget);
  52. var lineRect = sentimentXianWidget.transform;
  53. Vector2 localPointA = root.worldToLocalMatrix.MultiplyPoint3x4(lastSentimentWidget.own.transform.position);
  54. Vector2 localPointB = root.worldToLocalMatrix.MultiplyPoint3x4(this.transform.position);
  55. lineRect.anchoredPosition = localPointB;
  56. // 计算长度
  57. float distance = Vector2.Distance(localPointA, localPointB);
  58. lineRect.sizeDelta = new Vector2(lineRect.sizeDelta.x, distance);
  59. //计算角度
  60. Vector2 direction = localPointB - localPointA;
  61. Quaternion q = Quaternion.identity;
  62. q.SetFromToRotation(Vector3.up, direction);
  63. lineRect.eulerAngles = new Vector3(q.eulerAngles.x, 0, q.eulerAngles.z);
  64. UpdateXian();
  65. }
  66. public void UpdateXian()
  67. {
  68. if (lastSentimentWidget.sentimentProperty.level >= sentimentEffectConfig.unlockLevel)
  69. {
  70. foreach (var sentimentXianWidget in _sentimentXianWidgets)
  71. {
  72. sentimentXianWidget.own.transform.RecoverColor();
  73. }
  74. }
  75. else
  76. {
  77. foreach (var sentimentXianWidget in _sentimentXianWidgets)
  78. {
  79. sentimentXianWidget.own.transform.Gray();
  80. }
  81. }
  82. }
  83. public override void DormancyObj()
  84. {
  85. foreach (var sentimentXianWidget in _sentimentXianWidgets)
  86. {
  87. UIManager.Instance.DormancyGComponent(sentimentXianWidget);
  88. }
  89. _sentimentXianWidgets.Clear();
  90. base.DormancyObj();
  91. }
  92. }
  93. }