Пример #1
0
 public void LoadScript(string _fname)
 {
     BackgroundMaster.UnloadBackgrounds();
     ScriptCompiler.UnloadCheckpoints();
     AudioMaster.UnloadAudio();
     VNHandler.UnloadCharacters();
     Resources.UnloadUnusedAssets();
     currentScript_c = M22.ScriptCompiler.CompileScript(_fname);
     //M22.ScriptCompiler.CompileScriptAsync(_fname, ref currentScript_c);
     lineIndex = 0;
     TEXT.Reset(true);
     CURRENT_LINE = currentScript_c.GetLine(lineIndex);
     TEXT.SetNewCurrentLine(CURRENT_LINE.m_lineContents);
     ExecuteFunction(CURRENT_LINE);
 }
Пример #2
0
        public ScriptMaster(
            VNHandler _VNHandlerScript,
            AudioMaster _AudioMasterScript,
            Image _TextboxImage,
            GameObject _DecisionsPrefab,
            GameObject _TransitionPrefab,
            GameObject _VideoPlayerPrefab,
            GameObject _LoopedSFXPrefab
            )
        {
            VNHandlerScript   = _VNHandlerScript;
            AudioMasterScript = _AudioMasterScript;
            TextboxIMG        = _TextboxImage;
            DecisionsPrefab   = _DecisionsPrefab;
            TransitionPrefab  = _TransitionPrefab;
            VideoPlayerPrefab = _VideoPlayerPrefab;
            LoopedSFXPrefab   = _LoopedSFXPrefab;

            this.registeredFunctions = new Dictionary <LINETYPE, InternalFunction>();
            this.registerFunctionClass(LINETYPE.GOTO, new M22.Functions.Goto());
            this.registerFunctionClass(LINETYPE.DRAW_CHARACTER, new M22.Functions.DrawCharacter());
            this.registerFunctionClass(LINETYPE.WAIT, new M22.Functions.Wait());
            this.registerFunctionClass(LINETYPE.NEW_PAGE, new M22.Functions.NewPage());
            this.registerFunctionClass(LINETYPE.DRAW_BACKGROUND, new M22.Functions.DrawBackground());
            this.registerFunctionClass(LINETYPE.SET_FLAG, new M22.Functions.SetFlag());
            this.registerFunctionClass(LINETYPE.NARRATIVE, new M22.Functions.Narrative());
            this.registerFunctionClass(LINETYPE.DIALOGUE, new M22.Functions.Dialogue());
            this.registerFunctionClass(LINETYPE.CLEAR_CHARACTER, new M22.Functions.ClearCharacter());
            this.registerFunctionClass(LINETYPE.CLEAR_CHARACTERS, new M22.Functions.ClearCharacters());
            this.registerFunctionClass(LINETYPE.STOP_SFX_LOOPED, new M22.Functions.StopSFXLooped());
            this.registerFunctionClass(LINETYPE.MOVEMENT_SPEED, new M22.Functions.MovementSpeed());
            this.registerFunctionClass(LINETYPE.LOAD_SCRIPT, new M22.Functions.LoadScript());

            this.Awake();
            this.Start();
        }
Пример #3
0
        void Awake()
        {
            if (!(camera = this.GetComponent <Camera>()))
            {
                throw new System.Exception("[SceneManager] Needs to be attached to a camera.");
            }

            this.AddPrefabs();

            musicSource = this.gameObject.AddComponent <AudioSource>();
            musicSource.bypassEffects     = true;
            musicSource.bypassReverbZones = true;
            musicSource.loop     = true;
            musicSource.priority = 64;
            musicSource.outputAudioMixerGroup = this.outputAudioMixer;
            audioMaster = new AudioMaster(musicSource, this);

            vnHandler    = new VNHandler(CharacterPrefab);
            scriptMaster = new ScriptMaster(
                vnHandler,
                audioMaster,
                TextboxCanvas.transform.Find("Textbox").GetComponent <Image>(),
                DecisionsPrefab,
                TransitionPrefab,
                VideoPlayerPrefab,
                LoopedSFXPrefab
                );
            scriptMaster.background        = BackgroundCanvas.gameObject.transform.Find("Background").gameObject.GetComponent <Image>();
            scriptMaster.backgroundTrans   = BackgroundCanvas.gameObject.transform.Find("BackgroundTransition").gameObject.GetComponent <Image>();
            scriptMaster.TEXT              = TextboxCanvas.gameObject.transform.GetComponentInChildren <TypeWriterScript>();
            scriptMaster.TransitionPrefab  = this.TransitionPrefab;
            scriptMaster.DecisionsPrefab   = this.DecisionsPrefab;
            scriptMaster.VideoPlayerPrefab = this.VideoPlayerPrefab;

            customFunctionality = new CustomFunctionHandler();
        }
Пример #4
0
        static public void CompileLine(ref M22.line_c _lineC, List <string> _splitStr, ref List <M22.script_checkpoint> _chkpnt, int _scriptPos)
        {
            for (int i = 0; i < _splitStr.Count; i++)
            {
                _splitStr[i] = _splitStr[i].Trim('\r', '\n', '\t');
            }
            switch (_lineC.m_lineType)
            {
            case M22.LINETYPE.CHECKPOINT:
                _lineC.m_parameters_txt = new List <string>();
                _splitStr[0]            = _splitStr[0].Substring(2).TrimEnd('\r', '\n');
                _lineC.m_parameters_txt.Add(_splitStr[0]);
                _chkpnt.Add(new M22.script_checkpoint(_scriptPos, _splitStr[0]));
                break;

            case M22.LINETYPE.ANIMATION_TYPE:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters = new List <int>();
                    _splitStr[1]        = _splitStr[1].ToLower();
                    if (_splitStr[1].Equals("lerp"))
                    {
                        _lineC.m_parameters.Add((int)ANIMATION_TYPES.LERP);
                    }
                    else if (_splitStr[1].Equals("smooth"))
                    {
                        _lineC.m_parameters.Add((int)ANIMATION_TYPES.SMOOTH);
                    }
                    else
                    {
                        UnityWrapper.LogErrorFormat("Invalid animation type at line {0}!", _lineC.m_origScriptPos);
                        _lineC.m_parameters.Add(0);
                    }
                }
                break;

            case M22.LINETYPE.TEXT_SPEED:
            case M22.LINETYPE.MOVEMENT_SPEED:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    _lineC.m_parameters_txt.Add(_splitStr[1]);
                }
                break;

            case M22.LINETYPE.SET_ACTIVE_TRANSITION:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    _splitStr[1]            = _splitStr[1].TrimEnd('\r', '\n');
                    _lineC.m_parameters_txt.Add(_splitStr[1]);
                }
                break;

            case M22.LINETYPE.GOTO:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    _splitStr[1]            = _splitStr[1].TrimEnd('\r', '\n');
                    _lineC.m_parameters_txt.Add(_splitStr[1]);
                }
                break;

            case M22.LINETYPE.NEW_PAGE:
                break;

            case M22.LINETYPE.DRAW_CHARACTER:
                if (_splitStr.Count > 1)
                {
                    if (_splitStr.Count < 4)
                    {
                        UnityWrapper.LogError("Not enough parameters for DrawCharacter @ Line " + _lineC.m_origScriptPos.ToString());
                    }
                    _lineC.m_parameters_txt = new List <string>();
                    _lineC.m_parameters_txt.Add(_splitStr[1]);
                    _lineC.m_parameters_txt.Add(_splitStr[2]);
                    _lineC.m_parameters = new List <int>();
                    _lineC.m_parameters.Add(Int32.Parse(_splitStr[3]));
                    if (_splitStr.Count >= 5)
                    {
                        if (_splitStr[4].Equals("true"))
                        {
                            _lineC.m_parameters.Add(1);
                        }
                        else
                        {
                            _lineC.m_parameters.Add(0);
                        }
                    }
                    else
                    {
                        _lineC.m_parameters.Add(0);
                    }

                    if (!M22.VNHandler.LoadCharacter(_lineC.m_parameters_txt[0], _lineC.m_parameters_txt[1]))
                    {
                        UnityWrapper.LogErrorFormat("Failed to load character \"{0}\" at line {1}!", (_lineC.m_parameters_txt[0] + " - " + _lineC.m_parameters_txt[1]), _lineC.m_origScriptPos);
                    }
                    ;
                }
                break;

            case M22.LINETYPE.WAIT:
                _lineC.m_parameters = new List <int>();
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters.Add(Int32.Parse(_splitStr[1]));
                }
                else
                {
                    _lineC.m_parameters.Add(1000);
                }
                break;

            case M22.LINETYPE.CLEAR_CHARACTERS:
                _lineC.m_parameters = new List <int>();
                if (_splitStr.Count > 1 && _splitStr[1].Equals("true"))
                {
                    _lineC.m_parameters.Add(1);
                }
                else
                {
                    _lineC.m_parameters.Add(0);
                }
                if (_splitStr.Count > 2 && _splitStr[2].Equals("true"))
                {
                    _lineC.m_parameters.Add(1);
                }
                else
                {
                    _lineC.m_parameters.Add(0);
                }
                break;

            case M22.LINETYPE.PLAY_STING:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    _splitStr[1]            = _splitStr[1].TrimEnd('\r', '\n');
                    _lineC.m_parameters_txt.Add(_splitStr[1]);

                    if (!M22.AudioMaster.LoadSting(_lineC.m_parameters_txt[0]))
                    {
                        UnityWrapper.LogError("Failed to load sting! - " + _lineC.m_parameters_txt[0]);
                    }
                    ;
                }
                break;

            case M22.LINETYPE.PLAY_MUSIC:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    _splitStr[1]            = _splitStr[1].TrimEnd('\r', '\n');
                    _lineC.m_parameters_txt.Add(_splitStr[1]);

                    if (!M22.AudioMaster.LoadMusic(_lineC.m_parameters_txt[0]))
                    {
                        UnityWrapper.LogErrorFormat("Failed to load music file \"{0}\" at line {1}!", _lineC.m_parameters_txt[0], _lineC.m_origScriptPos);
                    }
                    ;
                }
                break;

            case M22.LINETYPE.EXECUTE_FUNCTION:
                if (_splitStr.Count > 1)
                {
                    // heart_throb 4.0 2.0
                    //            |
                    _lineC.m_parameters_txt = new List <string>();
                    for (int i = 1; i < _splitStr.Count; i++)
                    {
                        _lineC.m_parameters_txt.Add(_splitStr[i]);
                    }
                    _splitStr[_splitStr.Count - 1] = _splitStr[_splitStr.Count - 1].TrimEnd('\r', '\n');
                    // _lineC.m_parameters_txt.Add(_splitStr[_splitStr.Count - 1]);

                    // should be 4
                    while (_lineC.m_parameters_txt.Count < 4)
                    {
                        _lineC.m_parameters_txt.Add("");
                    }

                    if (RegisteredCustomFunctions.TryGetValue(_splitStr[0], out _lineC.m_custFunc) == false)
                    {
                        UnityWrapper.LogErrorFormat("Custom function \"{0}\" does not exist at line {1}!", _lineC.m_parameters_txt[0], _lineC.m_origScriptPos);
                    }
                }
                break;

            case M22.LINETYPE.STOP_MUSIC:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    //_splitStr[1] = _splitStr[1].TrimEnd('\r', '\n');
                    _lineC.m_parameters_txt.Add(_splitStr[1]);
                }
                // we store the float value as a string for later use, if provided.
                // otherwise, just continue
                break;

            case M22.LINETYPE.TRANSITION:
                if (_splitStr.Count > 1)
                {       //Transition other_iwanako tr_eyes 0
                    _lineC.m_parameters_txt = new List <string>();
                    for (int i = 1; i < _splitStr.Count; i++)
                    {
                        _lineC.m_parameters_txt.Add(_splitStr[i]);
                    }

                    if (!M22.BackgroundMaster.LoadBackground(_lineC.m_parameters_txt[0]))
                    {
                        UnityWrapper.LogErrorFormat("Failed to load background - \"{0}\"", _lineC.m_parameters_txt[0]);
                        // failed to load bg!
                    }
                    ;
                }
                break;

            case M22.LINETYPE.DRAW_BACKGROUND:
                if (_splitStr.Count >= 2)
                {
                    _lineC.m_parameters     = new List <int>();
                    _lineC.m_parameters_txt = new List <string>();
                    _lineC.m_parameters_txt.Add(_splitStr[1]);
                    if (_splitStr.Count >= 3)
                    {
                        _lineC.m_parameters.Add(Int32.Parse(_splitStr[2]));
                        if (_splitStr.Count >= 4)
                        {
                            _lineC.m_parameters.Add(Int32.Parse(_splitStr[3]));
                        }
                        if (_splitStr.Count >= 5)
                        {
                            _lineC.m_parameters_txt.Add(_splitStr[4]);
                        }
                        if (_splitStr.Count >= 6)
                        {
                            _lineC.m_parameters_txt.Add(_splitStr[5]);
                        }
                    }
                    else
                    {
                        _lineC.m_parameters.Add(0);
                        _lineC.m_parameters.Add(0);
                        _lineC.m_parameters_txt.Add("1.0");
                        _lineC.m_parameters_txt.Add("1.0");
                    }

                    if (_splitStr[_splitStr.Count - 1].Equals("true"))
                    {
                        _lineC.m_parameters.Add(1);
                    }
                    else
                    {
                        _lineC.m_parameters.Add(0);
                    }

                    if (!M22.BackgroundMaster.LoadBackground(_lineC.m_parameters_txt[0]))
                    {
                        UnityWrapper.LogErrorFormat("Failed to load background \"{0}\" at line {1}", _lineC.m_parameters_txt[0], _lineC.m_origScriptPos);
                    }
                    ;
                }
                else
                {
                    UnityWrapper.LogErrorFormat("Not enough parameters on DrawBackground at line {0}", _lineC.m_origScriptPos);
                }
                break;

            case M22.LINETYPE.ENABLE_NOVEL_MODE:
                break;

            case M22.LINETYPE.DISABLE_NOVEL_MODE:
                break;

            case M22.LINETYPE.PLAY_VIDEO:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    _lineC.m_parameters_txt.Add(_splitStr[1]);

                    if (M22.ScriptMaster.LoadVideoFile(_splitStr[1]) == false)
                    {
                        UnityWrapper.LogError("Failed to load video file: " + _splitStr[1]);
                    }
                }
                break;

            case M22.LINETYPE.CLEAR_CHARACTER:
                if (_splitStr.Count >= 2)
                {
                    _lineC.m_parameters     = new List <int>();
                    _lineC.m_parameters_txt = new List <string>();
                    _lineC.m_parameters_txt.Add(_splitStr[1]);
                    if (_splitStr.Count >= 3)
                    {
                        if (_splitStr[2].Equals("true"))
                        {
                            _lineC.m_parameters.Add(1);
                        }
                        else
                        {
                            _lineC.m_parameters.Add(0);
                        }
                    }
                    else
                    {
                        _lineC.m_parameters.Add(0);
                    }
                }
                break;

            case M22.LINETYPE.LOAD_SCRIPT:
            case M22.LINETYPE.HIDE_WINDOW:
            case M22.LINETYPE.SHOW_WINDOW:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    _lineC.m_parameters_txt.Add(_splitStr[1]);
                }
                break;

            case M22.LINETYPE.SET_FLAG:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    _splitStr[1]            = _splitStr[1].TrimEnd('\r', '\n');
                    _lineC.m_parameters_txt.Add(_splitStr[1]);
                }
                break;

            case M22.LINETYPE.IF_STATEMENT:
                // m22IF _flag_to_check_if_true Command [params]
                //
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    _lineC.m_parameters_txt.Add(_splitStr[1]);

                    line_c        tempCompiledLine = new line_c();
                    List <string> functionSplit    = new List <string>();
                    for (int i = 2; i < _splitStr.Count; i++)
                    {
                        functionSplit.Add(_splitStr[i]);
                    }
                    tempCompiledLine.m_lineType = CheckLineType(_splitStr[2]);
                    CompileLine(ref tempCompiledLine, functionSplit, ref _chkpnt, _scriptPos);
                    if (tempCompiledLine.m_lineContents == null)
                    {
                        tempCompiledLine.m_lineContents = "";
                        for (int i = 2; i < _splitStr.Count; i++)
                        {
                            tempCompiledLine.m_lineContents += _splitStr[i] + " ";
                        }
                    }
                    tempCompiledLine.m_lineContents = tempCompiledLine.m_lineContents.Replace("\\n", "\n");
                    _lineC.m_lineContents           = tempCompiledLine.m_lineContents;
                    _lineC.m_lineTypeSecondary      = tempCompiledLine.m_lineType;

                    if (tempCompiledLine.m_parameters_txt != null)
                    {
                        for (int i = 0; i < tempCompiledLine.m_parameters_txt.Count; i++)
                        {
                            _lineC.m_parameters_txt.Add(tempCompiledLine.m_parameters_txt[i]);
                        }
                    }

                    if (tempCompiledLine.m_parameters != null)
                    {
                        _lineC.m_parameters = new List <int>();
                        for (int i = 0; i < tempCompiledLine.m_parameters.Count; i++)
                        {
                            _lineC.m_parameters.Add(tempCompiledLine.m_parameters[i]);
                        }
                    }
                }
                break;

            case M22.LINETYPE.PLAY_SFX_LOOPED:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    _lineC.m_parameters_txt.Add(_splitStr[1]);

                    if (_splitStr.Count > 3)
                    {
                        _lineC.m_parameters_txt.Add(_splitStr[2]);
                        _lineC.m_parameters_txt.Add(_splitStr[3]);
                    }
                    else
                    {
                        _lineC.m_parameters_txt.Add("1.0");
                        _lineC.m_parameters_txt.Add("1.0");
                    }

                    if (!M22.AudioMaster.LoadSting(_lineC.m_parameters_txt[0]))
                    {
                        UnityWrapper.LogError("Failed to load sting! - " + _lineC.m_parameters_txt[0]);
                    }
                    ;
                }
                break;

            case M22.LINETYPE.STOP_SFX_LOOPED:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    _lineC.m_parameters_txt.Add(_splitStr[1]);

                    if (AudioMaster.IsAudioLoaded(_splitStr[1]) == false)
                    {
                        UnityWrapper.LogWarningFormat("Stopping a looped SFX that isn't played/loaded yet at line {0}; this shouldn't happen!", _lineC.m_origScriptPos);
                    }

                    if (_splitStr.Count > 2)
                    {
                        _lineC.m_parameters_txt.Add(_splitStr[2]);
                    }
                    else
                    {
                        _lineC.m_parameters_txt.Add("1.0");
                    }
                }
                break;

            case M22.LINETYPE.MAKE_DECISION:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    string reconstructed = "";
                    for (int i = 0; i < _splitStr.Count; i++)
                    {
                        reconstructed += _splitStr[i] + " ";
                    }
                    List <string> splitByQuote = new List <string>();
                    SplitString(ref reconstructed, ref splitByQuote, '\"');

                    // Should be 5 or 7
                    if (splitByQuote.Count != 5 && splitByQuote.Count != 7)
                    {
                        UnityWrapper.LogError("MakeDecision error; mismatched number of quotemarks!");
                    }

                    for (int i = 1; i < splitByQuote.Count; i++)
                    {
                        //splitByQuote[i] = _splitStr[i].TrimEnd(' ');
                        //splitByQuote[i] = _splitStr[i].TrimStart(' ');
                        splitByQuote[i] = splitByQuote[i].Trim(' ', '\"');
                        _lineC.m_parameters_txt.Add(splitByQuote[i]);
                    }

                    // up to 6 parameters
                    // flags do not use "" but the text string does
                    // i.e. MakeDecision "Choice 1" choice_1 "Choice 2" choice_2 "Choice 3" choice_3
                    // if(num of quotemarks != 6) mismatch error
                    //
                    // This means splitStr is useless cus of spaces, and will need to be re-split in terms of " marks
                    // i.e. splitStr[0] == "MakeDecision ";
                    // splitStr[1] == "Choice 1";
                    // splitStr[2] == " choice_1 ";
                }
                break;
            }
            return;
        }
Пример #5
0
        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;
            }
        }
Пример #6
0
        void Start()
        {
            VNHandlerScript   = this.gameObject.GetComponent <M22.VNHandler>();
            AudioMasterScript = this.gameObject.GetComponent <AudioMaster>();
            TextboxIMG        = GameObject.Find("Textbox").GetComponent <Image>();
            if (TEXT == null)
            {
                Debug.Log("TEXT not found in ScriptMaster; falling back to searching...");
                TEXT = TextboxIMG.gameObject.GetComponentInChildren <TypeWriterScript>();
                if (TEXT == null)
                {
                    Debug.Log("This also failed! :(");
                }
                else
                {
                    TEXT.SetParent(this);
                }
            }
            else
            {
                TEXT.SetParent(this);
            }
            if (background == null)
            {
                Debug.Log("background not found in ScriptMaster; falling back to searching...");
                if (GameObject.Find("Background") != null)
                {
                    background = GameObject.Find("Background").GetComponent <Image>();
                }
                if (background == null)
                {
                    Debug.Log("This also failed! :(");
                }
                else
                {
                    backgroundScript = background.gameObject.GetComponent <BackgroundScript>();
                }
            }
            else
            {
                backgroundScript = background.gameObject.GetComponent <BackgroundScript>();
            }

            if (backgroundTrans == null)
            {
                Debug.Log("backgroundTrans not found in ScriptMaster; falling back to searching...");
                if (GameObject.Find("BackgroundTransition") != null)
                {
                    backgroundTrans = GameObject.Find("BackgroundTransition").GetComponent <Image>();
                }
                if (backgroundTrans == null)
                {
                    Debug.Log("This also failed! :(");
                }
                else
                {
                    backgroundTransScript = backgroundTrans.gameObject.GetComponent <BackgroundScript>();
                }
            }
            else
            {
                backgroundTransScript = backgroundTrans.gameObject.GetComponent <BackgroundScript>();
            }

            if (GameObject.Find("BackgroundCanvas") != null)
            {
                Canvases.Add(GameObject.Find("BackgroundCanvas").GetComponent <Canvas>());
            }
            if (GameObject.Find("PreCharacterEffectCanvas") != null)
            {
                Canvases.Add(GameObject.Find("PreCharacterEffectCanvas").GetComponent <Canvas>());
            }
            if (GameObject.Find("CharacterCanvas") != null)
            {
                Canvases.Add(GameObject.Find("CharacterCanvas").GetComponent <Canvas>());
            }
            if (GameObject.Find("PostCharacterEffectCanvas") != null)
            {
                Canvases.Add(GameObject.Find("PostCharacterEffectCanvas").GetComponent <Canvas>());
            }
            if (GameObject.Find("TextboxCanvas") != null)
            {
                Canvases.Add(GameObject.Find("TextboxCanvas").GetComponent <Canvas>());
            }
            if (GameObject.Find("EffectCanvas") != null)
            {
                Canvases.Add(GameObject.Find("EffectCanvas").GetComponent <Canvas>());
            }

            if (TransitionPrefab == null)
            {
                Debug.LogError("TransitionPrefab not attached to ScriptMaster! Check this under Main Camera!");
            }
            TransitionEffects = new Dictionary <string, Sprite>();
            TransitionEffects.Add("tr_eyes", Resources.Load <Sprite>("Transitions/tr_eyes") as Sprite);
            TransitionEffects.Add("default", Resources.Load <Sprite>("Images/white") as Sprite);
            TransitionEffects.Add("tr-pronoise", Resources.Load <Sprite>("Transitions/tr-pronoise") as Sprite);
            TransitionEffects.Add("tr-clockwipe", Resources.Load <Sprite>("Transitions/tr-clockwipe") as Sprite);
            TransitionEffects.Add("tr-softwipe", Resources.Load <Sprite>("Transitions/tr-softwipe") as Sprite);
            TransitionEffects.Add("tr-delayblinds", Resources.Load <Sprite>("Transitions/tr-delayblinds") as Sprite);
            TransitionEffects.Add("tr-flashback", Resources.Load <Sprite>("Transitions/tr-flashback") as Sprite);

            if (VideoPlayerPrefab == null)
            {
                Debug.LogError("VideoPlayerPrefab not attached to ScriptMaster! Check this under Main Camera!");
            }

            LoopedSFXPrefab = Resources.Load("Prefabs/SFXPrefab") as GameObject;
            if (LoopedSFXPrefab == null)
            {
                Debug.LogError("Failed to load LoopedSFXPrefab! Check \"Resources/Prefabs\" for this!");
            }

            if (TextboxIMG != null)
            {
                HideText();
            }
        }
Пример #7
0
        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;
            }
        }