Esempio n. 1
0
    public void InsertTile(TileDao tile)
    {
        this.SelectButton(tile.name);

        this.tile         = tile;
        this.mapComponent = null;

        this.PrepareTemp(tile.Instantiate().model);
    }
Esempio n. 2
0
    void Start()
    {
        // Buttons
        this.buttonNew  = GameObject.Find("Canvas/Menu/ButtonNew");
        this.buttonLoad = GameObject.Find("Canvas/Menu/ButtonLoad");
        this.buttonSave = GameObject.Find("Canvas/Menu/ButtonSave");

        this.buttonSave.SetActive(false);

        this.mouseDown = false;

        this.tile         = null;
        this.mapComponent = null;
        this.temp         = null;

        this.timeCounter = 0;

        this.gameComponents              = new GameComponents();
        this.gameComponents.map          = null;
        this.gameComponents.mapTile      = null;
        this.gameComponents.mapComponent = null;

        this.components = GameObject.Find("components");;

        // ScrollView
        this.tilesView         = GameObject.Find("tilesView");
        this.mapComponentsView = GameObject.Find("mapComponentsView");

        GameObject button, model, tilesContent, mapComponentsContent;

        tilesContent         = GameObject.Find("tilesView/Viewport/Content");
        mapComponentsContent = GameObject.Find("mapComponentsView/Viewport/Content");

        tilesContent.GetComponent <RectTransform>().sizeDelta         = new Vector2(20 + 120 * this.gameComponents.tiles.Count, 0.0f);
        mapComponentsContent.GetComponent <RectTransform>().sizeDelta = new Vector2(20 + 120 * this.gameComponents.mapComponents.Count, 0.0f);

        int count = 0;

        List <string> options = new List <string>();

        foreach (TileDao tile in this.gameComponents.tiles.Values)
        {
            options.Add(tile.name);

            button      = new GameObject();
            button.name = "Button" + tile.name;
            button.transform.SetParent(tilesContent.transform);
            button.AddComponent <Button>();
            button.AddComponent <Image>();
            button.GetComponent <RectTransform>().anchorMin     = new Vector2(0.0f, 0.5f);
            button.GetComponent <RectTransform>().anchorMax     = new Vector2(0.0f, 0.5f);
            button.GetComponent <RectTransform>().pivot         = new Vector2(0.0f, 0.5f);
            button.GetComponent <RectTransform>().localScale    = new Vector3(1.0f, 1.0f, 1.0f);
            button.GetComponent <RectTransform>().localPosition = new Vector3(20.0f + 120 * count, -10.0f, 0.0f);
            UnityEngine.Events.UnityAction action = () => { InsertTile(tile); };
            button.GetComponent <Button>().onClick.AddListener(action);

            model = GameObject.Instantiate(tile.Instantiate().model);
            model.transform.SetParent(button.transform);
            model.AddComponent <RectTransform>();
            model.GetComponent <RectTransform>().anchorMin     = new Vector2(0.5f, 0.5f);
            model.GetComponent <RectTransform>().anchorMax     = new Vector2(0.5f, 0.5f);
            model.GetComponent <RectTransform>().pivot         = new Vector2(0.5f, 0.5f);
            model.GetComponent <RectTransform>().localScale    = new Vector3(95.0f, 95.0f, 1.0f);
            model.GetComponent <RectTransform>().localPosition = new Vector3(50.0f, 0.0f, 0.0f);

            count++;
        }

        count = 0;

        button      = new GameObject();
        button.name = "ButtonEmpty";
        button.transform.SetParent(mapComponentsContent.transform);
        button.AddComponent <Button>();
        button.AddComponent <Image>();
        button.GetComponent <RectTransform>().anchorMin     = new Vector2(0.0f, 0.5f);
        button.GetComponent <RectTransform>().anchorMax     = new Vector2(0.0f, 0.5f);
        button.GetComponent <RectTransform>().pivot         = new Vector2(0.0f, 0.5f);
        button.GetComponent <RectTransform>().localScale    = new Vector3(1.0f, 1.0f, 1.0f);
        button.GetComponent <RectTransform>().localPosition = new Vector3(20.0f + 120 * count, -10.0f, 0.0f);
        button.GetComponent <Button>().onClick.AddListener(DeleteMapComponent);

        GameObject text = new GameObject("empty", typeof(Text));

        text.gameObject.transform.SetParent(button.transform);
        text.GetComponent <RectTransform>().sizeDelta     = new Vector2(320.0f, 200.0f);
        text.GetComponent <RectTransform>().anchorMin     = new Vector2(0.0f, 0.0f);
        text.GetComponent <RectTransform>().anchorMax     = new Vector2(1.0f, 1.0f);
        text.GetComponent <RectTransform>().localScale    = new Vector3(1.0f, 1.0f, 1.0f);
        text.GetComponent <RectTransform>().localPosition = new Vector3(0.0f, 0.0f, 0.0f);
        text.GetComponent <RectTransform>().offsetMin     = new Vector2(0.0f, 0.0f);
        text.GetComponent <RectTransform>().offsetMax     = new Vector2(0.0f, 0.0f);
        text.GetComponent <Text>().font      = Font.CreateDynamicFontFromOSFont("Arial", 14);
        text.GetComponent <Text>().fontSize  = 30;
        text.GetComponent <Text>().fontStyle = FontStyle.Bold;
        text.GetComponent <Text>().color     = Color.red;
        text.GetComponent <Text>().alignment = TextAnchor.MiddleCenter;
        text.GetComponent <Text>().text      = "X";

        count++;

        foreach (MapComponentDao mapComponent in this.gameComponents.mapComponents.Values)
        {
            button      = new GameObject();
            button.name = "Button" + mapComponent.name;
            button.transform.SetParent(mapComponentsContent.transform);
            button.AddComponent <Button>();
            button.AddComponent <Image>();
            button.GetComponent <RectTransform>().anchorMin     = new Vector2(0.0f, 0.5f);
            button.GetComponent <RectTransform>().anchorMax     = new Vector2(0.0f, 0.5f);
            button.GetComponent <RectTransform>().pivot         = new Vector2(0.0f, 0.5f);
            button.GetComponent <RectTransform>().localScale    = new Vector3(1.0f, 1.0f, 1.0f);
            button.GetComponent <RectTransform>().localPosition = new Vector3(20.0f + 120 * count, -10.0f, 0.0f);
            UnityEngine.Events.UnityAction action = () => { InsertMapComponent(mapComponent); };
            button.GetComponent <Button>().onClick.AddListener(action);

            model = GameObject.Instantiate(mapComponent.Instantiate().model);
            model.transform.SetParent(button.transform);
            model.AddComponent <RectTransform>();
            model.GetComponent <RectTransform>().anchorMin     = new Vector2(0.5f, 0.5f);
            model.GetComponent <RectTransform>().anchorMax     = new Vector2(0.5f, 0.5f);
            model.GetComponent <RectTransform>().pivot         = new Vector2(0.5f, 0.5f);
            model.GetComponent <RectTransform>().localScale    = new Vector3(95.0f, 95.0f, 1.0f);
            model.GetComponent <RectTransform>().localPosition = new Vector3(50.0f, -30.0f, 0.0f);

            count++;
        }

        GameObject.Find("Canvas/PanelNewMap/Form/TileDefault/DropdownTiles").GetComponent <Dropdown>().AddOptions(options);

        // NewMap
        this.PanelNewMap = GameObject.Find("Canvas/PanelNewMap");

        this.PanelNewMap.SetActive(false);

        this.mapComponentsView.SetActive(false);
    }