Files
back_cantanBuilding/Assets/Scripts/SupplyDrop/Lucky3choose1Panel.cs
2026-05-26 16:15:54 +08:00

62 lines
1.8 KiB
C#

using GameCore;
using UnityEngine;
public class Lucky3choose1Panel : MonoBehaviour
{
SupplyDropGameplayLureCtrl supplyDropGameCtrl;
CanvasGroup canvasGroup;
GameObject text_info;
int layerMask;
Camera ui3d;
bool notClick = true;
private void Awake()
{
layerMask = 1 << LayerMask.NameToLayer("UI3D");
ui3d = UIManager.Instance.UI3DCamera;
canvasGroup = GetComponent<CanvasGroup>();
text_info = transform.Find("root/text_info").gameObject;
canvasGroup.alpha = 0f; // Start with the panel invisible
}
private void Start()
{
ShowPanel();
}
public void Init(SupplyDropGameplayLureCtrl supplyDropGameCtrl)
{
this.supplyDropGameCtrl = supplyDropGameCtrl;
}
void ShowPanel()
{
notClick = false;
canvasGroup.DOFadeAlpha(1f, 0.5f);
}
private void Update()
{
if (notClick)
return;
if (Input.GetMouseButtonUp(0))
{
var ray = ui3d.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out var hit, 100, layerMask))
{
Debug.Log($"<color=#e94242>hit: {hit.collider.gameObject.layer}</color>");
LurecardItem lurecardItem = hit.collider.transform.GetComponentInParent<LurecardItem>();
if (lurecardItem != null)
{
supplyDropGameCtrl.AddPlayerItem(lurecardItem.data);
supplyDropGameCtrl.ShowAllItem(lurecardItem.index);
notClick = true;
text_info.SetActive(false);
}
else
{
Debug.LogWarning("Clicked on an invalid item.");
}
}
}
}
}