67 lines
1.7 KiB
C#
67 lines
1.7 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEditor;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
public class figurestate : MonoBehaviour
|
|||
|
{
|
|||
|
public bool isAI;
|
|||
|
public delegate void FigureStateChanged(bool newState, figurestate sender);
|
|||
|
public static event FigureStateChanged OnFigureStateChanged;
|
|||
|
|
|||
|
private Button button; // <20><>ť<EFBFBD><C5A5><EFBFBD><EFBFBD>
|
|||
|
private GameObject image;
|
|||
|
void Start()
|
|||
|
{
|
|||
|
// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Button <20><><EFBFBD><EFBFBD>
|
|||
|
button = GetComponent<Button>();
|
|||
|
image=transform.Find("Image").gameObject;
|
|||
|
//.SetActive(false);
|
|||
|
if (button != null)
|
|||
|
{
|
|||
|
button.onClick.AddListener(OnButtonClicked);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Debug.LogError($"{gameObject.name} <20><>ȱ<EFBFBD><C8B1> Button <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
}
|
|||
|
}
|
|||
|
void Update()
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ط<EFBFBD><D8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ߹<D8B8><DFB9><EFBFBD>
|
|||
|
//if (Input.GetMouseButtonDown(0))
|
|||
|
//{
|
|||
|
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڰ<EFBFBD>ť<EFBFBD>ϣ<EFBFBD><CFA3><EFBFBD><EFBFBD>ظ߹<D8B8><DFB9><EFBFBD>
|
|||
|
// if (!IsMouseOverButton())
|
|||
|
// {
|
|||
|
// ToggleHighlightBar(false);
|
|||
|
// }
|
|||
|
//}
|
|||
|
}
|
|||
|
|
|||
|
// <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˰<EFBFBD>ť
|
|||
|
bool IsMouseOverButton()
|
|||
|
{
|
|||
|
RectTransform rectTransform = button.GetComponent<RectTransform>();
|
|||
|
return rectTransform.rect.Contains(Input.mousePosition);
|
|||
|
}
|
|||
|
// <20><><EFBFBD><EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ
|
|||
|
void OnButtonClicked()
|
|||
|
{
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʾ<EFBFBD>߹<EFBFBD><DFB9><EFBFBD>
|
|||
|
//ToggleHighlightBar(true);
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD>仯
|
|||
|
OnFigureStateChanged?.Invoke(isAI, this);
|
|||
|
|
|||
|
Debug.Log($"{gameObject.name} clicked. isAI = {isAI}");
|
|||
|
}
|
|||
|
// <20>л<EFBFBD><D0BB>߹<EFBFBD><DFB9><EFBFBD><EFBFBD><EFBFBD>ʾ״̬
|
|||
|
void ToggleHighlightBar(bool show)
|
|||
|
{
|
|||
|
image.SetActive(show);
|
|||
|
}
|
|||
|
}
|