예제 #1
0
    private void RenderNestedObjectButtons()
    {
        furnitureItems = new List <GameObject>();

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

        BuildModeController buildModeController = WorldController.Instance.buildModeController;

        foreach (string nestedObjectKey in PrototypeManager.NestedObject.Keys)
        {
            if (PrototypeManager.NestedObject.Get(nestedObjectKey).HasTypeTag("Non-buildable") && showAllFurniture == false)
            {
                continue;
            }

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

            NestedObject proto    = PrototypeManager.NestedObject.Get(nestedObjectKey);
            string       objectId = nestedObjectKey;

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

            gameObject.transform.GetComponentInChildren <Text>().text = proto.GetName();

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

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

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

            Image image = gameObject.transform.GetChild(0).GetComponentsInChildren <Image>().First();
            image.sprite = WorldController.Instance.nestedObjectSpriteController.GetSpriteForNestedObject(nestedObjectKey);
        }
    }