Exemple #1
0
    //导入各种预制体资源
    public void LoadResources()
    {
        //背景设置(其实就是一个方块加点贴图。能力限制,就这么弄了)
        background             = Instantiate <Transform>(Resources.Load <Transform>("Prefabs/backGround"), new Vector3(0, 6, 3), Quaternion.identity);
        background.name        = "background";
        background.localScale += new Vector3(35, 20, 2);
        background.Rotate(new Vector3(10, 0, 180));

        //导入陆地、河流和船
        GameObject river = createObject("River", new Vector3(0, 0, -2));

        river.name = "river";

        GameObject leftLand = createObject("Land", new Vector3(-10, 0.5f, -2));

        leftLand.name = "leftLand";

        GameObject rightLand = createObject("Land", new Vector3(10, 0.5f, -2));

        rightLand.name = "rightLand";

        GameObject t_boat = createObject("Boat", new Vector3(5, 1.15f, -2.5f));

        t_boat.name = "boat";

        //设置控制器
        fromLand = new LandController(rightLand, 1);
        toLand   = new LandController(leftLand, -1);
        boat     = new BoatController(t_boat);
        //导入游戏人物对象并设置控制器
        for (int i = 0; i < 3; i++)
        {
            GameObject    temp = createObject("devil", Vector3.zero);
            ChaController cha  = new ChaController(temp, 1);
            cha.setName("devil" + i);
            cha.setPosition(fromLand.getEmptyPosition());
            cha.getOnLand(fromLand);
            fromLand.getOnLand(cha);

            people[i] = cha;
        }

        for (int i = 0; i < 3; i++)
        {
            GameObject    temp = createObject("Priests", Vector3.zero);
            ChaController cha  = new ChaController(temp, 0);

            cha.setName("priest" + i);
            cha.setPosition(fromLand.getEmptyPosition());
            cha.getOnLand(fromLand);
            fromLand.getOnLand(cha);

            people[i + 3] = cha;
        }
    }
    /// <summary>
    /// 如果点了某个人物,判断其是在船上还是陆地上
    /// 如果在船上,则上岸;否则,上船
    /// </summary>
    /// <param name="chac">某个人</param>
    public void isClickCha(ChaController chac)
    {
        //上岸
        if (chac.isOnBoat())
        {
            LandController whichLand;
            if (boat.getOnWhere() == -1)
            {
                whichLand = toLand;
            }
            else
            {
                whichLand = fromLand;
            }

            boat.getOffBoat(chac.getChaName());
            //chac.movePosition(whichLand.getEmptyPosition());
            // chac.setDestination(whichLand.getEmptyPosition());
            actionManager.moveCharacter(chac, whichLand.getEmptyPosition());//动作执行
            chac.getOnLand(whichLand);
            whichLand.getOnLand(chac);
        }
        //上船
        else
        {
            LandController whichLand = chac.getLandCont();
            if (boat.getEmptyIndex() == -1)
            {
                return;
            }
            if (whichLand.getSide() != boat.getOnWhere())
            {
                return;
            }

            whichLand.getOffLand(chac.getChaName());
            //chac.movePosition(boat.getEmptyPos());
            // chac.setDestination(boat.getEmptyPos());
            actionManager.moveCharacter(chac, boat.getEmptyPos());//动作执行
            chac.getOnBoat(boat);
            boat.getOnBoat(chac);
        }
        userGUI.Status = isOver();//判断游戏是否已经达到了结束的条件
    }