public void InitFrom(InteractionScriptInfo info){ // initialize members from deserialized info gameObject.name = info.unityObjectName; // this should only be done if we have gameobject per script triggerStrings = info.triggerStrings; // the string that causes this script to start running triggerOnStatus = info.triggerOnStatus; // should we listen to InteractStatusMessages for our trigger ? startingArgs = info.startingArgs; scriptLines = new ScriptedAction[info.scriptLines.Length]; for (int i = 0; i<info.scriptLines.Length; i++){ GameObject go = new GameObject(info.scriptLines[i].unityObjectName); go.transform.parent = this.transform; scriptLines[i] = go.AddComponent("ScriptedAction") as ScriptedAction; scriptLines[i].InitFrom(info.scriptLines[i]); } // resolve any task sync cross references for (int j = 0; j<info.scriptLines.Length; j++){ if (scriptLines[j].syncToTasks != null && scriptLines[j].syncToTasks.Length > 0){ for (int k=0; k<scriptLines[j].syncToTasks.Length; k++){ scriptLines[j].syncToTasks[k] = scriptLines[scriptLines[j].syncToTasksIndex[k]]; } } } // public ScriptedAction.ScriptedActionInfo[] abortBranch; // the way out, if the user chooses not to complete this script // public ScriptedAction.ScriptedActionInfo[] errorBranch; // what to do if the script hangs, times out, encounters an error... owningRole = info.owningRole; roles = new List<string>(info.roles); // info.roles.CopyTo(roles); // roles = info.roles; // if null, then just one role for this script roleKeyString = info.roleKeyString; // enter this as a string in the editor, it gets parsed into a node tree on awake. autoExecuteInterval = info.autoExecuteInterval; autoExecuteProbability = info.autoExecuteProbability; AddToMenu = info.AddToMenu; menuOrder = info.menuOrder; interactionSet = info.interactionSet; commandVariation = info.commandVariation; // failsafe in case of blank Cmd but variations present, default to use trigger string or script name if (commandVariation != null && commandVariation.Cmd == "" && commandVariation.Variations.Count>0){ commandVariation.Cmd = name; // this is the convention we're using. Trigger string might contain multiples Debug.LogWarning(name+" was missing commandVariations.Cmd value "); } if (commandVariation != null && commandVariation.Cmd != null && commandVariation.Cmd != "") if (Application.isPlaying) FilterInteractions.GetInstance().AddVariation(commandVariation); callbackConfirmVoice = info.callbackConfirmVoice; item = info.item; prettyname = info.prettyname; response = info.response; response_title = info.response_title; note = info.note; tooltip = info.tooltip; sound = info.sound; task = info.task; log = info.log; readyState = info.readyState; // since an object reference is required to calc this, no getter. startPriority = info.startPriority; // 0 is the lowest cancellable = info.cancellable; skillVector = info.skillVector; extraCost = info.extraCost; prereq = info.prereq; category = info.category; param = info.param; debug = info.debug; // print out debug logging while running }
public InteractionScriptInfo ToInfo(InteractionScript script){ // saves values to an info for serialization (to XML) InteractionScriptInfo info = new InteractionScriptInfo(); info.unityObjectName = script.name; info.triggerStrings = script.triggerStrings; // the string that causes this script to start running info.triggerOnStatus = script.triggerOnStatus; // should we listen to InteractStatusMessages for our trigger ? info.startingArgs = script.startingArgs; info.scriptLines = new ScriptedAction.ScriptedActionInfo[script.scriptLines.Length]; for (int i = 0; i<script.scriptLines.Length; i++){ if (script.scriptLines[i] != null){ info.scriptLines[i] = script.scriptLines[i].ToInfo(script.scriptLines[i]); } else { Debug.Log("Script "+script.name+"contains null line at index "+i); #if UNITY_EDITOR EditorUtility.DisplayDialog("Save Failed","Script "+script.name+"contains null line at index "+i,"OK"); #endif } } // public ScriptedAction.ScriptedActionInfo[] abortBranch; // the way out, if the user chooses not to complete this script // public ScriptedAction.ScriptedActionInfo[] errorBranch; // what to do if the script hangs, times out, encounters an error... info.owningRole = script.owningRole; if (script.roles != null) info.roles = new List<string>(script.roles); // if null, then just one role for this script info.roleKeyString = script.roleKeyString; // enter this as a string in the editor, it gets parsed into a node tree on awake. info.autoExecuteInterval = script.autoExecuteInterval; info.autoExecuteProbability = script.autoExecuteProbability; info.AddToMenu = script.AddToMenu; info.menuOrder = script.menuOrder; info.interactionSet = script.interactionSet; info.commandVariation = script.commandVariation; info.callbackConfirmVoice = script.callbackConfirmVoice; info.item = script.item; info.prettyname = script.prettyname; info.response = script.response; info.response_title = script.response_title; info.note = script.note; info.tooltip = script.tooltip; info.sound = script.sound; info.task = script.task; info.log = script.log; info.readyState = script.readyState; // since an object reference is required to calc this, no getter. info.startPriority = script.startPriority; // 0 is the lowest info.cancellable = script.cancellable; info.skillVector = script.skillVector; info.extraCost = script.extraCost; info.prereq = script.prereq; info.category = script.category; info.param = script.param; info.debug = false; // always clear this when serializing.// print out debug logging while running return info; }