HeavenStudioPlus/Assets/Scripts/LevelEditor/EventSelector/GridGameSelectorGame.cs

90 lines
2.6 KiB
C#
Raw Normal View History

2022-01-11 00:17:29 +00:00
using UnityEngine;
using UnityEngine.Rendering;
2022-01-11 00:17:29 +00:00
using UnityEngine.UI;
using UnityEngine.EventSystems;
2022-01-11 00:17:29 +00:00
using DG.Tweening;
2022-03-14 14:21:05 +00:00
namespace HeavenStudio.Editor
2022-01-11 00:17:29 +00:00
{
public class GridGameSelectorGame : MonoBehaviour
{
public GameObject GameTitlePreview;
public Animator StarAnim;
public bool StarActive;
2022-01-11 00:17:29 +00:00
public GridGameSelector GridGameSelector;
public Texture MaskTex;
public Texture BgTex;
private Material m_Material;
private void Start()
2022-01-11 00:17:29 +00:00
{
Tooltip.AddTooltip(this.gameObject, EventCaller.instance.GetMinigame(this.gameObject.name).displayName);
}
private void OnEnable()
{
if (StarActive) StarAnim.Play("Appear", 0, 1);
2022-01-11 00:17:29 +00:00
}
public void SetupTextures()
{
if (m_Material == null)
{
m_Material = Instantiate(GetComponent<Image>().material);
GetComponent<Image>().material = m_Material;
}
m_Material.SetTexture("_MaskTex", MaskTex);
m_Material.SetTexture("_BgTex", BgTex);
}
public void OnClick()
2022-01-11 00:17:29 +00:00
{
if (Input.GetMouseButtonUp(0))
{
GridGameSelector.SelectGame(this.gameObject.name);
}
}
public void OnDown()
{
if (Input.GetMouseButtonDown(1))
{
// while holding shift and the game icon clicked has a star, it will disable all stars.
if (Input.GetKey(KeyCode.LeftShift)) {
if (!StarActive) return;
for (int i = 0; i < transform.parent.childCount; i++)
{
var ggsg = transform.parent.GetChild(i).GetComponent<GridGameSelectorGame>();
if (ggsg.StarActive) ggsg.Star();
}
} else {
Star();
}
}
}
public void Star()
{
StarAnim.CrossFade(StarActive ? "Disappear" : "Appear", 0.3f);
StarActive = !StarActive;
2022-01-11 00:17:29 +00:00
}
//TODO: animate between shapes
public void ClickIcon()
{
transform.DOScale(new Vector3(1.15f, 1.15f, 1f), 0.1f);
BgTex = Resources.Load<Texture>($"Sprites/GeneralPurpose/Circle");
SetupTextures();
}
public void UnClickIcon()
{
transform.DOScale(new Vector3(1f, 1f, 1f), 0.1f);
BgTex = Resources.Load<Texture>($"Sprites/GeneralPurpose/Square");
SetupTextures();
}
2022-01-11 00:17:29 +00:00
}
}