Exemplo n.º 1
0
        /// <summary>
        /// Called when current actions are all taken, or jump action or flag action is taking.
        /// Load next script, use the scriptName when it is set, or just load the next script in alphabet order of the script list.
        /// </summary>
        /// <param name="scriptName">Name of the next script should be loaded</param>
        /// <returns>Return a list of action from the loaded script</returns>
        public List <Action> loadNextScript(string scriptName = null)
        {
            if (scriptName == null)
            {
                if (currentScript == null)
                {
                    if (scriptNames == null || scriptNames.Count < 1)
                    {
                        return(null);
                    }
                    scriptName = scriptNames[0];
                }
                else
                {
                    //Debug.Log ("scriptNames.IndexOf(currentScriptName) = "+scriptNames.IndexOf(currentScriptName));
                    //Debug.Log ("scriptNames.Count = "+scriptNames.Count);
                    if (scriptNames.IndexOf(currentScriptName) + 1 == scriptNames.Count)
                    {
                        //No more scripts
                        Debug.Log("No more scripts");
                        return(null);
                    }
                    scriptName = scriptNames[scriptNames.IndexOf(currentScriptName) + 1];
                }
            }
            currentScriptName = scriptName;
            string scriptPath = FolderStructure.SCRIPTS + scriptName + "." + ScriptKeyword.SCRIPT_EXTENSION;

            Debug.Log("scriptPath: " + scriptPath);
            try {
                BinaryFormatter bf = new BinaryFormatter();

                TextAsset asset      = Resources.Load(scriptPath) as TextAsset;
                Stream    scriptFile = new MemoryStream(asset.bytes);

                //FileStream scriptFile = File.Open(scriptPath, FileMode.Open);
                Script scriptData = (Script)bf.Deserialize(scriptFile);
                scriptFile.Close();

                //Debug.Log("scriptData = " + scriptData);

                this.currentScript             = scriptData;
                this.currentScriptActionsCount = scriptData.actions.Count;
                Debug.Log("scriptData.actions.Count: " + scriptData.actions.Count);
                return(scriptData.actions);
            } catch (IOException ex) {
                Debug.LogError("IO error when saving: " + ex.Message);
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called when current actions are all taken, or jump action or flag action is taking.
        /// Load next script, use the scriptName when it is set, or just load the next script in alphabet order of the script list.
        /// </summary>
        /// <param name="scriptName">Name of the next script should be loaded</param>
        /// <returns>Return a list of action from the loaded script</returns>
        public List<Action> loadNextScript(string scriptName = null)
        {
            if (scriptName == null) {
                if (currentScript == null) {
                    if (scriptNames == null || scriptNames.Count < 1) {
                        return null;
                    }
                    scriptName = scriptNames[0];
                } else {
                    //Debug.Log ("scriptNames.IndexOf(currentScriptName) = "+scriptNames.IndexOf(currentScriptName));
                    //Debug.Log ("scriptNames.Count = "+scriptNames.Count);
                    if (scriptNames.IndexOf(currentScriptName) + 1 == scriptNames.Count) {
                        //No more scripts
                        Debug.Log("No more scripts");
                        return null;
                    }
                    scriptName = scriptNames[scriptNames.IndexOf(currentScriptName) + 1];
                }
            }
            currentScriptName = scriptName;
            string scriptPath = FolderStructure.SCRIPTS + scriptName + "." + ScriptKeyword.SCRIPT_EXTENSION;
            Debug.Log("scriptPath: " + scriptPath);
            try {
                BinaryFormatter bf = new BinaryFormatter();

                TextAsset asset = Resources.Load(scriptPath) as TextAsset;
                Stream scriptFile = new MemoryStream(asset.bytes);

                //FileStream scriptFile = File.Open(scriptPath, FileMode.Open);
                Script scriptData = (Script)bf.Deserialize(scriptFile);
                scriptFile.Close();

                //Debug.Log("scriptData = " + scriptData);

                this.currentScript = scriptData;
                this.currentScriptActionsCount = scriptData.actions.Count;
                Debug.Log("scriptData.actions.Count: " + scriptData.actions.Count);
                return scriptData.actions;

            } catch (IOException ex) {
                Debug.LogError("IO error when saving: " + ex.Message);
            }

            return null;
        }