Пример #1
0
    void OnGUI()
    {
        EditorStyles.textField.wordWrap = true;
        GUI.enabled = !modalWindows.IsWindowOpen;

        if (Selection.activeGameObject == null)
        {
            return;
        }


        SpeechableCharacter personagem = (SpeechableCharacter)Selection.activeGameObject.GetComponent <SpeechableCharacter>();

        if (personagem != null)
        {
            OpenCharacterDialogEditor(personagem);
        }

        PistaItem pista = (PistaItem)Selection.activeGameObject.GetComponent <PistaItem>();

        if (pista != null)
        {
            OpenPistaDialogEditor(pista);
        }

        if (GUI.changed)
        {
            EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
        }

        BeginWindows();
        modalWindows.Draw();
        EndWindows();
    }
    public ScenarioData CreateScenarioData()
    {
        ScenarioData data = new ScenarioData();

        //Itera por todos os personagens
        foreach (Transform obj in personagens_folder.transform)
        {
            SpeechableCharacter character = obj.GetComponent <SpeechableCharacter>();
            data.characters.Add(character.data);
        }
        //Itera por todas as pistas
        foreach (Transform obj in pistas_folder.transform)
        {
            PistaItem pista = obj.GetComponent <PistaItem>();
            data.pistas.Add(pista.data);
        }
        //Itera por todos os exits
        foreach (Transform obj in exits_folder.transform)
        {
            data.exits.Add(obj.GetComponent <ExitPoint>().GetData());
        }

        return(data);
    }
Пример #3
0
    public void OpenCharacterDialog(SpeechableCharacter personagem)
    {
        GlobalProfile.getInstance().SaveGame();
        Cursor.SetCursor(null, hotSpot, CursorMode);
        gameObject.SetActive(true);
        personagens.SetActive(false);
        gui.SetActive(false);
        if (!minimap)
        {
            minimap = GameObject.Find("MinimapCanvas");
        }
        if (minimap)
        {
            minimap.SetActive(false);
        }
        characterImage.sprite = manager.textureManager.GetSpritePose(personagem.data.defaultImage);
        characterImage.color  = new Color(1, 1, 1, 1);
        canvasText.text       = "";
        charName.text         = "Detetive";
        //Abre o menu de botões

        if (buttonCanvas == null)
        {
            //Cria o grupo de botões de perguntas
            buttonCanvas = new GameObject("Buttons Canvas");
            RectTransform rect = buttonCanvas.AddComponent <RectTransform>();
            rect.anchorMin = new Vector2(.5f, .5f);
            rect.anchorMax = new Vector2(.5f, .5f);

            List <Dialogo> digs = personagem.AvailableDialogs();

            float margin = (digs.Count + 1) * 10;

            rect.offsetMin = new Vector2(-200, -15 * digs.Count - margin / 2f);
            rect.offsetMax = new Vector2(200, 15 * digs.Count + margin / 2f);

            for (int i = 0; i < digs.Count; i++)
            {
                //Cria cada botão
                Dialogo       dig     = digs[i];
                GameObject    btn     = new GameObject("Button " + i);
                RectTransform btnRect = btn.AddComponent <RectTransform>();

                btnRect.anchorMin = new Vector2(0, 1);
                btnRect.anchorMax = new Vector2(1, 1);
                btnRect.pivot     = new Vector2(.5f, 1);
                btnRect.offsetMin = new Vector2(0, -40 - 40 * i);
                btnRect.offsetMax = new Vector2(0, -10 - 40 * i);

                Button btn_btn = btn.AddComponent <Button>();
                Image  img     = btn.AddComponent <Image>();
                img.color             = dig.read ? Color.gray : Color.white;
                btn_btn.targetGraphic = img;
                img.sprite            = buttonUp;
                img.type           = Image.Type.Sliced;
                btn_btn.transition = Selectable.Transition.SpriteSwap;
                SpriteState ss = new SpriteState();
                ss.pressedSprite    = buttonDown;
                btn_btn.spriteState = ss;

                btn.transform.SetParent(buttonCanvas.transform, false);

                btn_btn.onClick.AddListener(() => {
                    OpenText(dig.texts);

                    GlobalProfile.getInstance().addItem(
                        new InventoryItem(
                            personagem.data.id,
                            personagem.data.displayName,
                            manager.textureManager.GetSpritePista(personagem.data.headBob),
                            personagem.data.description
                            ));

                    dig.read = true;
                    GlobalProfile.getInstance().SendMessage(dig.id);
                    manager.RefreshAllCharacterDialogData();
                });

                //Cria o texto do botão
                GameObject    btnText = new GameObject();
                RectTransform txtRect = btnText.AddComponent <RectTransform>();

                txtRect.anchorMin = new Vector2(0, 0);
                txtRect.anchorMax = new Vector2(1, 1);

                txtRect.offsetMin = new Vector2(0, 0);
                txtRect.offsetMax = new Vector2(0, 0);

                Text txt = btnText.AddComponent <Text>();
                txt.alignment = TextAnchor.MiddleCenter;
                txt.text      = dig.pergunta;
                txt.color     = new Color(0, 0, 0);
                txt.font      = font;
                btnText.transform.SetParent(btn.transform, false);
            }

            buttonCanvas.transform.SetParent(panelImage.gameObject.transform, false);
        }
    }
Пример #4
0
    public void OpenCharacterDialogEditor(SpeechableCharacter personagem)
    {
        personagem.speechCanvas = (SpeechManager)EditorGUILayout.ObjectField("Speech Canvas", personagem.speechCanvas, typeof(SpeechManager), true);
        personagem.manager      = (InspectionManager)EditorGUILayout.ObjectField("Manager", personagem.manager, typeof(InspectionManager), true);

        if (personagem.manager != null)
        {
            //Busca a lista
            string[] pistaKeys = personagem.manager.textureManager.getPistaKeys();
            string[] poseKeys  = personagem.manager.textureManager.getPoseKeys();

            //Icone
            int bobValue = EditorGUILayout.Popup("Ícone", personagem.manager.textureManager.getIndexByKeyPista(personagem.data.headBob), pistaKeys);
            personagem.data.headBob = pistaKeys[bobValue];
            GUI.DrawTexture(new Rect(0, 70, 100, 100), personagem.manager.textureManager.pistas[bobValue].sprite.texture);
            GUILayout.Space(120);

            //Pose
            int poseValue = EditorGUILayout.Popup("Pose padrão", personagem.manager.textureManager.getIndexByKeyPose(personagem.data.defaultImage), poseKeys);
            personagem.data.defaultImage = poseKeys[poseValue];
            GUI.DrawTexture(new Rect(0, 210, 100, 100), personagem.manager.textureManager.sprites[poseValue].sprite.texture);
            GUILayout.Space(120);

            personagem.data.displayName = EditorGUILayout.TextField("Nome", personagem.data.displayName);
            personagem.data.id          = EditorGUILayout.TextField("ID", personagem.data.id);
            GUILayout.Label("Descrição");
            personagem.data.description = EditorGUILayout.TextArea(personagem.data.description, GUILayout.Width(300));


            GUILayout.Label("Diálogos:");
            if (GUILayout.Button("Adicionar diálogo"))
            {
                Dialogo nd = new Dialogo(new List <TextData>(), "", "", true, false, "");

                //Modal para criar o diálogo
                var win = new ModalWindow(new Rect(30, 30, position.width - 60, position.height - 60), "CreateDialog", (w) =>
                {
                    nd.id       = EditorGUILayout.TextField("ID da Mensagem", nd.id);
                    nd.pergunta = EditorGUILayout.TextField("Pergunta", nd.pergunta);
                    nd.enabled  = EditorGUILayout.Toggle("Destravado", nd.enabled);
                    if (GUILayout.Button("OK"))
                    {
                        personagem.data.dialogos.Add(nd);
                        w.Close();
                    }
                    if (GUILayout.Button("Cancel"))
                    {
                        w.Close();
                    }
                    GUI.DragWindow();
                });
                modalWindows.Add(win);
            }

            if (personagem.data.dialogos == null)
            {
                personagem.data.dialogos = new List <Dialogo>();
            }

            scrollPerso = GUILayout.BeginScrollView(scrollPerso);

            for (int i = 0; i < personagem.data.dialogos.Count; i++)
            {
                GUILayout.BeginVertical("box");
                if (personagem.data.dialogos[i] == null)
                {
                    personagem.data.dialogos[i] = new Dialogo(new List <TextData>(), "", "", true, false, "");
                }
                GUILayout.BeginHorizontal("box");
                GUILayout.Label("Pergunta");
                personagem.data.dialogos[i].pergunta = EditorGUILayout.TextField(personagem.data.dialogos[i].pergunta);
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal("box");
                GUILayout.Label("ID da Mensagem");
                personagem.data.dialogos[i].id = EditorGUILayout.TextField(personagem.data.dialogos[i].id);
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal("box");
                GUILayout.Label("Mensagem de desbloqueio");
                personagem.data.dialogos[i].unlock_message = EditorGUILayout.TextField(personagem.data.dialogos[i].unlock_message);
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal("box");
                if (GUILayout.Button("Editar"))
                {
                    //Modal pra editar cada texto do diálogo:
                    Dialogo dig = personagem.data.dialogos[i];
                    var     win = new ModalWindow(new Rect(30, 30, position.width - 60, position.height - 60), "Edit Dialog", (w) =>
                    {
                        dig.enabled = EditorGUILayout.Toggle("Destravado", dig.enabled);
                        if (GUILayout.Button("Adicionar Texto"))
                        {
                            dig.texts.Add(new TextData());
                        }
                        scrollDig = GUILayout.BeginScrollView(scrollDig);

                        for (int j = 0; j < dig.texts.Count; j++)
                        {
                            GUILayout.BeginVertical("box");
                            GUILayout.Label("Texto " + j, EditorStyles.boldLabel);
                            dig.texts[j].texto = EditorGUILayout.TextArea(dig.texts[j].texto, GUILayout.Width(350));

                            dig.texts[j].owner = EditorGUILayout.TextField("Quem tá falando", dig.texts[j].owner);

                            int index = personagem.manager.textureManager.getIndexByKeyPose(dig.texts[j].image);
                            if (index == -1)
                            {
                                index = 0;
                            }
                            int digValue       = EditorGUILayout.Popup("Imagem", index, poseKeys);
                            dig.texts[j].image = poseKeys[digValue];

                            if (GUILayout.Button("Remover"))
                            {
                                dig.texts.Remove(dig.texts[j]);
                            }

                            GUILayout.EndVertical();

                            GUILayout.Space(10);
                        }
                        GUILayout.EndScrollView();

                        if (GUILayout.Button("Fechar"))
                        {
                            w.Close();
                        }

                        GUI.DragWindow();
                    });
                    modalWindows.Add(win);
                }
                if (GUILayout.Button("Remover"))
                {
                    personagem.data.dialogos.Remove(personagem.data.dialogos[i]);
                }
                GUILayout.EndHorizontal();
                GUILayout.EndVertical();
                GUILayout.Space(10);
            }
            GUILayout.EndScrollView();
        }
    }