コード例 #1
0
    private void Start()
    {
        roadPlacer   = GameObject.Find("Manager(Has to be at 0,0,0)").GetComponent <RoadPlacer>();
        objectPlacer = GameObject.Find("Manager(Has to be at 0,0,0)").GetComponent <ObjectPlacer>();

        //Loop through each building we can place and create UI for them
        foreach (GameObject building in buildings)
        {
            GameObject ImageButton = new GameObject();
            GameObject ImageText   = new GameObject();
            ImageButton.transform.parent = panel.transform;
            //Get the image from the building
            Sprite image = building.GetComponent <AbstractBuilding>().clickableIcon;
            ImageButton.AddComponent <RectTransform>();
            ImageButton.AddComponent <Image>();
            ImageButton.AddComponent <Button>();
            //Set the image to the image from building
            ImageButton.GetComponent <Image>().sprite = image;


            ObjectSelectButton selectScript = ImageButton.AddComponent <ObjectSelectButton>();
            selectScript.building = building;
            selectScript.change   = this;
            ImageButton.GetComponent <Button>().onClick.AddListener(selectScript.SetBuilding);


            ImageText.transform.parent = ImageButton.transform;
            RectTransform trans = ImageText.AddComponent <RectTransform>();


            trans.localPosition = new Vector2(0, -67);

            TMPro.TextMeshProUGUI text = ImageText.AddComponent <TMPro.TextMeshProUGUI>();
            text.text      = building.transform.name;
            text.alignment = TextAlignmentOptions.Center;

            text.enableAutoSizing = true;
            text.fontSizeMin      = 10;
            text.fontSizeMax      = 18;
            text.fontSize         = 20;
        }
    }
コード例 #2
0
    private void Start()
    {
        roadPlacer = FindObjectOfType <RoadPlacer>();

        path = Application.persistentDataPath + "/" + "Save" + SceneManager.GetActiveScene().name + ".binary";
    }