Извините за поздний ответ @ Spyros.
Мой подход будет аналогичен подходу @D Manokhin, но вместо использования зубчатого массива я буду использовать многомерный массив (поскольку вы можете создать собственный сценарий редактора для их визуализации, я почти уверен, что вы можете визуализировать зубчатые массивы в редакторе без плагинов, я никогда не использовал плагин Odin).
Итак, я делаю один класс, который будет хранить структуры под названием TileData
:
using UnityEngine;
using System.Collections;
[System.Serializable]
public class TileData
{
/*
* rows
[rowData][rowData][rowData]
[cell] ->value
->type
[cell] ->value
->type
[cell] ->value
->type
*/
[System.Serializable]
public struct cell
{
public float value;
public string type;
}
[System.Serializable]
public struct rowData
{
public cell[] row;
}
public rowData[] rows;
}
Я использовал value
и type
в качестве «примеров», это абсолютно ваше дело, вы также можете сохранить Vector3, если хотите!
Тогда как вызвать и использовать такую структуру? Посмотрим:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Matrix : MonoBehaviour {
//declare the structure that will store the data
public TileData tileData = new TileData();
//those are public so you could make the matrix with the size you want..
//..ideally dynamically call it from your python file requisits
public int horizontalMatrixSize = 10;
public int verticalMatrixSize = 10;
// Use this for initialization
void Start()
{
//Create the matrix structure and fill it
tileData.rows = new TileData.rowData[horizontalMatrixSize];
for (int i = 0; i < tileData.rows.Length; i++)
{
tileData.rows[i].row = new TileData.cell[verticalMatrixSize];
for (int u = 0; u < tileData.rows[i].row.Length; u++)
{
tileData.rows[i].row[u].value = GetValuesFromPythonFileOrWhatever();
tileData.rows[i].row[u].type = GetValuesFromPythonFileOrWhatever();
}
}
}
}
Но если вам действительно нравится зазубренная структура, вы все равно можете использовать ее (но помните, что она не будет отображаться в редакторе) следующим образом:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Matrix : MonoBehaviour {
//declare the structure that will store the data
[SerializeField] private float[,] grayscaleBidimensional = null;
//those are public so you could make the matrix with the size you want..
//..ideally dynamically call it from your python file requisits
public int horizontalMatrixSize = 10;
public int verticalMatrixSize = 10;
// Use this for initialization
void Start()
{
//Create the matrix structure and fill it
tileData.rows = new TileData.rowData[horizontalMatrixSize];
grayscaleBidimensional = new float[horizontalMatrixSize, verticalMatrixSize];
for (int x = 0; x < horizontalMatrixSize; x++)
{
for (int y = 0; y < verticalMatrixSize; y++)
{
grayscaleBidimensional[x, y] = GetValuesFromPythonFileOrWhatever();
}
}
}
}
Помните, что вы можете задавать значения объектов так, как хотите, чтобы им не требовался статический размер!