The list I want to return is a list of objects of the following class:
public class LightObject : MonoBehaviour
{
public string lightType { get; set; }
public string lightNumber { get; set; }
public bool lightOn { get; set; }
public long? lightHue { get; set; }
public long lightBri { get; set; }
}
I want to get all the elements of the following list:
LightObject[] lightsObjects = new LightObject[jsonTotalLights];
This list is generated in this method:
public string GenerateLightsObjects()
{
// Obtención del JSON pidiendo la variable jsonlights al Lightipscript
GameObject a = GameObject.Find("Main Camera");
LightsIpScript b = a.GetComponent<LightsIpScript>();
// Obtenemos el JSON
jsonLights = b.jsonLights;
// Obtenemos la CANTIDAD de elementos del JSON
jsonTotalLights = b.jsonTotalOfLights;
// Se almacena en un diccionario los objetos del JSON
var dataDeserialized = JsonConvert.DeserializeObject<Dictionary<string, Light>>(jsonLights);
// Almacenar el nombre de todas las bombillas
ReadAndGetNameOfParentsFromJson(jsonLights);
// Generar objetos de las luces
LightObject[] lightsObjects = new LightObject[jsonTotalLights];
for (int i = 0; i < jsonTotalLights; i++)
{
string bombillaActual = listOfParents[i];
lightsObjects[i] = new LightObject() {
lightType = dataDeserialized[bombillaActual].Type,
lightOn = dataDeserialized[bombillaActual].State.On,
lightNumber = bombillaActual,
lightHue = dataDeserialized[bombillaActual].State.Hue,
lightBri = dataDeserialized[bombillaActual].State.Bri
};
}
// SACAR POR CONSOLA LA LISTA DE BOMBILLAS
for (int i = 0; i < jsonTotalLights; i++)
{
Debug.Log("-- BOMBILLA: "+lightsObjects[i].lightNumber);
Debug.Log("-- TIPO DE BOMBILLA: " + lightsObjects[i].lightType);
Debug.Log("-- COLOR DE BOMBILLA: " + lightsObjects[i].lightHue);
Debug.Log("-- BRILLO DE BOMBILLA: " + lightsObjects[i].lightBri);
Debug.Log("-- ESTADO DE BOMBILLA: " + lightsObjects[i].lightOn);
Debug.Log("valor de la I: "+i);
}
return jsonLights;
}
Currently it returns a string and the method is created to return that, but I have tried different modifications and I can't find how to return all of them. I have been able to return only 1, but I need to get the whole list to use in other methods. Thank you very much for the help.
You must set your method to return an array[] and return the same object that you filled.