Debug.Log();
Expects either string
or an object
(the base class of everything in c#) as parameter. If you pass in an object
the Debug.Log
internally will automatically convert it to a string
using the ToString
method of that object
.
The question is what should be logged here?
Ofcourse you could define that "ad-hoc" within the Debug.Log
like e.g.
public void SomeClassDebug(Result_Splash result)
{
Debug.Log(result.id);
}
so you will see the result of result.id.ToString()
as log.
In my eyes the better way is in your classes implement/override ToString
in order to customize the output it will generate according to your needs. (I'm lazy so I'll show it for the smaller class - the other one is your homework)
public class Result_Splash
{
public string id;
public string version_code;
public string version_number;
public override string ToString()
{
// For example print the values as requested
return $"id: {id}, version_code: {version_code}, version_number: {version_number}";
}
}
I used a $
string interpolation which is basically a better way of writing e.g.
return base.ToString() + " id: " + id + ", version_code: " + version_code + ", version_number: " + version_number;
but you can use whatever you want to return the values.
Now you can simply do
public void SomeClassDebug(Result_Splash result)
{
Debug.Log(result);
}
And when you call it then pass in an instance of that type
var aResult = new Result_Splash()
{
id = "Hello",
version_code = " ",
version_number = "World!"
};
SomeClassDebug(aResult);
this should generate a log
id: Hello, version_code = , version_number = World!