###Vector2Direction
and DirectionVector2
Vector2Direction
and DirectionVector2
You should consider to rename this methods to ToDirection()
and ToVector2()
. In this way it is more clear what the methods are doing, ideally this methods would live in a Convert
class. Initializing for each method a dictionary would be the way to go IMO.
Assume you have done this and named this dictionary vectorsDictionary
then your former Vector2Direction()
method would look like so
public static Direction ToDirection(Vector2 vector)
{
Direction direction;
if (vectorsDictionary.TryGetValue(vector.normalized, out direction))
{
return direction;
}
throw new ArgumentException("Argument must be a vector along an axis.", "vector");
}
In the same way you can do it for DirectionVector2
and this would be also possible for the updateSprite()
method.
###Vector2Direction
and DirectionVector2
You should consider to rename this methods to ToDirection()
and ToVector2()
. In this way it is more clear what the methods are doing, ideally this methods would live in a Convert
class. Initializing for each method a dictionary would be the way to go IMO.
Assume you have done this and named this dictionary vectorsDictionary
then your former Vector2Direction()
method would look like so
public static Direction ToDirection(Vector2 vector)
{
Direction direction;
if (vectorsDictionary.TryGetValue(vector.normalized, out direction))
{
return direction;
}
throw new ArgumentException("Argument must be a vector along an axis.", "vector");
}
In the same way you can do it for DirectionVector2
and this would be also possible for the updateSprite()
method.
Vector2Direction
and DirectionVector2
You should consider to rename this methods to ToDirection()
and ToVector2()
. In this way it is more clear what the methods are doing, ideally this methods would live in a Convert
class. Initializing for each method a dictionary would be the way to go IMO.
Assume you have done this and named this dictionary vectorsDictionary
then your former Vector2Direction()
method would look like so
public static Direction ToDirection(Vector2 vector)
{
Direction direction;
if (vectorsDictionary.TryGetValue(vector.normalized, out direction))
{
return direction;
}
throw new ArgumentException("Argument must be a vector along an axis.", "vector");
}
In the same way you can do it for DirectionVector2
and this would be also possible for the updateSprite()
method.
###Vector2Direction
and DirectionVector2
You should consider to rename this methods to ToDirection()
and ToVector2()
. In this way it is more clear what the methods are doing, ideally this methods would live in a Convert
class. Initializing for each method a dictionary would be the way to go IMO.
Assume you have done this and named this dictionary vectorsDictionary
then your former Vector2Direction()
method would look like so
public static Direction ToDirection(Vector2 vector)
{
Direction direction;
if (vectorsDictionary.TryGetValue(vector.normalized, out direction))
{
return direction;
}
throw new ArgumentException("Argument must be a vector along an axis.", "vector");
}
In the same way you can do it for DirectionVector2
and this would be also possible for the updateSprite()
method.