Exemplo n.º 1
0
        public void NextLine(bool _isInLine = false)
        {
            if (_isInLine == true || inLineFunctionMode == true)
            {
                TEXT.FinishedInlineFunction();
                inLineFunctionMode = false;
                return;
            }
            else if (isMakingDecision())
            {
                return;
            }

            ++lineIndex;
            CURRENT_LINE = currentScript_c.GetLine(lineIndex);
            if (VNHandlerScript.VNMode == true && CURRENT_LINE.m_lineType != LINETYPE.MAKE_DECISION)
            {
                TEXT.Reset(true);
            }
            if (CURRENT_LINE.m_lineType != LINETYPE.MAKE_DECISION)
            {
                TEXT.SetNewCurrentLine("");
            }
            ExecuteFunction(CURRENT_LINE);
        }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
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;
            }
        }
Exemplo n.º 5
0
 public void SetCurrentInlineFunction(line_c _lineC)
 {
     CurrentInlineFunction = _lineC;
 }
Exemplo n.º 6
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;
            }
        }
Exemplo n.º 7
0
 virtual public void Func(ref line_c _line, bool _isInline = false)
 {
 }