PictureComponent.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using BeinLab.Util;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using XRTool.Util;
  6. using XRTool.WorldUI;
  7. namespace ShadowStudio.Model
  8. {
  9. /// <summary>
  10. /// 图片组件
  11. /// </summary>
  12. public class PictureComponent : UIComponent
  13. {
  14. private XRIcon xrIcon;
  15. /// <summary>
  16. /// 图片
  17. /// </summary>
  18. public XRIcon XrIcon
  19. {
  20. get
  21. {
  22. if (!xrIcon)
  23. {
  24. xrIcon = GetComponent<XRIcon>();
  25. }
  26. return xrIcon;
  27. }
  28. }
  29. /// <summary>
  30. /// 设置组件
  31. /// </summary>
  32. /// <param name="artContainer"></param>
  33. /// <param name="art"></param>
  34. /// <param name="info"></param>
  35. public override void SetContainer(ArtContainerHandler artContainer, UnityEngine.Object art, ArtInfo info)
  36. {
  37. base.SetContainer(artContainer, art, info);
  38. print(art);
  39. if (art is Texture2D || art is Sprite||art is Texture)
  40. {
  41. Sprite sprite = null;
  42. if (art is Sprite)
  43. {
  44. sprite = art as Sprite;
  45. }
  46. Texture2D img = art as Texture2D;
  47. Vector2 size = Vector2.zero;
  48. if (img)
  49. {
  50. size.x = img.width;
  51. size.y = img.height;
  52. }
  53. if (sprite)
  54. {
  55. size.x = sprite.texture.width;
  56. size.y = sprite.texture.height;
  57. }
  58. while (size.magnitude > 2000)
  59. {
  60. size /= 2;
  61. }
  62. while (size.magnitude < 100)
  63. {
  64. size *= 2;
  65. }
  66. if (DlgContainer && DlgContainer.Dlg)
  67. {
  68. DlgContainer.Dlg.DlgTrans.sizeDelta = size;
  69. DlgContainer.Dlg.SetScale(size, 1);
  70. if (DlgContainer.Transfer && DlgContainer.Transfer.IsInit)
  71. {
  72. DlgContainer.Transfer.RemoveBound();
  73. //DlgContainer.Transfer.RemoveBound();
  74. TimerMgr.Instance.CreateTimer(() => { DlgContainer.Transfer.IsDragEnable = false; }, 0);
  75. }
  76. //TimerMgr.Instance.CreateTimer(() =>
  77. //{
  78. // DlgContainer.Transfer.RemoveBound();
  79. //}, 0);
  80. //TimerMgr.Instance.CreateTimer(() =>
  81. //{
  82. // DlgContainer.Transfer.IsDragEnable = false;
  83. //}, 0.01f);
  84. //DlgContainer.Transfer.RemoveBound();
  85. //TimerMgr.Instance.CreateTimer(() => { DlgContainer.Transfer.IsDragEnable = false; }, 0.01f);
  86. }
  87. if (XrIcon)
  88. {
  89. XrIcon.rectTransform.offsetMax = Vector2.zero;
  90. XrIcon.rectTransform.offsetMin = Vector2.zero;
  91. if (sprite)
  92. {
  93. XrIcon.AutoSetSprite(sprite);
  94. }
  95. else if (img)
  96. {
  97. XrIcon.AutoSetSprite(img);
  98. }
  99. }
  100. }
  101. }
  102. }
  103. }