Exemplo n.º 1
0
    public GameObject AddNewDemo <T>(string Name) where T : GenericBehaviour
    {
        GameObject newObject = new GameObject(Name);

        newObject.SetActive(false);
        var newComponentScript = newObject.AddComponent <T>();

        ResetLevelFunction resetLevelFunction = () => newComponentScript.Generate();

        m_ListOfDemos.Add(new KeyValuePair <GameObject, ResetLevelFunction>(newObject, resetLevelFunction));
        newComponentScript.Constructor();

        var buttonObject = UnityEngine.Object.Instantiate(m_PrefabButton, new Vector3(0, 0, 0), Quaternion.identity, m_ParentCanvas.transform);

        buttonObject.transform.localPosition = new Vector3(0, OFFSET_BUTTONS_Y - m_Buttons.Count * 30, 0);
        m_Buttons.Add(buttonObject);

        var button = buttonObject.GetComponent <Button>();

        button.onClick.AddListener(() => ActivateDemo(newObject, resetLevelFunction));
        button.name = Name;

        var textButton = buttonObject.transform.GetChild(0).gameObject.GetComponent <Text>();

        textButton.text = Name;


        return(newObject);
    }
Exemplo n.º 2
0
    void ActivateDemo(GameObject gameObject, ResetLevelFunction resetLevelFunction)
    {
        m_Buttons.ForEach(x => x.SetActive(false));
        m_CurrentDemo = gameObject;

        resetLevel = resetLevelFunction;
        resetLevel();
        gameObject.SetActive(true);
    }