Beispiel #1
0
    // Use this for initialization
    void Start()
    {
        BuildModeController bmc = GameObject.FindObjectOfType <BuildModeController>();

        // For each furniture prototype in our world, create one instance
        // of the button to be clicked

        foreach (string s in World.Current.furniturePrototypes.Keys)
        {
            GameObject go = (GameObject)Instantiate(buildFurnitureButtonPrefab);
            go.transform.SetParent(this.transform);

            string objectId   = s;
            string objectName = World.Current.furniturePrototypes[s].Name;

            go.name = "Button - Build " + objectId;
            go.transform.GetComponentInChildren <TextLocalizer>().formatValues =
                new string[] { LocalizationTable.GetLocalization(World.Current.furniturePrototypes[s].LocalizationCode) };

            Button b = go.GetComponent <Button>();
            b.onClick.AddListener(delegate { bmc.SetMode_BuildFurniture(objectId); });
        }

        lastLanguage = LocalizationTable.currentLanguage;
    }
Beispiel #2
0
    // Use this for initialization
    void Start()
    {
        BuildModeController bmc = GameObject.FindObjectOfType <BuildModeController>();

        // For each furniture prototype in our world, create one instance
        // of the button to be clicked!


        foreach (string s in World.current.furniturePrototypes.Keys)
        {
            GameObject go = (GameObject)Instantiate(buildFurnitureButtonPrefab);
            go.transform.SetParent(this.transform);

            string objectId   = s;
            string objectName = World.current.furniturePrototypes[s].Name;

            go.name = "Button - Build " + objectId;

            go.transform.GetComponentInChildren <Text>().text = "Build " + objectName;

            Button b = go.GetComponent <Button>();

            b.onClick.AddListener(delegate { bmc.SetMode_BuildFurniture(objectId); });
        }
    }
    private void RenderFurnitureButtons()
    {
        furnitureItems = new List <GameObject>();

        UnityEngine.Object buttonPrefab     = Resources.Load("UI/MenuLeft/ConstructionMenu/Button");
        Transform          contentTransform = this.transform.FindChild("Scroll View").FindChild("Viewport").FindChild("Content");

        BuildModeController buildModeController = WorldController.Instance.buildModeController;

        // For each furniture prototype in our world, create one instance
        // of the button to be clicked!
        foreach (string furnitureKey in PrototypeManager.Furniture.Keys)
        {
            if (PrototypeManager.Furniture.Get(furnitureKey).HasTypeTag("Non-buildable") && showAllFurniture == false)
            {
                continue;
            }

            GameObject gameObject = (GameObject)Instantiate(buttonPrefab);
            gameObject.transform.SetParent(contentTransform);
            furnitureItems.Add(gameObject);

            Furniture proto    = PrototypeManager.Furniture.Get(furnitureKey);
            string    objectId = furnitureKey;

            gameObject.name = "Button - Build " + objectId;

            gameObject.transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[] { LocalizationTable.GetLocalization(proto.LocalizationCode) };

            Button button = gameObject.GetComponent <Button>();

            button.onClick.AddListener(delegate
            {
                buildModeController.SetMode_BuildFurniture(objectId);
                menuLeft.CloseMenu();
            });

            // http://stackoverflow.com/questions/1757112/anonymous-c-sharp-delegate-within-a-loop
            string furniture = furnitureKey;
            LocalizationTable.CBLocalizationFilesChanged += delegate
            {
                gameObject.transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[] { LocalizationTable.GetLocalization(PrototypeManager.Furniture.Get(furniture).LocalizationCode) };
            };

            Image image = gameObject.transform.GetChild(0).GetComponentsInChildren <Image>().First();
            image.sprite = WorldController.Instance.furnitureSpriteController.GetSpriteForFurniture(furnitureKey);
        }
    }
    private void GenerateMenuButtons()
    {
        BuildModeController bmc = WorldController.Instance.buildModeController;

        buildMenu = new List <GameObject>();

        // For each furniture prototype in our world, create one instance
        // of the button to be clicked!
        foreach (string furnitureKey in PrototypeManager.Furniture.Keys)
        {
            if (PrototypeManager.Furniture.Get(furnitureKey).HasTypeTag("Non-buildable") && showAllFurniture == false)
            {
                continue;
            }

            GameObject gameObject = (GameObject)Instantiate(buildFurnitureButtonPrefab);
            gameObject.transform.SetParent(this.transform);
            buildMenu.Add(gameObject);

            Furniture proto    = PrototypeManager.Furniture.Get(furnitureKey);
            string    objectId = furnitureKey;

            gameObject.name = "Button - Build " + objectId;

            gameObject.transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[] { LocalizationTable.GetLocalization(proto.LocalizationCode) };

            Button button = gameObject.GetComponent <Button>();

            button.onClick.AddListener(delegate
            {
                bmc.SetMode_BuildFurniture(objectId);
                this.gameObject.SetActive(false);
            });

            // http://stackoverflow.com/questions/1757112/anonymous-c-sharp-delegate-within-a-loop
            string furniture = furnitureKey;
            LocalizationTable.CBLocalizationFilesChanged += delegate
            {
                gameObject.transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[] { LocalizationTable.GetLocalization(PrototypeManager.Furniture.Get(furniture).LocalizationCode) };
            };
        }

        lastLanguage = LocalizationTable.currentLanguage;
    }
Beispiel #5
0
    // Use this for initialization
    private void Start()
    {
        BuildModeController bmc = WorldController.Instance.buildModeController;

        // For each furniture prototype in our world, create one instance
        // of the button to be clicked!
        foreach (string s in PrototypeManager.Furniture.Keys)
        {
            GameObject go = (GameObject)Instantiate(buildFurnitureButtonPrefab);
            go.transform.SetParent(this.transform);

            Furniture proto      = PrototypeManager.Furniture.GetPrototype(s);
            string    objectId   = s;
            string    objectName = proto.Name;

            go.name = "Button - Build " + objectId;

            go.transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[] { LocalizationTable.GetLocalization(proto.LocalizationCode) };

            Button b = go.GetComponent <Button>();

            b.onClick.AddListener(delegate
            {
                bmc.SetMode_BuildFurniture(objectId);
                this.gameObject.SetActive(false);
            });

            // http://stackoverflow.com/questions/1757112/anonymous-c-sharp-delegate-within-a-loop
            string furn = s;
            LocalizationTable.CBLocalizationFilesChanged += delegate
            {
                go.transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[] { LocalizationTable.GetLocalization(PrototypeManager.Furniture.GetPrototype(furn).LocalizationCode) };
            };
        }

        lastLanguage = LocalizationTable.currentLanguage;
    }