105 lines
3.3 KiB
C#
105 lines
3.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System;
|
|
|
|
/// <summary>
|
|
/// ±¸¼þ¿â
|
|
/// </summary>
|
|
public class SpareLibrary : MonoBehaviour
|
|
{
|
|
public static SpareLibrary instance;
|
|
public GameObject mask;
|
|
public Transform content;
|
|
|
|
private GameObject spareItem;
|
|
public GameObject SpareItem { get { if (spareItem == null) spareItem = Resources.Load<GameObject>("SparePartsModel/Button/SparePartsBtn"); return spareItem; } }
|
|
|
|
private RectTransform maskRect;
|
|
public RectTransform MaskRect { get { if (maskRect == null) maskRect = mask.GetComponent<RectTransform>(); return maskRect; } }
|
|
|
|
List<SparePartsButton> SpareItems = new List<SparePartsButton>();
|
|
private void Awake()
|
|
{
|
|
instance = this;
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))
|
|
{
|
|
if (!RectTransformUtility.RectangleContainsScreenPoint(MaskRect, Input.mousePosition))
|
|
mask.gameObject.SetActive(false);
|
|
}
|
|
|
|
}
|
|
|
|
public void Generate(string _toolName,string _resourcePath, Action<Texture> _call)
|
|
{
|
|
for (int i = 0; i < SpareItems.Count; i++)
|
|
{
|
|
Destroy(SpareItems[i].gameObject);
|
|
}
|
|
SpareItems.Clear();
|
|
|
|
|
|
Sprite[] allSprite = Resources.LoadAll<Sprite>(_resourcePath);
|
|
for (int i = 0; i < allSprite.Length; i++)
|
|
{
|
|
SparePartsButton spareBtn = Instantiate(SpareItem, content).GetComponent<SparePartsButton>();
|
|
spareBtn.Image.sprite = allSprite[i];
|
|
|
|
SpareItems.Add(spareBtn);
|
|
spareBtn.onClick.AddListener(() =>
|
|
{
|
|
//if (SelectionManage.instance)
|
|
//{
|
|
// SelectionManage.instance.SolveIssue(_toolName, spareBtn.Image.mainTexture);
|
|
//}
|
|
|
|
XFrame.Core.UI.XUIPanel.ClosePanel<PackagePanel>();
|
|
mask.gameObject.SetActive(false);
|
|
PreviewWindow.Preveiw(null);
|
|
_call?.Invoke(spareBtn.Image.mainTexture);
|
|
Debug.Log("ÄÃÈ¡¡¾" + _toolName + "¡¿");
|
|
});
|
|
}
|
|
|
|
mask.SetActive(true);
|
|
}
|
|
|
|
public void Generate(string _toolName, string _resourcePath, Action<string> _call)
|
|
{
|
|
for (int i = 0; i < SpareItems.Count; i++)
|
|
{
|
|
Destroy(SpareItems[i].gameObject);
|
|
}
|
|
SpareItems.Clear();
|
|
|
|
|
|
Sprite[] allSprite = Resources.LoadAll<Sprite>(_resourcePath);
|
|
for (int i = 0; i < allSprite.Length; i++)
|
|
{
|
|
SparePartsButton spareBtn = Instantiate(SpareItem, content).GetComponent<SparePartsButton>();
|
|
spareBtn.Image.sprite = allSprite[i];
|
|
|
|
SpareItems.Add(spareBtn);
|
|
spareBtn.onClick.AddListener(() =>
|
|
{
|
|
//if (SelectionManage.instance)
|
|
//{
|
|
// SelectionManage.instance.SolveIssue(_toolName, spareBtn.Image.mainTexture);
|
|
//}
|
|
|
|
XFrame.Core.UI.XUIPanel.ClosePanel<PackagePanel>();
|
|
mask.gameObject.SetActive(false);
|
|
PreviewWindow.Preveiw(null);
|
|
_call?.Invoke(spareBtn.Image.sprite.name);
|
|
Debug.Log("ÄÃÈ¡¡¾" + _toolName + "¡¿");
|
|
});
|
|
}
|
|
|
|
mask.SetActive(true);
|
|
}
|
|
}
|