public void FadeToBlackCallback() { BackgroundTransition temp = GameObject.FindGameObjectWithTag("Transition").GetComponent <BackgroundTransition>(); background.sprite = temp.destSprite; backgroundScript.UpdateBackground( 0, 0, 1.0f, 1.0f ); //WaitState = WAIT_STATE.NOT_WAITING; if (WaitQueue.Count > 0) { WaitQueue.RemoveAt(0); } NextLine(); }
public void ExecuteFunction(line_c _line, bool _isInLine = false) { if (_isInLine == true) { inLineFunctionMode = true; } switch (_line.m_lineType) { case LINETYPE.NARRATIVE: TEXT.SetNewCurrentLine(CURRENT_LINE.m_lineContents); VNHandlerScript.ClearCharacterName(); break; case LINETYPE.DIALOGUE: TEXT.SetNewCurrentLine(CURRENT_LINE.m_lineContents); VNHandlerScript.UpdateCharacterName(CURRENT_LINE.m_speaker); break; case LINETYPE.NEW_PAGE: if (VNHandlerScript == null || VNHandlerScript.VNMode == false) { TEXT.Reset(true, NextLine); } else { NextLine(_isInLine); } break; case LINETYPE.MOVEMENT_SPEED: if (VNHandlerScript != null) { VNHandlerScript.SetMovementSpeed(float.Parse(_line.m_parameters_txt[0])); } NextLine(_isInLine); break; case LINETYPE.TEXT_SPEED: if (TEXT != null) { TEXT.SetTextSpeed(float.Parse(_line.m_parameters_txt[0])); } NextLine(_isInLine); break; case LINETYPE.DRAW_BACKGROUND: if (backgroundScript.IsMoving()) { backgroundScript.SetIsMoving(false); } backgroundTrans.sprite = M22.BackgroundMaster.GetBackground(_line.m_parameters_txt[0]); //RectTransform tempRT = backgroundTrans.gameObject.GetComponent<RectTransform>(); //tempRT.offsetMax = new Vector2(backgroundTrans.sprite.texture.height, 0); if (backgroundTrans.sprite == background.sprite) { //WaitState = WAIT_STATE.BACKGROUND_MOVING; WaitQueue.Add(new M22.WaitObject(WAIT_STATE.BACKGROUND_MOVING)); backgroundScript.UpdatePos( _line.m_parameters[0], _line.m_parameters[1] ); } else { backgroundTransScript.UpdateBackground( _line.m_parameters[0], _line.m_parameters[1], float.Parse(_line.m_parameters_txt[1]), float.Parse(_line.m_parameters_txt[2]) ); backgroundTrans.color = new Color(1, 1, 1, 0.001f); } if (_line.m_parameters[2] == 1) { //WaitState = WAIT_STATE.NOT_WAITING; if (WaitQueue.Count > 0) { WaitQueue.RemoveAt(0); } NextLine(_isInLine); } break; case LINETYPE.GOTO: bool success = false; foreach (var item in M22.ScriptCompiler.currentScript_checkpoints) { if (item.m_name == _line.m_parameters_txt[0]) { success = true; GotoLine(item.m_position); break; } } if (!success) { Debug.LogError("Failed to find checkpoint: " + _line.m_parameters_txt[0]); NextLine(_isInLine); } break; case LINETYPE.WAIT: //WaitState = WAIT_STATE.WAIT_COMMAND; WaitQueue.Add(new WaitObject(WAIT_STATE.WAIT_COMMAND)); waitCommandTimer = 0; break; case LINETYPE.DRAW_CHARACTER: VNHandlerScript.CreateCharacter(_line.m_parameters_txt[0], _line.m_parameters_txt[1], _line.m_parameters[0]); if (_line.m_parameters[1] != 1) { HideText(); //WaitState = WAIT_STATE.CHARACTER_FADEIN; WaitQueue.Add(new WaitObject(WAIT_STATE.CHARACTER_FADEIN)); } else { NextLine(_isInLine); } break; case LINETYPE.PLAY_MUSIC: M22.AudioMaster.ChangeTrack(_line.m_parameters_txt[0]); NextLine(_isInLine); break; case LINETYPE.ANIMATION_TYPE: ActiveAnimationType = (ScriptCompiler.ANIMATION_TYPES)_line.m_parameters[0]; NextLine(_isInLine); break; case LINETYPE.STOP_MUSIC: if (_line.m_parameters_txt != null) { AudioMasterScript.StopMusic(_line.m_parameters_txt[0]); } else { AudioMasterScript.StopMusic("1.0"); } NextLine(_isInLine); break; case LINETYPE.PLAY_STING: M22.AudioMaster.PlaySting(_line.m_parameters_txt[0]); NextLine(_isInLine); break; case LINETYPE.HIDE_WINDOW: if (_line.m_parameters_txt != null && _line.m_parameters_txt.Count >= 1) { HideText(true, float.Parse(_line.m_parameters_txt[0])); } else { HideText(); } NextLine(_isInLine); break; case LINETYPE.SHOW_WINDOW: if (_line.m_parameters_txt != null && _line.m_parameters_txt.Count >= 1) { ShowText(true, float.Parse(_line.m_parameters_txt[0])); } else { ShowText(); } NextLine(_isInLine); break; case LINETYPE.SET_FLAG: if (SCRIPT_FLAGS.Contains(_line.m_parameters_txt[0])) { // Flag already set, ignore } else { SCRIPT_FLAGS.Add(_line.m_parameters_txt[0]); } NextLine(_isInLine); break; case LINETYPE.IF_STATEMENT: // m22IF _flag_to_check_if_true Command [params] if (SCRIPT_FLAGS.Contains(_line.m_parameters_txt[0])) { //Debug.Log("True!"); line_c tempCompiledLine = new line_c(); tempCompiledLine.m_lineType = _line.m_lineTypeSecondary; tempCompiledLine.m_parameters_txt = new List <string>(); if (_line.m_parameters_txt != null && _line.m_parameters_txt.Count > 1) { for (int i = 1; i < _line.m_parameters_txt.Count; i++) { tempCompiledLine.m_parameters_txt.Add(_line.m_parameters_txt[i]); } } else { tempCompiledLine.m_parameters_txt = _line.m_parameters_txt; } tempCompiledLine.m_parameters = _line.m_parameters; tempCompiledLine.m_lineContents = _line.m_lineContents; ExecuteFunction(tempCompiledLine); } else { //Debug.Log("False!"); NextLine(_isInLine); } break; case LINETYPE.NULL_OPERATOR: NextLine(_isInLine); break; case LINETYPE.MAKE_DECISION: GameObject tempObj = GameObject.Instantiate <GameObject>(DecisionsPrefab, Canvases[(int)CANVAS_TYPES.EFFECTS].transform); if (_line.m_parameters_txt.Count == 6) { tempObj.GetComponent <Decision>().Initialize(_line.m_parameters_txt[0], _line.m_parameters_txt[1], _line.m_parameters_txt[2], _line.m_parameters_txt[3], _line.m_parameters_txt[4], _line.m_parameters_txt[5]); } else { tempObj.GetComponent <Decision>().Initialize(_line.m_parameters_txt[0], _line.m_parameters_txt[1], _line.m_parameters_txt[2], _line.m_parameters_txt[3]); } break; case LINETYPE.ENABLE_NOVEL_MODE: if (VNHandlerScript.VNMode == true) { VNHandlerScript.ToggleVNMode(); } NextLine(_isInLine); break; case LINETYPE.DISABLE_NOVEL_MODE: if (VNHandlerScript.VNMode == false) { VNHandlerScript.ToggleVNMode(); } NextLine(_isInLine); break; case LINETYPE.PLAY_VIDEO: VideoPlayerInstance = GameObject.Instantiate <GameObject>(VideoPlayerPrefab, Canvases[(int)CANVAS_TYPES.EFFECTS].transform).GetComponent <VideoPlayer>(); VideoPlayerInstance.targetCamera = Camera.main; AudioMasterScript.StopMusic("100.0"); VideoClip tempVid; loadedVideoClips.TryGetValue(_line.m_parameters_txt[0], out tempVid); VideoPlayerInstance.clip = tempVid; VideoPlayerInstance.SetTargetAudioSource(0, Camera.main.GetComponent <AudioSource>()); VideoPlayerInstance.Play(); //WaitState = WAIT_STATE.VIDEO_PLAYING; WaitQueue.Add(new WaitObject(WAIT_STATE.VIDEO_PLAYING)); break; case LINETYPE.LOAD_SCRIPT: LoadScript(_line.m_parameters_txt[0]); break; case LINETYPE.PLAY_SFX_LOOPED: SFXScript temploopSFX = GameObject.Instantiate <GameObject>(LoopedSFXPrefab, Camera.main.transform).GetComponent <SFXScript>(); temploopSFX.Init(AudioMaster.GetAudio(_line.m_parameters_txt[0]), _line.m_parameters_txt[1], _line.m_parameters_txt[2], true); NextLine(); break; case LINETYPE.STOP_SFX_LOOPED: GameObject loopSFXobj = GameObject.Find(_line.m_parameters_txt[0]); if (loopSFXobj == null) { Debug.LogErrorFormat("Failed to stop looping SFX \"{0}\" at line {1}; is not currently playing!", _line.m_parameters_txt[0], _line.m_origScriptPos); NextLine(); return; } SFXScript stopSFXloop = loopSFXobj.GetComponent <SFXScript>(); stopSFXloop.Stop(_line.m_parameters_txt[1]); NextLine(); break; case LINETYPE.CLEAR_CHARACTER: if (VNHandlerScript.ClearCharacter(_line.m_parameters_txt[0], _line.m_parameters[0] == 1 ? true : false) == false) { Debug.LogErrorFormat("Unable to clear character {0} at line {1}", _line.m_parameters_txt[0], _line.m_origScriptPos); NextLine(_isInLine); break; } if (_line.m_parameters[0] == 1) { NextLine(_isInLine); } else { WaitQueue.Add(new WaitObject(WAIT_STATE.CHARACTER_FADEOUT_INDIVIDUAL, _line.m_parameters_txt[0])); } break; case LINETYPE.CLEAR_CHARACTERS: VNHandlerScript.ClearCharacters(_line.m_parameters[0] == 1 ? true : false); HideText(); //WaitState = WAIT_STATE.CHARACTER_FADEOUT; WaitQueue.Add(new WaitObject(WAIT_STATE.CHARACTER_FADEOUT)); break; case LINETYPE.EXECUTE_FUNCTION: CustomFunctionHandler.CustomFunctionDelegate temp = CustomFunctionHandler.GetFunction(_line.m_parameters_txt[0]); if (temp != null) { string[] funcParams = new string[_line.m_parameters_txt.Count - 1]; for (int i = 1; i < _line.m_parameters_txt.Count; i++) { funcParams[i - 1] = _line.m_parameters_txt[i]; } temp(funcParams); } else { Debug.LogError("Failed to find custom function: " + _line.m_parameters_txt[0]); } break; case LINETYPE.TRANSITION: GameObject tempGO = GameObject.Instantiate <GameObject>(TransitionPrefab, Canvases[(int)CANVAS_TYPES.POSTCHARACTER].transform); tempGO.GetComponent <Image>().material = Instantiate <Material>(tempGO.GetComponent <Image>().material) as Material; BackgroundTransition TransitionObj = tempGO.GetComponent <BackgroundTransition>(); TransitionObj.callback = FadeToBlackCallback; if (_line.m_parameters_txt.Count >= 4) { TransitionObj.Speed = float.Parse(_line.m_parameters_txt[3]); } //TransitionObj.srcSprite = background.sprite; TransitionObj.srcSprite = Resources.Load <Sprite>("Images/empty") as Sprite; TransitionEffects.TryGetValue(_line.m_parameters_txt[1], out TransitionObj.effect); TransitionObj.destSprite = M22.BackgroundMaster.GetBackground(_line.m_parameters_txt[0]); TransitionObj.inOrOut = (String.Equals(_line.m_parameters_txt[2], "in") ? BackgroundTransition.IN_OR_OUT.IN : BackgroundTransition.IN_OR_OUT.OUT); //WaitState = WAIT_STATE.TRANSITION; WaitQueue.Add(new WaitObject(WAIT_STATE.TRANSITION)); break; case LINETYPE.NUM_OF_LINETYPES: // do nuzing. Debug.Log("End of script! This shouldn't really happen; make sure your script ends properly!"); HideText(); break; default: NextLine(_isInLine); break; } }
public void ExecuteFunction(line_c _line, bool _isInLine = false) { if (_isInLine == true) { inLineFunctionMode = true; } if (this.registeredFunctions.ContainsKey(_line.m_lineType)) { InternalFunction func; this.registeredFunctions.TryGetValue(_line.m_lineType, out func); func.Func(ref _line); } switch (_line.m_lineType) { case LINETYPE.TEXT_SPEED: if (TEXT != null) { TEXT.SetTextSpeed(float.Parse(_line.m_parameters_txt[0])); } NextLine(_isInLine); break; case LINETYPE.PLAY_MUSIC: M22.AudioMaster.ChangeTrack(_line.m_parameters_txt[0]); NextLine(_isInLine); break; case LINETYPE.ANIMATION_TYPE: ActiveAnimationType = (ScriptCompiler.ANIMATION_TYPES)_line.m_parameters[0]; NextLine(_isInLine); break; case LINETYPE.STOP_MUSIC: if (_line.m_parameters_txt != null) { AudioMasterScript.StopMusic(_line.m_parameters_txt[0]); } else { AudioMasterScript.StopMusic("1.0"); } NextLine(_isInLine); break; case LINETYPE.PLAY_STING: M22.AudioMaster.PlaySting(_line.m_parameters_txt[0]); NextLine(_isInLine); break; case LINETYPE.HIDE_WINDOW: if (_line.m_parameters_txt != null && _line.m_parameters_txt.Count >= 1) { HideText(true, float.Parse(_line.m_parameters_txt[0])); } else { HideText(); } NextLine(_isInLine); break; case LINETYPE.SHOW_WINDOW: if (_line.m_parameters_txt != null && _line.m_parameters_txt.Count >= 1) { ShowText(true, float.Parse(_line.m_parameters_txt[0])); } else { ShowText(); } NextLine(_isInLine); break; case LINETYPE.IF_STATEMENT: // m22IF _flag_to_check_if_true Command [params] if (SCRIPT_FLAGS.Contains(_line.m_parameters_txt[0])) { //Debug.Log("True!"); line_c tempCompiledLine = new line_c(); tempCompiledLine.m_lineType = _line.m_lineTypeSecondary; tempCompiledLine.m_parameters_txt = new List <string>(); if (_line.m_parameters_txt != null && _line.m_parameters_txt.Count > 1) { for (int i = 1; i < _line.m_parameters_txt.Count; i++) { tempCompiledLine.m_parameters_txt.Add(_line.m_parameters_txt[i]); } } else { tempCompiledLine.m_parameters_txt = _line.m_parameters_txt; } tempCompiledLine.m_parameters = _line.m_parameters; tempCompiledLine.m_lineContents = _line.m_lineContents; ExecuteFunction(tempCompiledLine); } else { //Debug.Log("False!"); NextLine(_isInLine); } break; case LINETYPE.NULL_OPERATOR: NextLine(_isInLine); break; case LINETYPE.MAKE_DECISION: setMakingDecision(true); GameObject tempObj = GameObject.Instantiate <GameObject>(DecisionsPrefab, Canvases[(int)CANVAS_TYPES.EFFECTS].transform); if (_line.m_parameters_txt.Count == 6) { tempObj.GetComponent <Decision>().Initialize(_line.m_parameters_txt[0], _line.m_parameters_txt[1], _line.m_parameters_txt[2], _line.m_parameters_txt[3], _line.m_parameters_txt[4], _line.m_parameters_txt[5]); } else { tempObj.GetComponent <Decision>().Initialize(_line.m_parameters_txt[0], _line.m_parameters_txt[1], _line.m_parameters_txt[2], _line.m_parameters_txt[3]); } break; case LINETYPE.ENABLE_NOVEL_MODE: if (VNHandlerScript.VNMode == true) { VNHandlerScript.ToggleVNMode(); } NextLine(_isInLine); break; case LINETYPE.DISABLE_NOVEL_MODE: if (VNHandlerScript.VNMode == false) { VNHandlerScript.ToggleVNMode(); } NextLine(_isInLine); break; case LINETYPE.PLAY_VIDEO: VideoPlayerInstance = GameObject.Instantiate <GameObject>(VideoPlayerPrefab, Canvases[(int)CANVAS_TYPES.EFFECTS].transform).GetComponent <VideoPlayer>(); VideoPlayerInstance.targetCamera = Camera.main; AudioMasterScript.StopMusic("100.0"); VideoClip tempVid; loadedVideoClips.TryGetValue(_line.m_parameters_txt[0], out tempVid); VideoPlayerInstance.clip = tempVid; VideoPlayerInstance.SetTargetAudioSource(0, Camera.main.GetComponent <AudioSource>()); VideoPlayerInstance.Play(); //WaitState = WAIT_STATE.VIDEO_PLAYING; WaitQueue.Add(new WaitObject(WAIT_STATE.VIDEO_PLAYING)); break; case LINETYPE.LOAD_SCRIPT: LoadScript(_line.m_parameters_txt[0]); break; case LINETYPE.CHECKPOINT: NextLine(_isInLine); break; case LINETYPE.PLAY_SFX_LOOPED: SFXScript temploopSFX = GameObject.Instantiate <GameObject>(LoopedSFXPrefab, Camera.main.transform).GetComponent <SFXScript>(); temploopSFX.Init(AudioMaster.GetAudio(_line.m_parameters_txt[0]), _line.m_parameters_txt[1], _line.m_parameters_txt[2], true); NextLine(); break; case LINETYPE.EXECUTE_FUNCTION: string[] funcParams = new string[_line.m_parameters_txt.Count]; for (int i = 0; i < _line.m_parameters_txt.Count; i++) { funcParams[i] = _line.m_parameters_txt[i]; } _line.m_custFunc.Func(funcParams); break; case LINETYPE.TRANSITION: GameObject tempGO = GameObject.Instantiate <GameObject>(TransitionPrefab, Canvases[(int)CANVAS_TYPES.POSTCHARACTER].transform); tempGO.GetComponent <Image>().material = GameObject.Instantiate <Material>(tempGO.GetComponent <Image>().material) as Material; BackgroundTransition TransitionObj = tempGO.GetComponent <BackgroundTransition>(); TransitionObj.callback = FadeToBlackCallback; if (_line.m_parameters_txt.Count >= 4) { TransitionObj.Speed = float.Parse(_line.m_parameters_txt[3]); } //TransitionObj.srcSprite = background.sprite; TransitionObj.srcSprite = TryToLoadImage("Images/empty") as Sprite; TransitionEffects.TryGetValue(_line.m_parameters_txt[1], out TransitionObj.effect); TransitionObj.destSprite = M22.BackgroundMaster.GetBackground(_line.m_parameters_txt[0]); TransitionObj.inOrOut = (String.Equals(_line.m_parameters_txt[2], "in") ? BackgroundTransition.IN_OR_OUT.IN : BackgroundTransition.IN_OR_OUT.OUT); //WaitState = WAIT_STATE.TRANSITION; WaitQueue.Add(new WaitObject(WAIT_STATE.TRANSITION)); break; case LINETYPE.NUM_OF_LINETYPES: // do nuzing. Debug.Log("End of script! This shouldn't really happen; make sure your script ends properly!"); HideText(); break; default: // NextLine(_isInLine); break; } }