Beispiel #1
0
    void SetupButtons()
    {
        buildButtons = new GameObject[buildButtonPrefabs.Length];

        float xPos = -columnWidth *Mathf.Min(columns, buildButtonPrefabs.Length) / 2;

        float yPos = minHeight + rowHeight * ((buildButtonPrefabs.Length - 1) / columns + 1);

        for (int i = 0; i < buildButtonPrefabs.Length; i++)
        {
            Vector3 position = transform.TransformPoint(new Vector3(xPos + (i % columns) - 0.5f, yPos + i / columns, 0));
            buildButtons[i] = (GameObject)Instantiate(buildButtonPrefabs[i], position, transform.rotation);

            RemoteActivatable act = buildButtons[i].GetComponent <RemoteActivatable>();
            act.target  = gameObject;
            act.payload = i;
            buildButtons[i].transform.parent = transform;
        }
    }
Beispiel #2
0
    void DoActivate(bool open)
    {
        if (open)
        {
            buttons = new ToggleButton[buttonPrefabs.Length];
            for (int i = 0; i < buttons.Length; i++)
            {
                GameObject button = (GameObject)Instantiate(buttonPrefabs[i], Vector3.zero, transform.rotation);
                button.transform.parent        = transform;
                button.transform.localPosition = new Vector3(1, i * 0.5f, 0);
                buttons[i] = button.GetComponent <ToggleButton>();
                RemoteActivatable ra = button.GetComponent <RemoteActivatable>();
                ra.target  = gameObject;
                ra.payload = i;
            }

            GameObject buildGO = (GameObject)Instantiate(buildButtonPrefab, Vector3.zero, transform.rotation);
            buildGO.transform.parent        = transform;
            buildGO.transform.localPosition = new Vector3(1.5f, 0.5f, 0);
            buildButton = buildGO.GetComponent <PressButton>();
            buildGO.GetComponent <RemoteActivatable>().target = gameObject;

            buttons[defaultChoice].on = true;
            ResetTimer();
        }
        else
        {
            for (int i = 0; i < buttons.Length; i++)
            {
                buttons[i].DoDestroy();
            }
            buildButton.DoDestroy();

            buttons     = null;
            buildButton = null;
        }

        isOpen = open;
    }