Hi!
So, I’m a bit confused… Here is some code:
class SomeClass
{
public SomeType field1;
public SomeType field2;
...
public SomeType fieldN;
}
And another one:
class SomeClass
{
public SomeType field1 { get; set; }
public SomeType field2 { get; private set; }
...
public SomeType fieldN { get; set; }
}
More flexible, isn’t it ?
However I do not like that code for two reasons:
- It is less readable, I think.
- Properties aren’t serializable.
Ok, ok… You can tell that we could make properties to be serializable, for example in a following way:
class SomeClass
{
[serializedField]
private SomeType field1, ... fieldN;
public SomeType Field1
{
get { return field1 };
set { field1 = value};
}
public SomeType Field2
{
get { return field2 };
private set { field2 = value};
}
...
}
So you see how simple code at the beginning became big and less readable… However that code could be more flexible and more safe.
So my question is: is it a good practise to use properties in Game Development with Unity ?
Thank you in advance.