/// <summary> /// Update the given game object with the given XML entity data /// </summary> /// <param name="destGameObject">The given game object to update</param> /// <param name="data">The given source XML entity data</param> protected void UpdateObject(GameObject destGameObject, VrXmlEntityData data) { destGameObject.name = data.name; EntityData entityData = destGameObject.GetComponent <EntityData>(); if (entityData == null) { entityData = destGameObject.AddComponent <EntityData>(); } entityData.id = data.id; entityData.name = data.name; entityData.type = data.type; entityData.description = data.description; if (!string.IsNullOrEmpty(data.localTransform.relToId)) { destGameObject.transform.SetParent(entityObjects[data.localTransform.relToId].transform, false); } else { destGameObject.transform.SetParent(null, false); } destGameObject.transform.localPosition = CsConversion.VecToVecRL(data.localTransform.position.Get(), scenarioData.upAxisIsZ); if (data.localTransform.useRotationMatrix) { Matrix4x4 rotMatrix = (Matrix4x4)(data.localTransform.rotationMatrix); destGameObject.transform.localRotation.SetLookRotation( CsConversion.RotMatForward(rotMatrix, scenarioData.upAxisIsZ), CsConversion.RotMatUp(rotMatrix, scenarioData.upAxisIsZ)); } else { destGameObject.transform.localEulerAngles = (Vector3)data.localTransform.eulerAngles; } destGameObject.transform.localScale = data.localTransform.scale.Get(); }
public override void UpdateScenarioData() { UpdateEntityObjectsList(); ClearScenarioData(); SimController simController = GetComponent <SimController>(); if (simController) { simController.StopSimulation(); if (scenarioData.simulation == null) { scenarioData.simulation = new VrXmlSimulationData(); } scenarioData.simulation.historyUri = simController.simulationHistory.historyUri; scenarioData.simulation.historyName = simController.simulationHistory.historyName; scenarioData.simulation.description = simController.simulationHistory.description; scenarioData.simulation.details = simController.simulationHistory.details; } foreach (var entry in entityObjects) { var data = scenarioData.entityList.Find(x => x.id == entry.Key); if (data == null) { data = new VrXmlEntityData(); scenarioData.entityList.Add(data); } UpdateEntity(entry.Value, data); // load simulation EntityHistory history = entry.Value.GetComponent <EntityHistory>(); if (history) { scenarioData.simulation.historyList.Add(ConvertObjectHistory(history)); } } }
protected void UpdateEntity(GameObject sourceGameObject, VrXmlEntityData data) { bool zUp = OriginalUpAxisIsZ; var entityInfo = sourceGameObject.GetComponent <EntityData>(); if (entityInfo == null) { Debug.LogWarning("Failed to get entity data from object " + sourceGameObject.name); return; } data.id = entityInfo.id; data.name = sourceGameObject.name; data.type = entityInfo.type; if (entityInfo.activeRepresentation) { if (data.representation == null) { data.representation = new VrXmlRepresentation(); } data.representation.assetBundleName = null; data.representation.assetName = null; data.representation.localTransform.FromTransform(entityInfo.activeRepresentation.transform, zUp); switch (entityInfo.activeRepresentation.assetType) { case EntityRepresentation.AssetType.AssetBundle: data.representation.assetType = VrXmlRepresentation.AssetType.AssetBundle; data.representation.assetBundleName = entityInfo.activeRepresentation.assetBundleName; data.representation.assetName = entityInfo.activeRepresentation.assetName; break; case EntityRepresentation.AssetType.Prefab: data.representation.assetType = VrXmlRepresentation.AssetType.Prefab; data.representation.assetName = entityInfo.activeRepresentation.assetName; break; case EntityRepresentation.AssetType.Model: data.representation.assetType = VrXmlRepresentation.AssetType.Model; data.representation.assetName = entityInfo.activeRepresentation.assetName; data.representation.importOptions = entityInfo.activeRepresentation.importOptions; break; case EntityRepresentation.AssetType.Primitive: data.representation.assetType = ConvertRepresentationPrimType(entityInfo.activeRepresentation.assetPrimType); break; case EntityRepresentation.AssetType.None: data.representation.assetType = VrXmlRepresentation.AssetType.None; break; } } else { if (!string.IsNullOrEmpty(entityInfo.assetName)) { if (data.representation == null) { data.representation = new VrXmlRepresentation(); } if (!string.IsNullOrEmpty(entityInfo.assetBundleName)) { data.representation.assetType = VrXmlRepresentation.AssetType.AssetBundle; } else { data.representation.assetType = VrXmlRepresentation.AssetType.Prefab; } data.representation.assetBundleName = entityInfo.assetBundleName; data.representation.assetName = entityInfo.assetName; } else if (entityInfo.GetComponent <MeshFilter>()) { if (data.representation == null) { data.representation = new VrXmlRepresentation(); } data.representation.assetBundleName = null; data.representation.assetName = null; Mesh mesh = entityInfo.GetComponent <MeshFilter>().sharedMesh; data.representation.assetType = ConvertMeshToAssetType(mesh); } } data.description = entityInfo.description; data.localTransform.FromTransform(sourceGameObject.transform, zUp); scenarioData.relationshipList.RemoveAll(x => x.ownerEntityId == entityInfo.id); foreach (var rel in sourceGameObject.GetComponents <Relationship>()) { scenarioData.relationshipList.Add(ConvertObjectRelationship(rel)); } }