Example #1
0
    public void SaveFaction()
    {
        if ((faction.factionName != null) && (faction.playerName != null) && (faction.voice != VoiceType.COUNT) && (faction.style != FactionStyle.COUNT) && (faction.attribute != Attribute.COUNT))
        {
            Debug.Log("You can move on to faction screen");
            createFactionPanel.SetActive(false);
            factionPanel.SetActive(true);
            FactionData.ExportJSON(faction, faction.factionName + ".json");
            GameObject newButton = Instantiate(buttonprefab);
            newButton.transform.SetParent(content.transform);
            newButton.GetComponent <Button>().onClick.AddListener(delegate { factionScript.FactionSelection(newButton.GetComponent <Button>()); });
            newButton.transform.localScale = new Vector3(1, 1, 1);
            content.sizeDelta = new Vector2(content.rect.width, content.rect.height + 20);

            for (int i = 0; i < newButton.transform.childCount; i++)
            {
                Transform child      = newButton.transform.GetChild(i);
                Image     childImage = null;
                Debug.Log(child.name);
                if ((childImage = child.GetComponent <Image>()) != null)
                {
                    if (child.name == "Pic")
                    {
                        childImage.GetComponent <Image>().sprite = faction.playerPortrait;
                    }
                    if (child.name == "FoodPic")
                    {
                        switch (faction.style)
                        {
                        case FactionStyle.AMERICAN:
                            child.gameObject.GetComponent <Image>().sprite = burgerSprite;
                            break;

                        case FactionStyle.ITALIAN:
                            child.gameObject.GetComponent <Image>().sprite = pizzaSprite;
                            break;

                        case FactionStyle.MEXICAN:
                            child.gameObject.GetComponent <Image>().sprite = tacoSprite;
                            break;
                        }
                    }
                }
            }

            newButton.GetComponentInChildren <Text>().text = faction.factionName;

            factionScript.ResetFactionCreation();
        }
        else
        {
            Debug.Log("You can't move on");
        }
    }