You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.7 KiB
91 lines
2.7 KiB
using UnityEngine; |
|
using UnityEngine.UI; |
|
namespace AX.ImageViewer |
|
{ |
|
public class ImageViewer : MonoBehaviour |
|
{ |
|
#region Static Variables |
|
private static ImageViewer m_instance = null; |
|
public static ImageViewer Instance |
|
{ |
|
get |
|
{ |
|
if (m_instance == null) |
|
{ |
|
m_instance = Instantiate(Resources.Load<GameObject>("ImageViewerCanvas")).GetComponent<ImageViewer>(); |
|
DontDestroyOnLoad(m_instance.gameObject); |
|
m_instance.gameObject.SetActive(false); |
|
} |
|
|
|
return m_instance; |
|
} |
|
} |
|
#endregion |
|
|
|
#region Variables |
|
[SerializeField] |
|
private Image ImagePanel; |
|
[SerializeField] |
|
private GameObject ScaleSlider; |
|
public int minWidth = 380; |
|
public int minHeight = 300; |
|
|
|
#endregion |
|
|
|
#region Button Events |
|
//Rotate |
|
public void OnRotate() |
|
{ |
|
ImagePanel.rectTransform.localEulerAngles = new Vector3(ImagePanel.rectTransform.localEulerAngles.x, ImagePanel.rectTransform.localEulerAngles.y, ImagePanel.rectTransform.localEulerAngles.z + -90f); |
|
} |
|
public void OnSacelButton() |
|
{ |
|
if (ScaleSlider.activeSelf) |
|
ScaleSlider.SetActive(false); |
|
else |
|
ScaleSlider.SetActive(true); |
|
} |
|
//Scale |
|
public void OnScale(Slider slider) |
|
{ |
|
ImagePanel.rectTransform.localScale = new Vector3(slider.value, slider.value, slider.value); |
|
} |
|
//Resize |
|
public void OnResize() |
|
{ |
|
ImagePanel.rectTransform.localEulerAngles = new Vector3(0, 0, 0); |
|
ScaleSlider.GetComponent<Slider>().value = 1; |
|
//ImagePanel.rectTransform.localScale = new Vector3(1, 1, 1); |
|
ImagePanel.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, 0); |
|
} |
|
//Close |
|
public void OnCloseButtonClicked() |
|
{ |
|
Hide(); |
|
} |
|
#endregion |
|
#region Helper Functions |
|
public void Show() |
|
{ |
|
gameObject.SetActive(true); |
|
} |
|
public void Hide() |
|
{ |
|
gameObject.SetActive(false); |
|
} |
|
#endregion |
|
|
|
/// <summary> |
|
/// 查看图片 |
|
/// </summary> |
|
/// <param name="ImagePath"></param> |
|
public static void Load(Texture2D texture) |
|
{ |
|
Instance.Show(); |
|
Instance.ImagePanel.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero); |
|
Instance.ImagePanel.preserveAspect = false; |
|
} |
|
} |
|
|
|
} |
|
|
|
|