我有一个函数,它在某个位置查找"瓷砖",将其添加到列表中,然后将该列表返回到另一个列表。但是,当游戏运行时,检查器中不会显示任何列表项,即使当我使用调试或DebugiderLog时,它也会显示列表包含正确的"瓷砖"。
下面是我的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PieceController : MonoBehaviour
{
[Header("Location managing")]
public Tile currentTile;
public Vector3 currentTilePos;
[Header("Move making")]
public Piece pieceType;
public List<Tile> validTiles = new List<Tile>();
private TileSelector tileSelector;
// Start is called before the first frame update
void Start()
{
tileSelector = GameObject.Find("GameController").GetComponent<TileSelector>();
}
// Update is called once per frame
void Update()
{
currentTilePos = currentTile.GetComponent<Tile>().positionTop;
validTiles = CalculateValidTiles();
Debug.Log("Valid tiles: " + validTiles.ToString());
}
public List<Tile> CalculateValidTiles()
{
float tileLength = pieceType.tileLength;
List<Tile> tiles = new List<Tile>();
foreach (LegalMove move in pieceType.moves)
{
//Debug.Log("Calculating move: " + move.name);
Vector3 legalPosition;
Vector3 originPosition = transform.position;
legalPosition = new Vector3(originPosition.x + move.tilesPositiveX, originPosition.y, originPosition.z + move.tilesPositiveZ);
//Debug.Log("Legal position: " + legalPosition.ToString());
Ray ray = new Ray(legalPosition, Vector3.down);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 1.5f))
{
Debug.Log("Hit: " + hit.collider.gameObject.name);
if (hit.collider.gameObject.tag == "piece" && !validTiles.Contains(hit.collider.gameObject.GetComponent<Tile>()))
{
tiles.Add(hit.collider.gameObject.GetComponent<Tile>());
//Debug.Log("Added tile: " + hit.collider.gameObject.GetComponent<Tile>().tile);
}
}
}
Debug.Log("Tiles calculated: " + tiles.ToString());
return tiles;
}
}
我想不通为什么它不会显示检查器中的项目,我试过将我的编辑器版本更新到2021.3.14f1,并直接将项目添加到"validTiles"列表中,而不是使用return。
1条答案
按热度按时间9jyewag01#
将
[System.Serializable]
属性添加到Tile
类,指示它可以是Unity的serialized