private void Start() { // Create our first sequence condition intCondition = new InteractionCondition(); intCondition.targetObject = targetObject; intCondition.targetCondition = triggerType; intCondition.RegisterCondition(); }
public IEnumerator PlaySequence(int idx = 0) { yield return(new WaitForSeconds(StartDelay)); for (int i = idx; i < SequenceElements.Count; i++) { if (!SequenceElements[i].EnableStep) { continue; } curIdx = i; // If we have a spawned prefab then destroy it and set to null unless set to persist. if (spawnedPrefab != null && !SequenceElements[curIdx].PrefabPersists) { GameObject.Destroy(spawnedPrefab); spawnedPrefab = null; } if (SequenceElements[curIdx].StepAudio != null) { _audioQueued = true; StartCoroutine("PlayAudio"); } msgBox.PlayMessage(SequenceElements[curIdx].Message); WaitingForEvent = SequenceElements[curIdx].WaitForEvent; WaitingForAudio = SequenceElements[curIdx].WaitForAudio; if (SequenceElements[curIdx].InstructionStep) { _repeatIdx = curIdx; } if (WaitingForEvent && !SequenceElements[curIdx].EventCondition.PrefabCondition) { InteractionCondition stepCondition = new InteractionCondition(); stepCondition.targetObject = SequenceElements[curIdx].EventCondition.targetObject; stepCondition.targetCondition = SequenceElements[curIdx].EventCondition.targetCondition; stepCondition.duration = SequenceElements[curIdx].EventCondition.duration; RegisterCondition(stepCondition); } if (SequenceElements[curIdx].StepPrefab != null) { spawnedPrefab = GameObject.Instantiate(SequenceElements[curIdx].StepPrefab) as GameObject; } // Check for event while (msgBox.playingMessage || WaitingForEvent || WaitingForAudio) { if (WaitingForEvent && curCondition != null && !msgBox.playingMessage) { WaitingForEvent = !curCondition.CheckCondition(); if (!WaitingForEvent) { curCondition = null; } } WaitingForAudio = _audioQueued || AudioManager.Instance.Playing; yield return(new WaitForEndOfFrame()); } } if (TransitionToLevel != null && TransitionToLevel.Length > 0 && TransitionToLevel != SceneManager.GetActiveScene().name) { // Debug.Log("Current: " + Application.loadedLevelName + " Loading: " + TransitionToLevel); SceneManager.LoadScene(TransitionToLevel, LoadSceneMode.Single); } SequenceComplete = true; yield return(null); }