天津23维预案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.4 KiB

3 years ago
using AX.MessageSystem;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// 战术克隆按钮基类
/// </summary>
public abstract class TacticCloneButtonBase : MonoBehaviour {
public TacticCloneType cloneObjType;//战术克隆类型
public bool selected;//克隆按钮是否选中
public virtual void OnEnable()
{
GetComponent<Button>().onClick.AddListener(CloneButtonClicked);
MessageDispatcher.AddListener("CANCEL_CLONEBTN_SELECTED", CancelSelected);//右键取消按钮选中
}
public virtual void OnDisable()
{
GetComponent<Button>().onClick.RemoveListener(CloneButtonClicked);
MessageDispatcher.RemoveListener("CANCEL_CLONEBTN_SELECTED", CancelSelected);//右键取消按钮选中
}
public virtual void OnDestroy()
{
GetComponent<Button>().onClick.RemoveListener(CloneButtonClicked);
MessageDispatcher.RemoveListener("CANCEL_CLONEBTN_SELECTED", CancelSelected);//右键取消按钮选中
}
private void CloneButtonClicked()
{
ResetOtherCloneBtn();
selected = !selected;
transform.Find("Image").gameObject.SetActive(selected);
//InputManager.Instance_.cloneType = cloneObjType;
if (selected)
{
InputManager.Instance_.cloneType = cloneObjType;
}
else
{
InputManager.Instance_.cloneType = TacticCloneType.None;
}
Clicked();
}
private void CancelSelected(IMessage obj)
{
var info = (bool)obj.Data;
if (selected)
{
Debug.Log("右键取消");
selected = info;
transform.Find("Image").gameObject.SetActive(selected);
InputManager.Instance_.cloneType = TacticCloneType.None;
MessageDispatcher.SendMessage("TACTICSTARTPOINT_RESET");
}
}
private void ResetOtherCloneBtn()
{
foreach (Transform child in transform.parent)
{
if (child.name != transform.name)
{
child.GetComponent<TacticCloneButton>().selected = false;
child.Find("Image").gameObject.SetActive(false);
InputManager.Instance_.cloneType = TacticCloneType.None;
MessageDispatcher.SendMessage("TACTICSTARTPOINT_RESET");
}
}
}
public abstract void Clicked();
}