123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using XRTool.Util;
- using XRTool.WorldUI;
- namespace ShadowStudio.Model
- {
- /// <summary>
- /// 图片组件
- /// </summary>
- public class PictureComponent : UIComponent
- {
- private XRIcon xrIcon;
- /// <summary>
- /// 图片
- /// </summary>
- public XRIcon XrIcon
- {
- get
- {
- if (!xrIcon)
- {
- xrIcon = GetComponent<XRIcon>();
- }
- return xrIcon;
- }
- }
- /// <summary>
- /// 设置组件
- /// </summary>
- /// <param name="artContainer"></param>
- /// <param name="art"></param>
- /// <param name="info"></param>
- public override void SetContainer(ArtContainerHandler artContainer, UnityEngine.Object art, ArtInfo info)
- {
- base.SetContainer(artContainer, art, info);
- print(art);
- if (art is Texture2D || art is Sprite||art is Texture)
- {
- Sprite sprite = null;
- if (art is Sprite)
- {
- sprite = art as Sprite;
- }
- Texture2D img = art as Texture2D;
- Vector2 size = Vector2.zero;
- if (img)
- {
- size.x = img.width;
- size.y = img.height;
- }
- if (sprite)
- {
- size.x = sprite.texture.width;
- size.y = sprite.texture.height;
- }
- while (size.magnitude > 2000)
- {
- size /= 2;
- }
- while (size.magnitude < 100)
- {
- size *= 2;
- }
- if (DlgContainer && DlgContainer.Dlg)
- {
- DlgContainer.Dlg.DlgTrans.sizeDelta = size;
- DlgContainer.Dlg.SetScale(size, 1);
- if (DlgContainer.Transfer && DlgContainer.Transfer.IsInit)
- {
- DlgContainer.Transfer.RemoveBound();
- //DlgContainer.Transfer.RemoveBound();
- TimerMgr.Instance.CreateTimer(() => { DlgContainer.Transfer.IsDragEnable = false; }, 0);
- }
- //TimerMgr.Instance.CreateTimer(() =>
- //{
- // DlgContainer.Transfer.RemoveBound();
- //}, 0);
- //TimerMgr.Instance.CreateTimer(() =>
- //{
- // DlgContainer.Transfer.IsDragEnable = false;
- //}, 0.01f);
- //DlgContainer.Transfer.RemoveBound();
- //TimerMgr.Instance.CreateTimer(() => { DlgContainer.Transfer.IsDragEnable = false; }, 0.01f);
- }
- if (XrIcon)
- {
- XrIcon.rectTransform.offsetMax = Vector2.zero;
- XrIcon.rectTransform.offsetMin = Vector2.zero;
- if (sprite)
- {
- XrIcon.AutoSetSprite(sprite);
- }
- else if (img)
- {
- XrIcon.AutoSetSprite(img);
- }
- }
- }
- }
- }
- }
|