Esempio n. 1
0
 // Update is called once per frame
 void OnMouseDown()
 {
     if (!PauseUI.Paused)
     {
         if (!speech.isActiveAndEnabled)
         {
             //Adicionar ao inventário
             //Abrir um texto
             GlobalProfile.getInstance().addItem(new InventoryItem(data.itemId, data.displayName, spriteRenderer.sprite, data.itemDescription));
             //Destruir item
             Debug.Log("Adding item with sprite: " + spriteRenderer.sprite.texture.name);
             GlobalProfile.getInstance().SendMessage(data.itemId);
             GlobalProfile.getInstance().SaveInventory();
             manager.RefreshAllCharacterDialogData();
             speech.OpenText(data.dialogo.texts);
             Destroy(gameObject);
         }
     }
 }
Esempio n. 2
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);
        }
    }