PictureComponent.cs 3.4 KB

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