64 lines
1.4 KiBLFS
C#
64 lines
1.4 KiBLFS
C#
|
|
|
|
using UnityEngine;
|
|
|
|
public class ClickableZoom : MonoBehaviour
|
|
{
|
|
|
|
[SerializeField] public Texture fullImage;
|
|
|
|
private SpriteRenderer spriteRenderer;
|
|
|
|
[SerializeField] private float zoomDuration = 0.5f;
|
|
[SerializeField] private float maxZoom = 2f;
|
|
|
|
|
|
[SerializeField] private bool hovering = false;
|
|
|
|
[SerializeField] private bool horizontal = true;
|
|
public bool Horizontal => horizontal;
|
|
|
|
public string text;
|
|
void Start()
|
|
{
|
|
spriteRenderer = GetComponent<SpriteRenderer>();
|
|
}
|
|
|
|
public void OnMouseDown()
|
|
{
|
|
if (fullImage != null)
|
|
{
|
|
CanvasManager.singleton.objectZoomPanel.gameObject.SetActive(true);
|
|
CanvasManager.singleton.objectZoomPanel.SetImage(this);
|
|
GameManager.singleton.soundManager.PlayClickSound();
|
|
Cursor.visible = false;
|
|
}
|
|
}
|
|
|
|
public void OnMouseEnter()
|
|
{
|
|
hovering = true;
|
|
}
|
|
|
|
public void OnMouseExit()
|
|
{
|
|
hovering = false;
|
|
CanvasManager.singleton.objectZoomPanel.gameObject.SetActive(false);
|
|
Cursor.visible = true;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
float zoom = transform.localScale.x;
|
|
if (hovering)
|
|
{
|
|
zoom = Mathf.Lerp(zoom, maxZoom, Time.deltaTime / zoomDuration);
|
|
}
|
|
else
|
|
{
|
|
zoom = Mathf.Lerp(zoom, 1, Time.deltaTime / zoomDuration);
|
|
}
|
|
spriteRenderer.sortingOrder = Mathf.RoundToInt(zoom * 100);
|
|
transform.localScale = new Vector3(zoom, zoom, 1);
|
|
}
|
|
} |