コード例 #1
0
ファイル: LevelManager.cs プロジェクト: MK4H/MHUrho
        /// <inheritdoc />
        public IUnit SpawnUnit(UnitType unitType, ITile tile, Quaternion initRotation, IPlayer player)
        {
            if (!unitType.CanSpawnAt(tile))
            {
                return(null);
            }

            IUnit newUnit = null;

            try {
                newUnit = unitType.CreateNewUnit(GetNewID(entities), this, tile, initRotation, player);
            }
            catch (CreationException) {
                return(null);
            }

            //Could not spawn unit, user restrictions
            if (newUnit == null)
            {
                return(null);
            }

            RegisterEntity(newUnit);
            units.Add(newUnit.ID, newUnit);
            player.AddUnit(newUnit);
            tile.AddUnit(newUnit);

            return(newUnit);
        }