void IterateToNextQuestion() { if (GameplayReferences.HMD == null) { Cleanup(false); return; } bool useLastPanelPosition = false; Vector3 lastPanelPosition = Vector3.zero; Quaternion lastPanelRotation = Quaternion.identity; //close current panel if (CurrentExitPollPanel != null) { lastPanelPosition = CurrentExitPollPanel.transform.position; lastPanelRotation = CurrentExitPollPanel.transform.rotation; useLastPanelPosition = true; //CurrentExitPollPanel = null; } if (!useLastPanelPosition) { if (!GetSpawnPosition(out lastPanelPosition)) { CognitiveVR.Util.logDebug("no last position set. invoke endaction"); Cleanup(false); return; } } //if next question, display that if (panelProperties.Count > 0 && currentPanelIndex < panelProperties.Count) { //DisplayPanel(panelProperties[currentPanelIndex], panelCount, lastPanelPosition); var prefab = GetPrefab(panelProperties[currentPanelIndex]); if (prefab == null) { Util.logError("couldn't find prefab " + panelProperties[currentPanelIndex]); Cleanup(false); return; } Vector3 spawnPosition = lastPanelPosition; Quaternion spawnRotation = lastPanelRotation; if (currentPanelIndex == 0) { //figure out world spawn position if (myparameters.UseOverridePosition || myparameters.ExitpollSpawnType == ExitPoll.SpawnType.World) { spawnPosition = myparameters.OverridePosition; } if (myparameters.UseOverrideRotation || myparameters.ExitpollSpawnType == ExitPoll.SpawnType.World) { spawnRotation = myparameters.OverrideRotation; } } var newPanelGo = GameObject.Instantiate <GameObject>(prefab, spawnPosition, spawnRotation); CurrentExitPollPanel = newPanelGo.GetComponent <ExitPollPanel>(); if (CurrentExitPollPanel == null) { Debug.LogError(newPanelGo.gameObject.name + " does not have ExitPollPanel component!"); GameObject.Destroy(newPanelGo); Cleanup(false); return; } CurrentExitPollPanel.Initialize(panelProperties[currentPanelIndex], panelCount, this); if (myparameters.ExitpollSpawnType == ExitPoll.SpawnType.World && myparameters.UseAttachTransform) { if (myparameters.AttachTransform != null) { newPanelGo.transform.SetParent(myparameters.AttachTransform); } } } else //finished everything format and send { SendResponsesAsTransaction(); //for personalization api var responses = FormatResponses(); NetworkManager.PostExitpollAnswers(responses, QuestionSetName, questionSetVersion); //for exitpoll microservice CurrentExitPollPanel = null; Cleanup(true); } panelCount++; }
void DisplayPanel(Dictionary <string, string> properties, int panelId, Vector3 spawnPoint) { GameObject prefab = null; switch (properties["type"]) { case "HAPPYSAD": prefab = ExitPoll.ExitPollHappySad; break; case "SCALE": prefab = ExitPoll.ExitPollScale; break; case "MULTIPLE": prefab = ExitPoll.ExitPollMultiple; break; case "VOICE": prefab = ExitPoll.ExitPollVoice; break; case "THUMBS": prefab = ExitPoll.ExitPollThumbs; break; case "BOOLEAN": prefab = ExitPoll.ExitPollTrueFalse; break; } if (prefab == null) { Util.logError("couldn't find prefab " + properties["type"]); if (EndAction != null) { EndAction.Invoke(); } OverridePosition = null; OverrideRotation = null; if (_pointer) { _pointer.SetVisible(false); } ExitPoll.CurrentExitPollSet = null; return; } var newPanelGo = GameObject.Instantiate <GameObject>(prefab); //set position if (OverridePosition.HasValue) { newPanelGo.transform.position = OverridePosition.Value; } else { newPanelGo.transform.position = spawnPoint; } //set rotation if (OverrideRotation.HasValue) { newPanelGo.transform.rotation = OverrideRotation.Value; } else { newPanelGo.transform.rotation = Quaternion.LookRotation(newPanelGo.transform.position - CognitiveVR_Manager.HMD.position, Vector3.up); } CurrentExitPollPanel = newPanelGo.GetComponent <ExitPollPanel>(); CurrentExitPollPanel.Initialize(properties, panelId, this); }