I'm working on a unity3d project.
Most of my code is loosely coupled to the engine i'm working with. Meaning To move a player i will have an InputProxy, which is Engine dependant, then some engine independent code like InputController, InputManager to eventually call a PlayerManager saying 'MoveForward(Player)' in this case being loosely coupled is not really an issue. Because i will have an EnginePlayer implementation, where the MoveForward call we be translated in relevant engine code.
Now i have the following situation: I want to spawn the avatar of my player in the world over the network.
Apart from a whole lot of other calls this ends in NetworkProxy.SpawnAvatarOnNetwork(INetworkPlayer). You can find the full code below, but the part my question is about this
`var avatarPrefab = player.Client.Player.Avatar.ToEngineAvatar() as GameObject;`
Is this good practice, providing casts in my framework to 'the engine version' or would you do this in another way?
This is the code of SpawnAvatarOnNetwork:
public void InitializeNetworkAwareAvatar(INetworkPlayer player)
{
if (player == null)
throw new ArgumentNullException("avatar");
var uLinkNetworkPlayer = (uLink.NetworkPlayer)player.EngineNetworkPlayer;
var avatarPrefab = player.Client.Player.Avatar.ToEngineAvatar() as GameObject;
var appendLoginData = false; // TODO Integrate login data
object[] initialData = appendLoginData ? uLink.Network.loginData : new object[0];
uLink.Network.Instantiate(uLinkNetworkPlayer,
avatarPrefab,
avatarPrefab,
avatarPrefab,
player.Client.Player.Avatar.Position,
player.Client.Player.Avatar.Rotation,
0, //Magical number - No different network groups at the moment
initialData
);
}