I'm new to both SmartFoxServer and Unity.
I have an array of some objects. Each frame I want to broadcast to other clients some information about the objects. My code looks like this.
Code: Select all
foreach(KeyValuePair<string, MyGameObject> entry in objects)
{
MyGameObject obj = entry.Value;
transferObjectSend = new SFSObject();
transferObjectSend.PutUtfString("messageID", "gameObject");
transferObjectSend.PutUtfString("objectID", obj.objectID);
transferObjectSend.PutUtfString("userID", obj.userID);
transferObjectSend.PutUtfString("prefab", obj.prefab);
transferObjectSend.PutFloatArray("locomotion", new float[]
{
obj.transform.position.x,
obj.transform.position.y,
obj.transform.position.z,
obj.transform.rotation.x,
obj.transform.rotation.y,
obj.transform.rotation.z,
obj.transform.rotation.w
});
transferObjectSend.PutUtfString("currentState", obj.currentState);
smartFox.Send(new ObjectMessageRequest(transferObjectSend, smartFox.LastJoinedRoom));
}
My test only has 3 such objects in the array, and the frame rate is already very low (< 10 fps). When I remove the call of smartFox.send. The frame rate goes back to good.
The login and room joining is all successful. I only have one client as myself in this test.
I know the code looks stupid, but it's only a test before I decide to continue my work using Unity/SmartFox combination. Optimizing those strings above could make performance better, but the point is that I intended to have a hundred such objects in my game, I guess it’s not a matter of optimization. Did I miss something? or it’s totally wrong?
Could anybody help? Thank you very much.