Пример #1
0
        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));
                }
            }
        }
Пример #2
0
        protected override IEnumerator UpdateScene()
        {
            Debug.Log("Updating scenario...");
            // scan each data info in the scenario and add missing objects in the scene
            foreach (VrXmlEntityData entity in scenarioData.entityList)
            {
                if (!entityObjects.ContainsKey(entity.id))
                {
                    GameObject go         = new GameObject();//GameObject.CreatePrimitive(PrimitiveType.Cube);
                    EntityData entityData = go.AddComponent <EntityData>();
                    entityData.id = entity.id;
                    entityObjects.Add(entity.id, go);
                }
                if (entity.representation != null)
                {
                    representationCount++;
                }
            }
            yield return(new WaitForSecondsRealtime(0.2f));

            Debug.Log("Updating entities...");
            // scan each data info in the scenario and (add and) update objects in the scene
            foreach (VrXmlEntityData entity in scenarioData.entityList)
            {
                if (entityObjects.ContainsKey(entity.id))
                {
                    UpdateObject(entityObjects[entity.id], entity);
#if UNITY_EDITOR
                    if (progressDelay > 0)
                    {
                        yield return(new WaitForSecondsRealtime(progressDelay));
                    }
#endif

                    if (entity.representation != null)
                    {
                        yield return(CreateRepresentationObject(entityObjects[entity.id].GetComponent <EntityData>(), entity.representation));
                    }
                    updatedEntities++;
                }
            }

            Debug.Log("Updating relationships...");
            // scan each relationship in the scenario and (add and) update components in the scene
            foreach (VrXmlRelationship entity in scenarioData.relationshipList)
            {
                ConvertEntityRelationship(entity);
            }

            if (scenarioData.simulation != null)
            {
                Debug.Log("Loading simulation...");
                SimController simController = GetComponent <SimController>();
                if (simController == null)
                {
                    simController = gameObject.AddComponent <SimController>();
                }
                simController.simulationHistory.historyUri  = scenarioData.simulation.historyUri;
                simController.simulationHistory.historyName = scenarioData.simulation.historyName;
                simController.simulationHistory.description = scenarioData.simulation.description;
                simController.simulationHistory.details     = scenarioData.simulation.details;
                // scan each history in the scenario and (add and) update components in the scene
                foreach (VrXmlHistoryData history in scenarioData.simulation.historyList)
                {
                    ConvertEntityHistory(history);
                }
                simController.LoadSimulation();
                if (scenarioData.simulation.autoStart)
                {
                    simController.PlaySimulation();
                }
            }
            Debug.Log("Scenario updated.");
        }