Ejemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        mSpawner = GameObject.FindObjectOfType <Spawner>().GetComponent <Spawner>();
        GameObject man   = mSpawner.Spawn("PrefabMan", 0, 0);
        Mover      mover = man.GetComponent <Mover>();

        mover.SetSpeed(1);
        mover.MoveToGrid(2, 2);

        GameObject woman = mSpawner.Spawn("PrefabWoman", 0, 1);

        woman.GetComponent <Mover>().SetSpeed(1);
        woman.GetComponent <Mover>().MoveToGrid(2, 0);

        mGameUI = GameObject.FindObjectOfType <GameUI>().GetComponent <GameUI>();
        List <MenuItem> root_items = mGameUI.AddMenuItem(new List <string>()
        {
            "BUILD", "RECRUIT"
        }, 0);

        root_items[0].SetSubItems(new List <string>()
        {
            "DESK", "CHAIR"
        });
        root_items[1].SetSubItems(new List <string>()
        {
            "TEACHER", "CLEANER"
        });
    }
Ejemplo n.º 2
0
        public void ICanAddMenuItemsSimplePasses()
        {
            // Use the Assert class to test conditions
            List <MenuItem> items = gameUI.AddMenuItem(new List <string>( )
            {
                "BUILD", "RECRUIT"
            }, 0);

            Assert.AreEqual(2, GameObject.FindObjectsOfType <MenuItem>().Length);

            float x0 = items[0].GetComponent <RectTransform>().position.x;
            float y0 = items[0].GetComponent <RectTransform>().position.y;
            float x1 = items[1].GetComponent <RectTransform>().position.x;
            float y1 = items[1].GetComponent <RectTransform>().position.y;

            Assert.AreEqual(0, x0);
            Assert.AreEqual(GameUI.MENU_GAP, x1 - x0);
            Assert.AreEqual(0, y0);
            Assert.AreEqual(0, y1);

            Assert.AreEqual("BUILD", items[0].mName);
            Assert.AreEqual("RECRUIT", items[1].mName);

            click_count = 0;
            items[0].mOnClickCallback += TestClick;
            items[0].OnClicked();
            items[0].OnClicked();
            Assert.AreEqual(2, click_count);

            items[0].AddSubItems(new List <string>()
            {
                "DESK", "CHAIR"
            });
            items[1].AddSubItems(new List <string>()
            {
                "TEACHER", "CLEANER"
            });
            Assert.AreEqual(6, GameObject.FindObjectsOfType <MenuItem>().Length);
        }