c# - 在 Unity 中堆叠图像
问题描述
我有 4 个按钮,每个按钮都会激活一个图像(请参阅链接 - 堆叠)。一个脚本附加到所有 4 个按钮。有 4 个占位符。我正在使用一种堆栈的方法来一个接一个地堆叠图像。也就是说,如果第一个插槽是空的,则图像会放在那里。该按钮有两个功能,添加图像和删除图像。如果删除了第一个插槽的图像,则将第二个插槽的图像放置在第一个插槽上,并将第三个插槽的图像放置在第二个插槽上。如何在这种情况下添加推送和弹出?
编辑:我尝试使用 List 但我迷路了。有没有更简单的方法?
public class ActivateStackImages : MonoBehaviour {
public GameObject ImageGameObject_To_Add; //Each instance of this script has unique image
public Vector3[] PositionOfImages; //4 positions
private ActivateStackImages [] activateImages; //Script added to 4 buttons
public bool Slot_1_Filled = false;
public bool Slot_2_Filled = false;
public bool Slot_3_Filled = false;
public bool Slot_4_Filled = false;
public bool isImageAdded = false;
private void Awake () {
activateImages= FindObjectsOfType (typeof (ActivateStackImages )) as ActivateStackImages [];
}
public void ActivateGraph () {
if (this.isImageAdded == false) {
for (int i = 0; i < activateImages.Length; i++) {
if (activateImages[i].Slot_1_Filled == false) {
ImageGameObject_To_Add.SetActive (true);
ImageGameObject_To_Add.GetComponent<RectTransform> ().anchoredPosition = PositionOfImages[0];
activateImages[i].Slot_1_Filled = true;
} else if (activateImages[i].Slot_2_Filled == false) {
ImageGameObject_To_Add.SetActive (true);
ImageGameObject_To_Add.GetComponent<RectTransform> ().anchoredPosition = PositionOfImages[2];
activateImages[i].Slot_2_Filled = true;
} else if (activateImages[i].Slot_3_Filled == false) {
ImageGameObject_To_Add.SetActive (true);
ImageGameObject_To_Add.GetComponent<RectTransform> ().anchoredPosition = PositionOfImages[2];
activateImages[i].Slot_3_Filled = true;
} else if (activateImages[i].Slot_4_Filled == false) {
ImageGameObject_To_Add.SetActive (true);
ImageGameObject_To_Add.GetComponent<RectTransform> ().anchoredPosition = PositionOfImages[3];
activateImages[i].Slot_4_Filled = true;
}
}
this.isImageAdded = true;
} else if (this.isImageAdded == true) {
ImageGameObject_To_Add.SetActive (false);
}
}
}
解决方案
推荐阅读
- database - 试图了解一致性哈希如何在数据库服务器上更好地工作
- amazon-web-services - 当我在公共子网中有 ELB 和 NAT 网关将流量分配到我的私有子网中的三个节点时,数据包如何流动?
- powershell - 安全帐户管理器属性
- java - Spring Boot 上的本机查询:混合?不支持参数和其他形式,如 ?1
- php - 在codeigniter中合并两个std类对象
- python - 如何在 Python 2.7 中使用 raw_input 捕获 EOFError 的值?
- c# - SSIS包如何根据查询有选择地导入CSV行
- vtk - 如何为特定的 vtkCells 着色?
- android - 如何正确“setMutableVisiblity”?
- xamarin.android - 如何在 ListView 中显示 ArticleResults