private void Start() { musicController = GameObject.FindObjectOfType <MusicController>(); TB_Questions[] questions = GameObject.FindObjectsOfType <TB_Questions>(); for (int i = 0; i < questions.Length; i++) { if (questions[i].IsStartNode) { startQuestion = questions[i]; break; } } animationFinders = GameObject.FindObjectsOfType <AnimationFinder>(); spriteFinders = GameObject.FindObjectsOfType <SpriteFinder>(); }
// Update is called once per frame void Update() { if (!TB_Execute.isRunning) { if (from == null | from.FREEZE == false) { if (actions != null && oldActionsCount != actions.Length) { oldActionsCount = actions.Length; attachedTrans.Clear(); attachedTrans = new List <Transform>(); attachedTrans.Add(textDiagIndex.transform); for (int i = 0; i < actions.Length; i++) { attachedTrans.Add(actions[i].transform); } updateSelfRenderPos(); } if (oldFrom != from) { if (oldFrom != null) { oldFrom.DeRegisterDialog(this); } if (from != null) { from.RegisterDialog(this); } oldFrom = from; updateSelfRenderPos(); } if (oldTo != to) { oldTo = to; updateSelfRenderPos(); } if (from != null) { if (oldFromPos != from.transform.position) { oldFromPos = from.transform.position; updateSelfRenderPos(); } if (oldName != dialogName) { oldName = dialogName; from.UpdateOutDiagStringArray(); DiagTopTag = dialogName; } } if (to != null) { if (oldToPos != to.transform.position) { oldToPos = to.transform.position; updateSelfRenderPos(); } } } } }
private void Update() { for (int i = 0; i < toStopAnims.Count; i++) { toStopAnims[i].stopIn -= Time.deltaTime; if (toStopAnims[i].stopIn <= 0f) { toStopAnims[i].animator.SetBool(toStopAnims[i].animationClip, false); toStopAnims.RemoveAt(i); i--; } } if (RUN == false && isRunning) { isRunning = false; } if (RUN && wasRunning == false) { resetAllGlows(); curNode = startQuestion; curNode.IsGlowing = true; state = ExecState.QUESTION; wasRunning = true; //isRunning = true; } else if (RUN && wasRunning) { switch (state) { case ExecState.QUESTION: curNode.IsGlowing = true; if (curNode.endingIndex != -1) { newsPaperFlyer.Fly(curNode.endingIndex); } else { if (curNode.isFactorNode) { Debug.Log("Factor question node"); Debug.Log("Factors: " + StaticParameters.factorMoneyFamily.ToString() + ", " + StaticParameters.factorIntimicy + ", " + StaticParameters.factorConvProg + ", " + StaticParameters.factorTrustFun); string[] toAsk = curNode.Questions; float maxVal = Mathf.Max(StaticParameters.factorConvProg, StaticParameters.factorIntimicy, StaticParameters.factorMoneyFamily, StaticParameters.factorTrustFun); if (maxVal == StaticParameters.factorConvProg) { AnswerQuestion("ConvProg"); } else if (maxVal == StaticParameters.factorMoneyFamily) { AnswerQuestion("MoneyFamily"); } else if (maxVal == StaticParameters.factorIntimicy) { AnswerQuestion("Intimicy"); } else { AnswerQuestion("TrustFun"); } } else { string[] toAsk = Utils <string> .Mix(curNode.Questions); AskQuestion(toAsk); Debug.Log("Asking questions: " + toAsk.ToString()); state = ExecState.QUESTION_WAIT; // H_ATS if (curNode.hat.Length > 0) { bool foundTarget = false; for (int i = 0; i < animationFinders.Length; i++) { if (animationFinders[i].animatorName == "LeftPerson") { for (int j = 0; j < allHats.Length; j++) { animationFinders[i].GetComponent <Animator>().SetBool("hat_" + allHats[j], false); } animationFinders[i].GetComponent <Animator>().SetBool("hat_" + curNode.hat, true); } } } if (curNode.hatRight.Length > 0) { bool foundTarget = false; for (int i = 0; i < animationFinders.Length; i++) { if (animationFinders[i].animatorName == "RightPerson") { for (int j = 0; j < allHats.Length; j++) { animationFinders[i].GetComponent <Animator>().SetBool("hat_" + allHats[j], false); } animationFinders[i].GetComponent <Animator>().SetBool("hat_" + curNode.hatRight, true); } } } } } break; case ExecState.ACTION: if (curAction != null) { curAction.IsGlowing = false; } if (curNode != null) { curNode.IsGlowing = false; } if (actionIndex < curDiag.Actions.Length) { curAction = curDiag.Actions[actionIndex]; curAction.IsGlowing = true; actionIndex++; waitTime = curAction.Time; // Actions if (curAction.GetType() == typeof(TB_ActionMusicLayer)) { Debug.Log("Action Music Layer"); TB_ActionMusicLayer actionMusicLayer = (TB_ActionMusicLayer)curAction; musicController.PlayLayers(actionMusicLayer.MusicLayerProps); } else if (curAction.GetType() == typeof(TB_ActionSpeak)) { Debug.Log("Action Speak"); TB_ActionSpeak actionSpeak = (TB_ActionSpeak)curAction; if (actionSpeak.SpeakAnimation.Length > 0) { for (int i = 0; i < animationFinders.Length; i++) { if (animationFinders[i].animatorName == (actionSpeak.PersonSpeakIndex == 0 ? "Left" : "Right") + "Person") { animationFinders[i].GetComponent <Animator>().SetBool(actionSpeak.SpeakAnimation, true); runningSpeakAnim = true; runningSpeakAnimLeftPerson = actionSpeak.PersonSpeakIndex == 0; runningSpeakAnimName = actionSpeak.SpeakAnimation; } } } interactor.ShowDialogText(actionSpeak.SpeakText, actionSpeak.PersonSpeakIndex == 0, actionSpeak.SpeakClip); } else if (curAction.GetType() == typeof(TB_ActionSound)) { Debug.Log("Action Sound"); TB_ActionSound actionSound = (TB_ActionSound)curAction; GameObject gamAudioSource = new GameObject("Sound " + actionSound.Clip.name); gamAudioSource.AddComponent <AudioSource>(); AudioSource audioSource = gamAudioSource.GetComponent <AudioSource>(); audioSource.clip = actionSound.Clip; audioSource.volume = actionSound.Volume; audioSource.loop = false; audioSource.Play(); Destroy(gamAudioSource, actionSound.Clip.length + 2f); } else if (curAction.GetType() == typeof(TB_ActionAnimation)) { Debug.Log("Action Animation"); TB_ActionAnimation actionAnimation = (TB_ActionAnimation)curAction; bool foundTarget = false; for (int i = 0; i < animationFinders.Length; i++) { if (animationFinders[i].animatorName == actionAnimation.AnimatorTarget) { foundTarget = true; if (actionAnimation.Duration == -2f) { animationFinders[i].GetComponent <Animator>().SetBool(actionAnimation.AnimationClipName, false); } else if (actionAnimation.Duration == -1f) { animationFinders[i].GetComponent <Animator>().SetBool(actionAnimation.AnimationClipName, true); } else { animationFinders[i].GetComponent <Animator>().SetBool(actionAnimation.AnimationClipName, true); AnimationStopper animStop = new AnimationStopper(); animStop.animationClip = actionAnimation.AnimationClipName; animStop.animator = animationFinders[i].GetComponent <Animator>(); animStop.stopIn = actionAnimation.Duration; toStopAnims.Add(animStop); } } } if (!foundTarget) { Debug.LogError("Didn't find animation target. Is a AnimationFinder attached to the Animator object?"); } } else if (curAction.GetType() == typeof(TB_ActionSprite)) { TB_ActionSprite actionSprite = (TB_ActionSprite)curAction; bool foundTarget = false; for (int i = 0; i < spriteFinders.Length; i++) { if (spriteFinders[i].spriteName == actionSprite.SpriteName) { foundTarget = true; SpriteRenderer[] children = spriteFinders[i].GetComponentsInChildren <SpriteRenderer>(); GameObject spriteFader = new GameObject("Sprite Fader"); spriteFader.AddComponent <SpriteFader>(); spriteFader.GetComponent <SpriteFader>().fadeTime = 5f; spriteFader.GetComponent <SpriteFader>().fadeToSprite = actionSprite.Sprite; spriteFader.GetComponent <SpriteFader>().spriteRenderer = children[0].sprite == null ? children[1] : children[0]; spriteFader.GetComponent <SpriteFader>().spriteRendererDest = children[1].sprite == null ? children[1] : children[0]; spriteFader.GetComponent <SpriteFader>().StartAnim(); //spriteFinders[i].GetComponent<SpriteRenderer>().sprite = actionSprite.Sprite; } } if (!foundTarget) { Debug.LogError("Didn't find sprite target. Is a SpriteFinder attached to the SpriteRenderer object?"); } } state = ExecState.ACTION_WAIT; } // Was last action else { Debug.Log("Last Action"); curNode = curDiag.QuestionTo; state = ExecState.QUESTION; } break; case ExecState.ACTION_WAIT: if (waitTime != -1f) { waitTime -= Time.deltaTime; if (waitTime <= 0f) { state = ExecState.ACTION; } } break; } } }