123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using XRTool.Util;
- public class PrintscreenItem : MonoBehaviour
- {
- public RawImage mainImage;
- public Text nameText;
- public RectTransform rectTransform;
- public SCButton deleteBtn;
- private void Start()
- {
- deleteBtn.onClick.AddListener(ClickOnDeleteBtn);
- }
- private void ClickOnDeleteBtn()
- {
- Destroy(this.gameObject);
- }
- private BoundingBox boundBox;
- public void Init(Texture2D tex)
- {
- if (tex)
- {
- Adaption(tex);
- mainImage.texture = tex;
- }
- if (!boundBox)
- {
- boundBox = GetComponent<BoundingBox>();
- if (!boundBox)
- {
- UnityLog.LogError(gameObject.name + "this is no XBoundingBox");
- }
- else
- {
- boundBox.ScaleStopped.AddListener(OnScaleStopped);
- }
- }
- }
- private void OnScaleStopped()
- {
- if (transform.localScale.x < 1f)
- {
- transform.localScale = Vector3.one;
- }
- }
- public void Adaption(Texture tex)
- {
- float standard_width = 150f;
- float standard_height = 84f;
- float video_width = tex.width;
- float video_height = tex.height;
- //Debug.Log(tex.width + "***" + tex.height);
- if (standard_width < video_width && standard_height > video_height)
- {
- float video_aspect = standard_width / video_width;
- rectTransform.sizeDelta = new Vector2(standard_width, video_height * video_aspect);
- }
- else if (standard_width > video_width && standard_height < video_height)
- {
- float video_aspect = standard_height / video_height;
- rectTransform.sizeDelta = new Vector2(video_width * video_aspect, standard_height);
- }
- else if (standard_width > video_width && standard_height > video_height)
- {
- if (standard_width / video_width > standard_height / video_height)
- {
- float video_aspect = standard_height / video_height;
- rectTransform.sizeDelta = new Vector2(video_width * video_aspect, video_height * video_aspect);
- }
- else
- {
- float video_aspect = standard_width / video_width;
- rectTransform.sizeDelta = new Vector2(video_width * video_aspect, video_height * video_aspect);
- }
- }
- else
- {
- if (standard_width / video_width > standard_height / video_height)
- {
- float video_aspect = standard_height / video_height;
- rectTransform.sizeDelta = new Vector2(video_width * video_aspect, video_height * video_aspect);
- }
- else
- {
- float video_aspect = standard_width / video_width;
- rectTransform.sizeDelta = new Vector2(video_width * video_aspect, video_height * video_aspect);
- }
- }
- }
- }
|