示例#1
0
文件: Configs.cs 项目: JvJ/CotWM
    /// <summary>
    /// Overlay the specified roomControl, room and config onto the room control.
    /// </summary>
    /// <param name='roomControl'>
    /// Room control.
    /// </param>
    /// <param name='room'>
    /// Room.
    /// </param>
    /// <param name='config'>
    /// Config.
    /// </param>
    public void Overlay(RoomControl roomControl, Room room, Config config)
    {
        if (config.Width != room.Width || config.Height != room.Height){
            throw new ConfigFormatException("Room and config dimensions do not match!");
        }

        for( int x = 0; x < room.Width; x++){
            for(int y = 0; y < room.Height; y++){

                // Only add the overlay if it's not already occupied by the room
                switch(room[x,y].Type){
                case TileType.BLANK:

                    var currentConf = config[x,y];
                    var currentPre = this[currentConf];

                    if (currentPre != null){

                        // Instantiate whatever the prefab is!
                        var o = GameObject.Instantiate(currentPre) as GameObject;

                        o.transform.position = CubeGen.Singleton.PositionFromIdx(roomControl.Position, new coords(x,y));

                        switch (currentConf){
                        case ObjectType.SNOW:
                            o.transform.localScale = new Vector3( CubeGen.Singleton.cubeSize, CubeGen.Singleton.cubeSize, CubeGen.Singleton.cubeSize);
                            var mRend = o.GetComponent(typeof(MeshRenderer)) as MeshRenderer;
                            mRend.material.color = new Color(1f,1f,1f);
                            o.tag = "SNOW";
                            o.layer = LayerMask.NameToLayer("Terrain");
                            roomControl.AddTerrain(o);
                            break;
                        case ObjectType.PLAYER_START:
                            roomControl.PlayerStart = o;
                            break;
                        case ObjectType.XLGRHTHBTRG:
                            var xc = o.GetComponent(typeof(XlGrhthbtrgControl)) as XlGrhthbtrgControl;
                            xc.player = player;
                            xc.currentState = EntityState.STILL;
                            xc.target = player.transform.Find("Armature/Hip");
                            o.layer = LayerMask.NameToLayer("Enemy");
                            roomControl.AddEnemy(xc);
                            break;
                        case ObjectType.WYRM:
                            numWyrms++;
                            var wc = o.GetComponent(typeof(WyrmControl)) as WyrmControl;
                            wc.player = player;
                            wc.currentState = EntityState.STILL;
                            o.layer = LayerMask.NameToLayer("Wyrm");
                            roomControl.AddEnemy(wc);
                            break;
                        case ObjectType.SHOGGOTH:
                            var sc = o.GetComponent(typeof(ShoggothControl)) as ShoggothControl;
                            sc.player = player;
                            sc.currentState = EntityState.STILL;
                            o.layer = LayerMask.NameToLayer("Enemy");
                            roomControl.AddEnemy(sc);
                            break;
                        }
                    }
                    break;
                default:
                    break;
                }
            }
        }
    }