public GameMsgFormInfo ToInfo(GameMsgForm gmf){ // saves values to an info for serialization (to XML) GameMsgFormInfo info = new GameMsgFormInfo(); info.msgType = gmf.msgType; // type of message to construct from this form info.gameObjectName = gmf.gameObjectName; info.log = gmf.log; // interact status message info.interactName = gmf.interactName; // dialog message info.command = gmf.command; info.x = gmf.x; info.y = gmf.y; info.w = gmf.w; info.h = gmf.h; info.text = gmf.text; info.title = gmf.title; info.time = gmf.time; info.modal = gmf.modal; info.xmlName = gmf.xmlName; info.className = gmf.className; info.dialogName = gmf.dialogName; info.waitForDialogClosed = gmf.waitForDialogClosed; info.waitForDialogName = gmf.waitForDialogName; info.anchor = gmf.anchor; info.arguments = gmf.arguments; info.numArguments = gmf.numArguments; //quickinfomsg info.timeout = gmf.timeout; info.editbox = gmf.editbox; info.editboxlabel = gmf.editboxlabel; info.editboxprompt = gmf.editboxprompt; info.sendMap = gmf.sendMap; //interact dialog info.items = gmf.items; //info.baseobj = gmf.baseobj; info.baseXML = gmf.baseXML; //popupmsg info.hasCancel = gmf.hasCancel; info.commandString = gmf.commandString; info.Params = gmf.Params; // used for interact status message // GUIScreenMsg info.ScreenName = gmf.ScreenName; return info; }
public void ShowInspectorGUI(string GUIlabel){ // should probably return the dirty bit from here... // lets extend this, to show only the fields required by the selected action type. // that will make it a lot friendlier in the editor if (serializedObject == null) serializedObject = new SerializedObject(this); EditorGUI.BeginChangeCheck(); type = (actionType)EditorGUILayout.EnumPopup("Action type",(System.Enum)type); if (type == actionType.enableInteraction){ objectToAffect = (GameObject)EditorGUILayout.ObjectField("objectToAffect",objectToAffect,typeof(GameObject),true); if (objectName == null) objectName = ""; objectName = EditorGUILayout.TextField("objectName",objectName); stringParam = EditorGUILayout.TextField("InteractionTAG",stringParam);// used for a lot of different things negate = EditorGUILayout.Toggle("disable",negate); // use to turn enable to disable, stop audio, etc. loop = EditorGUILayout.Toggle("append",loop); texture2D = (Texture2D)EditorGUILayout.ObjectField("iconTexture",texture2D,typeof(Texture2D),true); ease = EditorGUILayout.Toggle("remove icon",ease); // hackfully abuse this boolean } if (type == actionType.playAudio){ objectToAffect = (GameObject)EditorGUILayout.ObjectField("objectToPlay",objectToAffect,typeof(GameObject),true); if (objectName == null) objectName = ""; objectName = EditorGUILayout.TextField("objectName",objectName); if (stringParam == null) stringParam = ""; stringParam = EditorGUILayout.TextField("MappedSoundName",stringParam);// used for a lot of different things audioClip = (AudioClip)EditorGUILayout.ObjectField("audioClip",audioClip,typeof(AudioClip),true); fadeLength = EditorGUILayout.FloatField("delay After",fadeLength); if (stringParam2 == null) stringParam2 = ""; stringParam2 = EditorGUILayout.TextField("LookAt",stringParam2); // fadeLength = EditorGUILayout.FloatField("fadeLength",fadeLength); // also used for wait, move // ease = EditorGUILayout.Toggle("ease",ease); // ease or linear movement/fade negate = EditorGUILayout.Toggle("stop",negate); // use to turn enable to disable, stop audio, etc. loop = EditorGUILayout.Toggle("loop",loop); } if (type == actionType.playAnimation){ objectToAffect = (GameObject)EditorGUILayout.ObjectField("objectToAnimate",objectToAffect,typeof(GameObject),true); if (objectName == null) objectName = ""; objectName = EditorGUILayout.TextField("objectName",objectName); if (stringParam == null) stringParam = ""; stringParam = EditorGUILayout.TextField("animation",stringParam);// used for a lot of different things if (eventScript == null) eventScript = ""; eventScript = EditorGUILayout.TextField("eventScript",eventScript); // fadeLength = EditorGUILayout.FloatField("fadeLength",fadeLength); // also used for wait, move // desiredAlpha = EditorGUILayout.FloatField("desiredAlpha",desiredAlpha); loop = EditorGUILayout.Toggle("loop",loop); } if (type == actionType.putMessage){ objectToAffect = (GameObject)EditorGUILayout.ObjectField("objectToAffect",objectToAffect,typeof(GameObject),true); if (objectName == null) objectName = ""; objectName = EditorGUILayout.TextField("objectName",objectName); fadeLength = EditorGUILayout.FloatField("delay",fadeLength); // see about adding local gameMessage to use in this script if (gameMsgForm == null){ gameMsgForm = gameObject.AddComponent<GameMsgForm>();//gameObject.AddComponent<GameMsgForm>(); // could just do this when we know we'll need one... gameMsgForm.map = gameObject.AddComponent<InteractionMapForm>(); //gameObject.AddComponent<InteractionMapForm>(); EditorUtility.SetDirty(this); } else { if (gameMsgForm.ShowInspectorGUI()) EditorUtility.SetDirty(this); } if (gameMsgForm.msgType==GameMsgForm.eMsgType.dialogMsg) dialogIfThen = EditorGUILayout.Toggle("Treat As If-Then-Else",dialogIfThen); // stringParam = EditorGUILayout.TextField("message tag",stringParam);// used for a lot of different things } if (type == actionType.move){ objectToAffect = (GameObject)EditorGUILayout.ObjectField("objectToMove",objectToAffect,typeof(GameObject),true); if (objectName == null) objectName = ""; objectName = EditorGUILayout.TextField("objectName",objectName); fadeLength = EditorGUILayout.FloatField("moveTime",fadeLength); // also used for wait, move moveTo = (Transform)EditorGUILayout.ObjectField("moveTo",moveTo,typeof(Transform),true); if (moveToName == null) moveToName = ""; moveToName = EditorGUILayout.TextField("moveToName",moveToName); offset = EditorGUILayout.Vector3Field("offset",offset); // in moveTo reference frame ease = EditorGUILayout.Toggle("ease",ease); // ease or linear movement/fade } if (type == actionType.fade){ objectToAffect = (GameObject)EditorGUILayout.ObjectField("objectToAffect",objectToAffect,typeof(GameObject),true); if (objectName == null) objectName = ""; objectName = EditorGUILayout.TextField("objectName",objectName); // stringParam = EditorGUILayout.TextField("stringParam",stringParam);// used for a lot of different things fadeLength = EditorGUILayout.FloatField("fadeLength",fadeLength); // also used for wait, move desiredAlpha = EditorGUILayout.FloatField("desiredAlpha",desiredAlpha); desiredColor = EditorGUILayout.ColorField("desiredColor",desiredColor); if (stringParam == null) stringParam = ""; stringParam = EditorGUILayout.TextField("New Matl or Mesh",stringParam); ease = EditorGUILayout.Toggle("ease",ease); // ease or linear movement/fade } if (type == actionType.ifThenElse){ objectToAffect = (GameObject)EditorGUILayout.ObjectField("objectToTest",objectToAffect,typeof(GameObject),true); if (objectName == null) objectName = ""; objectName = EditorGUILayout.TextField("objectName",objectName); if (stringParam == null) stringParam = ""; stringParam = ValidateConditionalString("attribute conditional",stringParam);// used for a lot of different things } if (type == actionType.executeScript){ objectToAffect = (GameObject)EditorGUILayout.ObjectField("objectToExecute",objectToAffect,typeof(GameObject),true); if (objectName == null) objectName = ""; objectName = EditorGUILayout.TextField("objectName",objectName); scriptToExecute = (InteractionScript)EditorGUILayout.ObjectField("scriptToExecute",scriptToExecute,typeof(InteractionScript),true); if (scriptToExecute != null) stringParam2 = scriptToExecute.name; if (stringParam2 == null) stringParam2 = ""; stringParam2 = EditorGUILayout.TextField("script name",stringParam2); if (stringParam == null) stringParam = ""; stringParam = EditorGUILayout.TextField("args",stringParam);// used for a lot of different things ease = EditorGUILayout.Toggle("pass args",ease); // reused boolean } if (type == actionType.queueScript){ objectToAffect = (GameObject)EditorGUILayout.ObjectField("objectToExecute",objectToAffect,typeof(GameObject),true); if (objectName == null) objectName = ""; objectName = EditorGUILayout.TextField("objectName",objectName); scriptToExecute = (InteractionScript)EditorGUILayout.ObjectField("scriptToExecute",scriptToExecute,typeof(InteractionScript),true); if (scriptToExecute != null) stringParam2 = scriptToExecute.name; if (stringParam2 == null) stringParam2 = ""; stringParam2 = EditorGUILayout.TextField("script name",stringParam2); if (stringParam == null) stringParam = ""; stringParam = EditorGUILayout.TextField("args",stringParam);// used for a lot of different things ease = EditorGUILayout.Toggle("pass args",ease); // reused boolean loop = EditorGUILayout.Toggle("check to flush",loop); // reused boolean if (loop) stringParam2 = ""; //flush takes empty script } if (type == actionType.wait){ if (stringParam == null) stringParam = ""; stringParam = ValidateConditionalString("wait Condition",stringParam); if (stringParam != "" && stringParam != null) fadeLength = EditorGUILayout.FloatField("Timeout Value",fadeLength); else fadeLength = EditorGUILayout.FloatField("wait Time",fadeLength); // also used for wait, move if (preAttributes!="" || postAttributes != "" || stringParam != ""){ objectToAffect = (GameObject)EditorGUILayout.ObjectField("object for Attributes",objectToAffect,typeof(GameObject),true); if (objectName == null) objectName = ""; objectName = EditorGUILayout.TextField("object Name for attributes",objectName); } loop = EditorGUILayout.Toggle("Hold Position",loop); // reused boolean } if (type == actionType.characterTask){ objectToAffect = (GameObject)EditorGUILayout.ObjectField("characterToAffect",objectToAffect,typeof(GameObject),true); if (objectName == null) objectName = ""; objectName = EditorGUILayout.TextField("characterName",objectName); if (moveToName == null) moveToName = ""; moveToName = EditorGUILayout.TextField("Position",moveToName);// used for a lot of different things if (stringParam == null) stringParam = ""; stringParam = EditorGUILayout.TextField("Posture",stringParam); if (stringParam2 == null) stringParam2 = ""; stringParam2 = EditorGUILayout.TextField("LookAt",stringParam2); if (stringParam3 == null) stringParam3 = ""; stringParam3 = EditorGUILayout.TextField("Animation",stringParam3); fadeLength = EditorGUILayout.FloatField("delay",fadeLength); if (voiceTag == null) voiceTag = ""; voiceTag = EditorGUILayout.TextField("voiceTag",voiceTag); if (stringParam4 == null) stringParam4 = ""; stringParam4 = EditorGUILayout.TextField(":COMPLETE msg?",stringParam4); heading = EditorGUILayout.FloatField("Heading",heading); speed = EditorGUILayout.FloatField ("Speed",speed); if (attachmentOverride == null) attachmentOverride = ""; attachmentOverride = EditorGUILayout.TextField("attachmentOverride",attachmentOverride); if (eventScript == null) eventScript = ""; eventScript = EditorGUILayout.TextField("eventScript",eventScript); // I had no idea how to write this, but thanks to Unity forums, here is a nice Array custom inspector! serializedObject.Update(); EditorGUIUtility.LookLikeInspector(); SerializedProperty myIterator = serializedObject.FindProperty("syncToTasks"); while (true){ Rect myRect = GUILayoutUtility.GetRect(0f, 16f); bool showChildren = EditorGUI.PropertyField(myRect, myIterator); if (!myIterator.NextVisible(showChildren)) break; } serializedObject.ApplyModifiedProperties() ; EditorGUIUtility.LookLikeControls(); // end of Thanks to the Forums for the code! } if (type == actionType.attach){ negate = EditorGUILayout.Toggle("check for DETACH",negate); objectToAffect = (GameObject)EditorGUILayout.ObjectField("objectToAffect",objectToAffect,typeof(GameObject),true); if (objectName == null) objectName = ""; objectName = EditorGUILayout.TextField("objectName",objectName); if (attachmentOverride == null) attachmentOverride = ""; if (negate) attachmentOverride = EditorGUILayout.TextField("reparentOverride",attachmentOverride); else attachmentOverride = EditorGUILayout.TextField("target parent Override",attachmentOverride); offset = EditorGUILayout.Vector3Field("offset",offset); orientation = EditorGUILayout.Vector3Field("orientation",orientation); fadeLength = EditorGUILayout.FloatField("lerpTime",fadeLength); // stringParam = EditorGUILayout.TextField("parent name",stringParam);// used for a lot of different things } if (type == actionType.spawn){ objectToAffect = (GameObject)EditorGUILayout.ObjectField("SpawnLocationObject",objectToAffect,typeof(GameObject),true); if (objectName == null) objectName = ""; objectName = EditorGUILayout.TextField("LocationObjectName",objectName); if (stringParam == null) stringParam = ""; stringParam = EditorGUILayout.TextField("template",stringParam);// used for a lot of different things if (stringParam2 == null) stringParam2 = ""; stringParam2 = EditorGUILayout.TextField("newName",stringParam2); if (stringParam3 == null) stringParam3 = ""; stringParam3 = EditorGUILayout.TextField("newParent?",stringParam3); // loop = EditorGUILayout.Toggle("attach To Location?",loop); offset = EditorGUILayout.Vector3Field("attach offset",offset); } if (type == actionType.destroy){ objectToAffect = (GameObject)EditorGUILayout.ObjectField("objectToAffect",objectToAffect,typeof(GameObject),true); if (objectName == null) objectName = ""; objectName = EditorGUILayout.TextField("objectName",objectName); } if (type == actionType.unityMessage){ objectToAffect = (GameObject)EditorGUILayout.ObjectField("objectToAnimate",objectToAffect,typeof(GameObject),true); if (objectName == null) objectName = ""; objectName = EditorGUILayout.TextField("objectName",objectName); if (stringParam == null) stringParam = ""; stringParam = EditorGUILayout.TextField("method",stringParam);// used for a lot of different things if (stringParam2 == null) stringParam2 = ""; stringParam2 = EditorGUILayout.TextField("argumentString",stringParam2);// used for a lot of different things } if (type == actionType.lockPosition){ objectToAffect = (GameObject)EditorGUILayout.ObjectField("objectToLock",objectToAffect,typeof(GameObject),true); if (objectName == null) objectName = ""; objectName = EditorGUILayout.TextField("objectName",objectName); if (stringParam == null) stringParam = ""; stringParam = EditorGUILayout.TextField("lockScriptPriority",stringParam);// used for a lot of different things negate = EditorGUILayout.Toggle("check for UNLOCK",negate); } if (type == actionType.goToLine){ if (stringParam == null) stringParam = ""; stringParam = EditorGUILayout.TextField("abort or line#",stringParam); GUILayout.Label("BE CAREFUL WITH THOSE LINE NUMBERS!"); } if (type == actionType.setIKTarget){ objectToAffect = (GameObject)EditorGUILayout.ObjectField("taskCharacter",objectToAffect,typeof(GameObject),true); if (objectName == null) objectName = ""; objectName = EditorGUILayout.TextField("taskCharacterName",objectName); if (moveToName == null) moveToName = ""; moveToName = EditorGUILayout.TextField("targetName",moveToName);// used for a lot of different things if (stringParam == null) stringParam = ""; stringParam = EditorGUILayout.TextField("Left or Right",stringParam); fadeLength = EditorGUILayout.FloatField("blendTime",fadeLength); offset = EditorGUILayout.Vector3Field("offset",offset); orientation = EditorGUILayout.Vector3Field("orientation",orientation); if (stringParam2 == null) stringParam2 = "0"; stringParam2 = EditorGUILayout.TextField("Hold Time",stringParam2); } GUILayout.Space(10); if (comment == null) comment = ""; comment = EditorGUILayout.TextField("comment",comment); if (preAttributes == null) preAttributes = ""; preAttributes = EditorGUILayout.TextField("preAttributes",preAttributes); // set when line starts if (postAttributes == null) postAttributes = ""; postAttributes = EditorGUILayout.TextField("postAttributes",postAttributes); // set when line completes block = (blockType)EditorGUILayout.EnumPopup("IfThenElse bracket",(System.Enum)block); SetNamePrefix(block); executeOnlyOnce = EditorGUILayout.Toggle("executeOnlyOnce",executeOnlyOnce); waitForCompletion = EditorGUILayout.Toggle("waitForCompletion",waitForCompletion); sequenceEnd = EditorGUILayout.Toggle("sequenceEnd",sequenceEnd); breakpoint = EditorGUILayout.Toggle("debug breakpoint",breakpoint); bool dirty = EditorGUI.EndChangeCheck(); if (dirty){ if (objectToAffect != null && objectName == ""){ // default, or we could try looking up the name again... objectName = objectToAffect.name; } if (moveTo != null && moveToName == ""){ // default, or we could try looking up the name again... moveToName = moveTo.name; } if (scriptToExecute != null && stringParam2 == ""){ // default, or we could try looking up the name again... stringParam2 = scriptToExecute.name; } EditorUtility.SetDirty(this); } /* cut and paste reference for new inspector types * objectToAffect = (GameObject)EditorGUILayout.ObjectField("objectToAffect",objectToAffect,typeof(GameObject)); objectName = EditorGUILayout.TextField("objectName",objectName); stringParam = EditorGUILayout.TextField("stringParam",stringParam);// used for a lot of different things audioClip = (AudioClip)EditorGUILayout.ObjectField("audioClip",audioClip,typeof(AudioClip)); fadeLength = EditorGUILayout.FloatField("fadeLength",fadeLength); // also used for wait, move desiredAlpha = EditorGUILayout.FloatField("desiredAlpha",desiredAlpha); desiredColor = EditorGUILayout.ColorField("desiredColor",desiredColor); moveTo = (Transform)EditorGUILayout.ObjectField("moveTo",moveTo,typeof(Transform)); ease = EditorGUILayout.Toggle("ease",ease); // ease or linear movement/fade negate = EditorGUILayout.Toggle("negate",negate); // use to turn enable to disable, stop audio, etc. loop = EditorGUILayout.Toggle("loop",loop); waitForCompletion = EditorGUILayout.Toggle("waitForCompletion",waitForCompletion); executeOnlyOnce = EditorGUILayout.Toggle("executeOnlyOnce",executeOnlyOnce); ifBranch = EditorGUILayout.TextField("ifBranch",ifBranch); elseBranch = EditorGUILayout.TextField("elseBranch",elseBranch); */ /* if (GUILayout.Button("SERIALIZE")){ // ScriptedActionInfo info = ToInfo (this); ScriptedObject pop = this.transform.parent.parent.GetComponent<ScriptedObject>(); ScriptedObject.ScriptedObjectInfo info = pop.ToInfo (pop); XmlSerializer serializer = new XmlSerializer(typeof(ScriptedObject.ScriptedObjectInfo)); FileStream stream = new FileStream("TESTSOSERIAL.xml", FileMode.Create); serializer.Serialize(stream, info); stream.Close(); } */ }
public void InitFrom(ScriptedActionInfo info){ // initialize members from deserialized info gameObject.name = info.unityObjectName; comment = info.comment; objectName = info.objectName; type = info.type; role = info.role; // in a multi-role script, which role performs this action stringParam = info.stringParam; // used for a lot of different things //info.audioClipName = sa.audioClipName; fadeLength = info.fadeLength; // also used for wait, move desiredAlpha = info.desiredAlpha; desiredColor = info.desiredColor; // public Texture2Dname texture2D = null; // used for enableInteraction; // public Transform moveTo; moveToName = info.moveToName; offset = info.offset; // offset from transform for move, in transform's reference frame orientation = info.orientation; // if (info.scriptToExecuteName != null && info.scriptToExecuteName){ // this probably need a redesign, where the search occurs at Start() time, since the script // info.scriptToExecuteName = scriptToExecute.name; // } ease = info.ease; negate = info.negate; // use to turn enable to disable, stop audio, etc. loop = info.loop; waitForCompletion = info.waitForCompletion; // signal complete after audio, fade, etc. sequenceEnd = info.sequenceEnd; executeOnlyOnce = info.executeOnlyOnce; block = info.block; dialogIfThen = info.dialogIfThen; breakpoint = info.breakpoint; preAttributes = info.preAttributes; // processed when the line is begun postAttributes = info.postAttributes; // processed when the line completes stringParam2 = info.stringParam2; stringParam3 = info.stringParam3; stringParam4 = info.stringParam4; attachmentOverride = info.attachmentOverride; eventScript = info.eventScript; voiceTag = info.voiceTag; heading = info.heading; speed = info.speed; if (info.gameMsgFormInfo != null){ gameMsgForm = gameObject.AddComponent<GameMsgForm>(); gameMsgForm.InitFrom(info.gameMsgFormInfo); // info.gameMsg = sa.gameMsgForm.ToGameMsg(this); // how to handle message subclasses ? if (info.map != null){ gameMsgForm.map = gameObject.AddComponent<InteractionMapForm>(); gameMsgForm.map.InitFromMap(info.map); } } syncToTasksIndex = info.syncToTasksIndex; if (syncToTasksIndex != null) syncToTasks = new ScriptedAction[syncToTasksIndex.Length]; // will init when script is fully loaded. else syncToTasks = new ScriptedAction[0]; }
IEnumerator WaitForDialogClosed( ScriptedAction action, GameMsgForm form ) { UnityEngine.Debug.LogWarning("ScriptedAction.WaitForDialogClosed() : <" + form.xmlName + "> is waiting for dialog <" + form.waitForDialogName + ">"); // waitForDialogName is a CSV string with dialog names while( hasDialog(form.waitForDialogName) ) yield return new WaitForSeconds(.1f); UnityEngine.Debug.LogWarning("ScriptedAction.WaitForDialogClosed() : <" + form.xmlName + "> is waiting for dialog <" + form.waitForDialogName + "> done!"); form.PutMessage (action); if (waitForCompletion) { // if ( form.msgType == GameMsgForm.eMsgType.dialogMsg ) // It seems like this will always be true in this co routine ? waitingForDialog = true; // else // StartCoroutine(CompleteAfterDelay(form.time)); } else OnComplete (); Cleanup (); }