public void spawnObject() { SyncPositionMessage positionMessage = QTUtils.getSyncPositionMessage(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z); SyncRotationMessage rotationMessage = QTUtils.getSyncRotationMessage(gameObject.transform.rotation.eulerAngles.x, gameObject.transform.rotation.eulerAngles.y, gameObject.transform.rotation.eulerAngles.z); ServerQTObject obj = (ServerQTObject)WorkerServerManager.instance.spawnManager.spawnObject(Guid.NewGuid().ToString(), prefabName, positionMessage, rotationMessage); }
public static SyncRotationMessage getSyncRotationMessageFromObject(BaseQTObject obj) { SyncRotationMessage message = new SyncRotationMessage(); message.rotX = obj.gameObject.transform.eulerAngles.x; message.rotY = obj.gameObject.transform.eulerAngles.y; message.rotZ = obj.gameObject.transform.eulerAngles.z; return(message); }
public static SyncRotationMessage getSyncRotationMessage(float rotX = 0f, float rotY = 0f, float rotZ = 0f) { SyncRotationMessage message = new SyncRotationMessage(); message.rotX = rotX; message.rotY = rotY; message.rotZ = rotZ; return(message); }
public void emitRotationSync() { SyncRotationMessage message = new SyncRotationMessage(); message.objectID = obj.objectID; message.rotX = gameObject.transform.rotation.eulerAngles.x; message.rotY = gameObject.transform.rotation.eulerAngles.y; message.rotZ = gameObject.transform.rotation.eulerAngles.z; message.index = index; WorkerServerManager.instance.sendMessageToAllReady(message); }
public static GameObject spawnGameobject(GameObject obj, SyncPositionMessage spawnPosition, SyncRotationMessage spawnRotation) { GameObject gameObject = Instantiate(obj); gameObject.transform.SetPositionAndRotation(new Vector3(spawnPosition.posX, spawnPosition.posY, spawnPosition.posZ), Quaternion.Euler(spawnRotation.rotX, spawnRotation.rotY, spawnRotation.rotZ)); return(gameObject); }
public override BaseQTObject spawnObject(string objectID, string prefabName, SyncPositionMessage spawnPosition, SyncRotationMessage spawnRotation) { GameObject obj = QTUtils.spawnGameobject(AppManager.instance.networkStorage.prefabs.Find(o => o.name == prefabName), spawnPosition, spawnRotation); ClientQTObject spawnedObj = obj.AddComponent <ClientQTObject>(); spawnedObj.objectID = objectID; spawnedObj.prefabName = prefabName; processSpawn(spawnedObj); QTDebugger.instance.debug(QTDebugger.debugType.BASE, "Spawned " + prefabName + " with ID - " + objectID); return(spawnedObj); }
public override BaseQTObject spawnObject(string objectID, string prefabName, SyncPositionMessage spawnPosition, SyncRotationMessage spawnRotation) { GameObject obj = QTUtils.spawnGameobject(AppManager.instance.networkStorage.prefabs.Find(o => o.name == prefabName), spawnPosition, spawnRotation); ServerQTObject spawnedObj = obj.AddComponent <ServerQTObject>(); spawnedObj.objectID = objectID; spawnedObj.prefabName = prefabName; processSpawn(spawnedObj); SpawnMessage message = new SpawnMessage(); message.objectID = spawnedObj.objectID; message.prefabName = prefabName; message.spawnPosition = spawnPosition; message.spawnRotation = spawnRotation; WorkerServerManager.instance.sendMessageToAllReady(message); QTDebugger.instance.debug(QTDebugger.debugType.BASE, "Spawned " + prefabName + " with ID - " + objectID); return(spawnedObj); }
public abstract BaseQTObject spawnObject(string objectID, string prefabName, SyncPositionMessage spawnPosition, SyncRotationMessage spawnRotation);
public override void handleMessage(QTMessage message) { switch (message.messageType) { case QTMessage.type.SYNC_POSITION: { SyncPositionMessage syncMessage = (SyncPositionMessage)message; if (ClientManager.instance.spawnManager.spawnedObjects.ContainsKey(syncMessage.objectID) == false) { return; } ClientQTObject clientObject = (ClientQTObject)ClientManager.instance.spawnManager.spawnedObjects[syncMessage.objectID]; SyncGameobject syncComponent = (SyncGameobject)clientObject.objectComponents[syncMessage.index]; syncComponent.syncedPosition = new Vector3(syncMessage.posX, syncMessage.posY, syncMessage.posZ); break; } case QTMessage.type.SYNC_ROTATION: { SyncRotationMessage syncMessage = (SyncRotationMessage)message; if (ClientManager.instance.spawnManager.spawnedObjects.ContainsKey(syncMessage.objectID) == false) { return; } ClientQTObject clientObject = (ClientQTObject)ClientManager.instance.spawnManager.spawnedObjects[syncMessage.objectID]; SyncGameobject syncComponent = (SyncGameobject)clientObject.objectComponents[syncMessage.index]; syncComponent.syncedRotation = new Vector3(syncMessage.rotX, syncMessage.rotY, syncMessage.rotZ); break; } case QTMessage.type.SYNC_ACTIVE: { SyncActiveMessage syncMessage = (SyncActiveMessage)message; if (ClientManager.instance.spawnManager.spawnedObjects.ContainsKey(syncMessage.objectID) == false) { return; } ClientQTObject clientObject = (ClientQTObject)ClientManager.instance.spawnManager.spawnedObjects[syncMessage.objectID]; SyncGameobject syncComponent = (SyncGameobject)clientObject.objectComponents[syncMessage.index]; syncComponent.gameObject.SetActive(syncMessage.value); break; } case QTMessage.type.SYNC_FIELD: { FieldInfoMessage syncMessage = (FieldInfoMessage)message; if (ClientManager.instance.spawnManager.spawnedObjects.ContainsKey(syncMessage.objectID) == false) { return; } ClientQTObject clientObject = (ClientQTObject)ClientManager.instance.spawnManager.spawnedObjects[syncMessage.objectID]; BaseQTObjectComponent component = clientObject.objectComponents[syncMessage.index]; component.clientComponent.setSyncedField(syncMessage.fieldName, QTUtils.getValueFromSyncFieldMessage(syncMessage)); break; } case QTMessage.type.SYNC_ANIMATION: { AnimationParameterInfoMessage syncMessage = (AnimationParameterInfoMessage)message; if (ClientManager.instance.spawnManager.spawnedObjects.ContainsKey(syncMessage.objectID) == false) { return; } ClientQTObject clientObject = (ClientQTObject)ClientManager.instance.spawnManager.spawnedObjects[syncMessage.objectID]; SyncAnimation component = (SyncAnimation)clientObject.objectComponents[syncMessage.index]; QTUtils.applySyncAnimationMessageToAnimator(component.animator, syncMessage); break; } case QTMessage.type.CALL_FUNCTION: { try { CallFunctionMessage callMessage = (CallFunctionMessage)message; if (ClientManager.instance.spawnManager.spawnedObjects.ContainsKey(callMessage.objectID) == false) { return; } ClientQTObject clientObject = (ClientQTObject)ClientManager.instance.spawnManager.spawnedObjects[callMessage.objectID]; BaseQTObjectComponent component = clientObject.objectComponents[callMessage.index]; List <object> parameters = new List <object>(); if (callMessage.parameters != null) { foreach (FieldInfoMessage fieldMessage in callMessage.parameters) { parameters.Add(QTUtils.getValueFromSyncFieldMessage(fieldMessage)); } } component.callFunction(callMessage.functionName, parameters.ToArray()); } catch (Exception e) { Debug.LogError(e); } break; } } }