IEnumerator UpdateSceneCoroutine() { //GenericLog.Log("UPDATE SCENE"); while (!SEGMentPath.instance.ArePathGenerated()) { yield return(null); } //Author - Vincent Casamayou - June 2019 //Check and Update the Radar m_disableRadar = true; Debug.Log("The Radar is " + m_SEGMentEngine.GetCurrentRadar()); if (m_SEGMentEngine.GetCurrentRadar() == true) { m_disableRadar = false; } if (m_backgroundDisplay != null) { GenericLog.Log("APPLI PATH : " + SEGMentPath.instance.GetSEGMentDiagramPath()); //GenericLog.Log("GDATADIRECTORY PATH : " + m_gameDataDirectoryName); GenericLog.Log("GETCURRENTROOMBACKGROUND PATH : " + m_SEGMentEngine.GetCurrentRoomBackgroundImageURL()); m_backgroundDisplay.ChangeImageFromURL(Path.Combine(SEGMentPath.instance.GetSEGMentGameDataPath(), m_SEGMentEngine.GetCurrentRoomBackgroundImageURL())); while (m_backgroundDisplay.IsLoadingNewImage()) { yield return(null); } MetricLogger.instance.Log("CHANGE_ROOM", m_SEGMentEngine.GetCurrentRoomBackgroundImageURL()); yield return(null); } foreach (KeyValuePair <int, GameObject> currentItemKeyValue in m_sceneItemsBySEGMentIndex) { //for (int i = 0; i < m_sceneItems.Count ; ++i) { //foreach (GameObject item in m_sceneItems) { //GameObject currentItem = m_sceneItems[i]; GameObject currentItem = currentItemKeyValue.Value; SpriteSetter currentSpriteSetter = currentItem.GetComponent <SpriteSetter> (); PuzzleBehavior currentPuzzleBehavior = currentItem.GetComponent <PuzzleBehavior>(); if (currentSpriteSetter != null) { m_SEGMentEngine.SetItemStartFrame(currentItemKeyValue.Key, currentSpriteSetter.GetCurrentSpriteFrameNum()); currentSpriteSetter.ReleaseSprite(); } if (currentPuzzleBehavior != null) { if (currentPuzzleBehavior.IsDragDropEnabled()) { //AddPuzzleSavPos(m_roomID, i, currentItem.transform.localPosition, currentItem.transform.localScale); AddPuzzleSavPos(currentItemKeyValue.Key, currentItem.transform.localPosition, currentItem.transform.localScale); } //currentPuzzleBehavior. } Destroy(currentItem); } //m_sceneItems.Clear(); m_sceneItemsBySEGMentIndex.Clear(); List <int> itemIndexes = m_SEGMentEngine.GetItemIndexes(); int orderInLayer = 0; m_roomID = m_SEGMentEngine.GetCurrentRoomID(); int currentPuzzleIndex = 0; m_objectStateToSolutionCheck.Clear(); foreach (int index in itemIndexes) { string itemImageURL = m_SEGMentEngine.GetItemImageURL(index); if (itemImageURL != "") { BoundingBox relativeItemPosBB = m_SEGMentEngine.GetItemBoundingBox(index); GameObject currentItem = Instantiate(m_itemObject, Vector3.zero, Quaternion.identity) as GameObject; SpriteSetter itemSpriteSetter = currentItem.GetComponent <SpriteSetter> (); if (itemSpriteSetter != null) { itemSpriteSetter.SetUIManager(m_UIManager); StartCoroutine(itemSpriteSetter.SetSpriteByURLRelativelyToAnotherOneCoroutine(Path.Combine(SEGMentPath.instance.GetSEGMentGameDataPath(), itemImageURL), m_backgroundDisplay.GetMainSpriteRenderer(), relativeItemPosBB.x1, relativeItemPosBB.y1, relativeItemPosBB.x2, relativeItemPosBB.y2, orderInLayer)); while (!itemSpriteSetter.IsSpriteLoaded()) { yield return(null); } } string itemSoundName = m_SEGMentEngine.GetItemSoundName(index); string itemDescriptionName = m_SEGMentEngine.GetItemDescription(index); bool isPuzzlePiece = m_SEGMentEngine.IsItemPuzllePiece(index); if (isPuzzlePiece) { PuzzleBehavior currentPuzzleBehavior = currentItem.GetComponent <PuzzleBehavior>(); if (currentPuzzleBehavior) { currentPuzzleBehavior.SetUIManager(m_UIManager); currentPuzzleBehavior.EnableDragDrop(true); //if (IsPuzzleSavExist(m_roomID, m_sceneItems.Count)) { //int key = GetHashForPuzzleSav(m_roomID, m_sceneItems.Count); if (IsPuzzleSavExist(index)) { //int key = GetHashForPuzzleSav(m_roomID, index); currentItem.transform.localPosition = m_puzzleSavPositions[index].puzzlePos; currentItem.transform.localScale = m_puzzleSavPositions[index].puzzleScale; ChangePuzzleBehaviorForPuzzleCheck(m_roomID, currentPuzzleIndex, currentPuzzleBehavior); currentPuzzleIndex++; } else { AddPuzzlePieceToChecker(m_roomID, currentPuzzleBehavior); currentPuzzleBehavior.RandomizePos(); } } } if (itemDescriptionName != "") { Text itemText = currentItem.GetComponent <Text>(); if (itemText != null) { itemText.text = itemDescriptionName; } } SoundLauncher itemSoundLauncher = currentItem.GetComponent <SoundLauncher>(); if (itemSoundName != "") { if (itemSoundLauncher != null) { itemSoundLauncher.LoadSoundByURL(SEGMentPath.instance.GetSoundPath(itemSoundName), true); } itemSoundLauncher.PlayLoadedSoundWhenReady(); } List <int> stopFrames = m_SEGMentEngine.GetItemStopFrames(index); List <int> solutionFrames = m_SEGMentEngine.GetItemSolutionFrames(index); AudioSource itemAudioSource = currentItem.GetComponent <AudioSource>(); if (itemAudioSource != null) { if (stopFrames.Count > 0) { itemAudioSource.volume = 0f; } } foreach (int stopFrame in stopFrames) { itemSpriteSetter.SetStopFrame(stopFrame); } if (solutionFrames.Count > 0) { m_objectStateToSolutionCheck[itemSpriteSetter] = solutionFrames; } itemSpriteSetter.setFrameIndex(m_SEGMentEngine.GetItemStartFrame(index)); itemSpriteSetter.StartGifLoop(); //m_sceneItems.Add(currentItem); m_sceneItemsBySEGMentIndex[index] = currentItem; orderInLayer++; yield return(null); } } List <int> clickTextIndexes = m_SEGMentEngine.GetClickTextIndexes(); foreach (GameObject clickText in m_sceneClickTexts) { Destroy(clickText); } foreach (GameObject radarIcon in m_sceneClickTextRadarIcons) { Destroy(radarIcon); } m_sceneClickTexts.Clear(); m_sceneClickTextRadarIcons.Clear(); foreach (int index in clickTextIndexes) { SpriteRenderer clickTextSpriteRenderer = m_clickTextObject.GetComponent <SpriteRenderer>(); if (clickTextSpriteRenderer != null) { GameObject currentClickText = Instantiate(m_clickTextObject, Vector3.zero, Quaternion.identity) as GameObject; GameObject currentClickTextRadarIcon = Instantiate(m_clickTextRadarIcon, Vector3.zero, Quaternion.identity) as GameObject; BoundingBox relativeClickTextPosBB = m_SEGMentEngine.GetClickTextBoundingBox(index); SpriteSetter clickTextSpriteSetter = currentClickText.GetComponent <SpriteSetter> (); if (clickTextSpriteSetter != null) { clickTextSpriteSetter.SetSpriteRelativelyToAnotherOne(clickTextSpriteRenderer.sprite, m_backgroundDisplay.GetMainSpriteRenderer(), relativeClickTextPosBB.x1, relativeClickTextPosBB.y1, relativeClickTextPosBB.x2, relativeClickTextPosBB.y2); } string clickTextSoundName = m_SEGMentEngine.GetClickTextSoundName(index); string clickTextText = m_SEGMentEngine.GetClickTextText(index); bool isClickTextAnURL = m_SEGMentEngine.IsClickTextAnURL(index); if (clickTextText != "") { Text actualText = currentClickText.GetComponent <Text>(); if (actualText != null) { actualText.text = clickTextText; } } if (clickTextSoundName != "") { SoundLauncher clickTextSoundLauncher = currentClickText.GetComponent <SoundLauncher>(); if (clickTextSoundLauncher != null) { clickTextSoundLauncher.LoadSoundByURL(SEGMentPath.instance.GetSoundPath(clickTextSoundName), false); } } MustTextBeConsideredAsURL mustClicTextBeSeenAsAnURL = currentClickText.GetComponent <MustTextBeConsideredAsURL>(); if (mustClicTextBeSeenAsAnURL != null) { mustClicTextBeSeenAsAnURL.SetTextAsBeingAnURL(isClickTextAnURL); } m_sceneClickTexts.Add(currentClickText); // Create a click text radar icon with a respected ratio if (currentClickText.transform.localScale.x < currentClickText.transform.localScale.y) { currentClickTextRadarIcon.transform.localScale = new Vector3(currentClickText.transform.localScale.x, currentClickText.transform.localScale.x, 1.0f); } else { currentClickTextRadarIcon.transform.localScale = new Vector3(currentClickText.transform.localScale.y, currentClickText.transform.localScale.y, 1.0f); } currentClickTextRadarIcon.transform.localPosition = currentClickText.transform.localPosition; m_sceneClickTextRadarIcons.Add(currentClickTextRadarIcon); // *********** // yield return(null); } } if (m_preventInputByKeyboard != null) { if (m_sceneClickTexts.Count > 0) { m_preventInputByKeyboard.SetActive(true); } else { m_preventInputByKeyboard.SetActive(false); } } foreach (GameObject goTo in m_sceneGoTos) { Destroy(goTo); } foreach (GameObject radarIcon in m_sceneGoToRadarIcons) { Destroy(radarIcon); } List <BoundingBox> goToAreas = m_SEGMentEngine.GetListOfDisplacementAreas(); foreach (BoundingBox currentGoToBB in goToAreas) { SpriteRenderer goToAreaSpriteRenderer = m_gotoObject.GetComponent <SpriteRenderer> (); if (goToAreaSpriteRenderer != null) { GameObject currentGoTo = Instantiate(m_gotoObject, Vector3.zero, Quaternion.identity) as GameObject; GameObject currentGoToRadarIcon = Instantiate(m_gotoRadarIcon, Vector3.zero, Quaternion.identity) as GameObject; BoundingBox relativeGoToPosBB = currentGoToBB; SpriteSetter goToSpriteSetter = currentGoTo.GetComponent <SpriteSetter> (); if (goToSpriteSetter != null) { goToSpriteSetter.SetSpriteRelativelyToAnotherOne(goToAreaSpriteRenderer.sprite, m_backgroundDisplay.GetMainSpriteRenderer(), relativeGoToPosBB.x1, relativeGoToPosBB.y1, relativeGoToPosBB.x2, relativeGoToPosBB.y2); } m_sceneGoTos.Add(currentGoTo); // Create a click text radar icon with a respected ratio if (currentGoTo.transform.localScale.x < currentGoTo.transform.localScale.y) { currentGoToRadarIcon.transform.localScale = new Vector3(currentGoTo.transform.localScale.x, currentGoTo.transform.localScale.x, 1.0f); } else { currentGoToRadarIcon.transform.localScale = new Vector3(currentGoTo.transform.localScale.y, currentGoTo.transform.localScale.y, 1.0f); } currentGoToRadarIcon.transform.localPosition = currentGoTo.transform.localPosition; m_sceneGoToRadarIcons.Add(currentGoToRadarIcon); // *********** // } } m_mustHighlightDiary = false; string diaryEntry = m_SEGMentEngine.PopCurrentRoomDiaryEntryName(); if (diaryEntry != "") { m_UIManager.AddDiaryImage(SEGMentPath.instance.GetDiaryPath(diaryEntry)); while (m_UIManager.IsDiaryImageStillLoading()) { yield return(null); } if (m_SEGMentEngine.ShouldDiaryEntryBeHighlighted()) { m_mustHighlightDiary = true; } } UpdatePuzzleChecker(m_roomID); while (Time.fixedTime - m_launchDate < m_minimumWaitTimeForFirstLoad) { yield return(null); } if (m_SEGMentEngine.GetCurrentRoomBackgroundMusicName() != "") { if (m_currentlyPlayedMusic != m_SEGMentEngine.GetCurrentRoomBackgroundMusicName()) { AudioManager.instance.PlayMusicByURL(SEGMentPath.instance.GetSoundPath(m_SEGMentEngine.GetCurrentRoomBackgroundMusicName()), m_SEGMentEngine.MustCurrentRoomBackgroudMusicLoop()); while (!AudioManager.instance.isMusicLoaded()) { yield return(null); } } } else { AudioManager.instance.StopMusic(); } yield return(null); m_currentlyPlayedMusic = m_SEGMentEngine.GetCurrentRoomBackgroundMusicName(); m_isSceneLoaded = true; }
public void UserClicOnClickText(GameObject clickText, Vector3 pos) { if (!m_isClicEnabled) { return; } if (!IsClicEnabledAfterZoom()) { return; } Text textToHandle = clickText.GetComponent <Text>(); MustTextBeConsideredAsURL mustClicTextBeSeenAsAnURL = clickText.GetComponent <MustTextBeConsideredAsURL>(); if (textToHandle != null) { MetricLogger.instance.Log("GO_TO_URL", textToHandle.text, pos.x, pos.y); if (mustClicTextBeSeenAsAnURL != null && mustClicTextBeSeenAsAnURL.IsMatchingTextAnURL()) { #if UNITY_WEBGL //Application.ExternalEval("window.open(\"" + textToHandle.text + \"");"); Application.ExternalEval("window.open(\"" + textToHandle.text + "\")"); #else Application.OpenURL(textToHandle.text); #endif } else if (textToHandle.text != RETURN_STRING) { if ((textToHandle.text.Length > ADD_STRING.Length) && (textToHandle.text.StartsWith(ADD_STRING))) { string actualTextToAdd = textToHandle.text.Substring(ADD_STRING.Length, textToHandle.text.Length - ADD_STRING.Length); MetricLogger.instance.Log("CLICK_TEXT_ADD", actualTextToAdd, pos.x, pos.y); m_UIManager.AddTextToAnswer(actualTextToAdd); } else { MetricLogger.instance.Log("CLICK_TEXT_REPLACE", textToHandle.text, pos.x, pos.y); m_UIManager.ChangeTextToAnswer(textToHandle.text); } } else { m_UIManager.ValidateAnswer(); } SoundLauncher clickTextSoundLauncher = clickText.GetComponent <SoundLauncher> (); if (clickTextSoundLauncher != null) { clickTextSoundLauncher.PlayLoadedSound(); } } // Destroy a potentially created radar if the user actually clicked on an interactable area m_lastInteractionClicTime = Time.time; if (m_lastInteractionClicTime == m_lastRadarCreationTime) { if (m_lastCreatedRadar != null) { Destroy(m_lastCreatedRadar); } } // ********** // }