public override void OnGUI()
    {
        if(!IsVisible())
            return;

        Texture2D texture;
        base.OnGUI();

        float x = Screen.width * 0.5f - 300;
        float y = Screen.height * 0.5f - 190;
        float width = 600;
        float height = 420;

        // Render background
        GUILayout.BeginArea(new Rect(x, y, width, height), skin.box);
        {
            // Render title
            GUILayout.Label(dialogueTitle, skin.customStyles[1], GUILayout.MaxWidth(width));

            // Render NPC dialogue
            GUILayout.BeginHorizontal();
            {
                // Render NPC picture
                GUILayout.BeginVertical();
                {
                    texture = DialogueTree.Instance.GetProfileImage(image);
                    if (texture != null)
                        GUILayout.Label(texture, skin.label);
                }
                GUILayout.EndVertical();

                // Render text
                float textWidth = width - (texture.width + skin.label.border.top + skin.label.border.bottom + skin.scrollView.border.left + skin.scrollView.border.right);
                float textHeight = skin.label.border.top + skin.label.border.bottom + texture.height;
                scrollPositionDialogue = GUILayout.BeginScrollView(scrollPositionDialogue, false, false, skin.horizontalScrollbar, skin.verticalScrollbar, skin.label, GUILayout.MaxWidth(textWidth), GUILayout.MaxHeight(textHeight));
                {
                    // Render dialogue
                    //GUILayout.Space(10);
                    GUILayout.Label(displayDialogue, skin.customStyles[0]);
                }
                GUILayout.EndScrollView();
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(3);

            // Render PC choices
            GUILayout.BeginVertical();
            {
                scrollPositionOptions = GUILayout.BeginScrollView(scrollPositionOptions, false, false, skin.horizontalScrollbar, skin.verticalScrollbar, skin.label);
                {
                    // Render option buttons
                    for (int i = 0; i < options.Length; i++)
                    {
                        if (options[i] != null && options[i].text.Length > 0 && !(options[i].visited && options[i].clearOnVisited))
                        {
                            // Render option 1
                            if (GUILayout.Button(options[i].text, skin.button) || CommandOption == i )
                            {
                                // reset command option
                                CommandOption = -1;

                                Brain.GetInstance().StopVocals();
                                // play special audio or click if nothing here
                                if (options[i].audio != null)
                                    Brain.GetInstance().PlayAudio(options[i].audio);
                                else
                                    Brain.GetInstance().PlayAudio("GENERIC:CLICK");

                                options[i].visited = true;

                                // Log dialogue result.
                                if(!(displayDialogue.Length == 0 && options[i].text == "Next"))
                                    LogMgr.GetInstance().Add(new DialogueLogItem(Time.time, dialogueTitle, options[i].text, options[i].correctAnswer));

                                // Report titled dialogues to brain
                                if (title.Length > 0)
                                    DialogueTree.Instance.ReportDialogue(title, i, options[i].correctAnswer);

                                // Report InteractMsg
                                if (options[i].interactMsg != null && options[i].interactMsg.Length > 0)
                                {
                                    InteractMsg iMsg = new InteractMsg(this.gameObject, options[i].interactMsg);
                                    // log it
                                    InteractLogItem logitem = new InteractLogItem(Time.time, this.name, iMsg.map.item, StringMgr.GetInstance().Get(iMsg.map.response),iMsg);
                                    if (iMsg.log == true)
                                        LogMgr.GetInstance().Add(logitem);
                                    // send to brain
                                    Brain.GetInstance().PutMessage(iMsg);
                                }

                                if (options[i].goToID == -1)
                                {
                                    // End dialogue
                                    DialogueTree.Instance.EndActiveDialogue();
                                }
                                else if (options[i].goToID >= 0)
                                {
                                    // Move to next dialogue
                                    DialogueTree.Instance.GoToDialogue(options[i].goToID, false);
                                }
                            }
                        }
                    }
                }
                GUILayout.EndScrollView();
            }
            GUILayout.EndVertical();
        }
        GUILayout.EndArea();

    }
    virtual public void HandleInteractMsg(string name, InteractMsg interactMsg)
    {
		if ( interactMsg == null || interactMsg.map == null )
			return;
		
        // translate
        string response = Translate(interactMsg.map.response);
        // log interaction
        if (interactMsg.log == true)
        {
            InteractLogItem logitem = new InteractLogItem(Time.time, interactMsg.gameObject, interactMsg.map.item, StringMgr.GetInstance().Get(response), interactMsg);
            LogMgr.GetInstance().Add(logitem);
        }
    }
    public InteractMsg SendInteractionMap(string objname, InteractionMap map)
    {
        InteractMsg imsg = new InteractMsg(null, map);

        // log it
        if (map.log == true)
        {
            InteractLogItem logitem = new InteractLogItem(Time.time, objname, imsg.map.item, StringMgr.GetInstance().Get(imsg.map.response), imsg);
            LogMgr.GetInstance().Add(logitem);
        }

        // send to brain
        Brain.GetInstance().PutMessage(imsg);

        return imsg;
    }