コード例 #1
0
 /// <summary>
 /// 根据网格获取网格的世界坐标
 /// </summary>
 /// <param name="g"> 网格 </param>
 /// <returns></returns>
 public Vector3 GetPosition(FBGrid g)
 {
     return(new Vector3(
                -f_mapWidth / 2 + (g.Index_X + 0.5f) * f_tileWidth,
                -f_mapHeight / 2 + (g.Index_Y + 0.5f) * f_tileHeight,
                0));
 }
コード例 #2
0
        void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                FBGrid g = GetTileUnderMouse();

                if (g != null)
                {
                    //触发鼠标左键点击事件
                    FBGridClickEventArgs e = new FBGridClickEventArgs(0, g);
                    if (OnFBGridClick != null)
                    {
                        OnFBGridClick(this, e);
                    }
                }
            }

            if (Input.GetMouseButtonDown(1))
            {
                FBGrid g = GetTileUnderMouse();

                if (g != null)
                {
                    //触发鼠标右键点击事件
                    FBGridClickEventArgs e = new FBGridClickEventArgs(1, g);
                    if (OnFBGridClick != null)
                    {
                        OnFBGridClick(this, e);
                    }
                }
            }
        }
コード例 #3
0
        public void LoadLevel(FBLevel level)
        {
            //清除当前状态
            Clear();

            //保存
            f_level = level;

            //加载图片
            BackgroundImage = "file://" + FBConsts.MpsDir + "/" + level.Background;
            RoadImage       = "file://" + FBConsts.MpsDir + "/" + level.Road;

            //寻路点
            for (int i = 0; i < level.Path.Count; i++)
            {
                FBCoords c = level.Path[i];
                FBGrid   t = GetGrid(c.X, c.Y);
                f_road.Add(t);
            }

            //炮塔点
            for (int i = 0; i < level.Holders.Count; i++)
            {
                FBCoords c = level.Holders[i];
                FBGrid   t = GetGrid(c.X, c.Y);
                t.CanHold = true;
            }
        }
コード例 #4
0
        public void Load(int towerId, FBGrid grid, Rect mapRect)
        {
            FBTowerInfo info = FBGame.Instance.StaticData.GetTower(towerId);

            ID          = info.ID;
            MaxLevel    = info.MaxLevel;
            BasePrice   = info.BasePrice;
            GuardRange  = info.GuardRange;
            ShotRate    = info.ShotRate;
            UseBulletID = info.UseBulletID;
            Level       = 1;
            f_grid      = grid;
            MapRect     = mapRect;
        }
コード例 #5
0
        private void OnSpawnTower(FBSpawnTowerArgs args)
        {
            //创建Tower
            FBTowerInfo info = FBGame.Instance.StaticData.GetTower(args.TowerID);
            GameObject  go   = FBGame.Instance.ObjectPool.Spawn(info.PrefabName);

            FBTower tower = go.GetComponent <FBTower>();

            tower.transform.position = args.Position;

            //Tile里放入Tower信息
            FBGrid tile = f_map.GetGrid(args.Position);

            ////初始化Tower
            tower.Load(args.TowerID, tile, f_map.MapRect);

            tile.Data = tower;
        }
コード例 #6
0
        public override void OnUnspawn()
        {
            if (f_animator.gameObject.activeSelf)
            {
                f_animator.ResetTrigger("IsAttack");
            }

            f_animator  = null;
            f_target    = null;
            ID          = 0;
            Level       = 0;
            MaxLevel    = 0;
            BasePrice   = 0;
            GuardRange  = 0;
            ShotRate    = 0;
            UseBulletID = 0;

            f_grid = null;
        }
コード例 #7
0
        private void OnMapGridClick(object sender, FBGridClickEventArgs e)
        {
            FBGameModel game = GetModel <FBGameModel>();

            //游戏还未开始,那么不操作菜单
            if (!game.IsPlaying)
            {
                return;
            }

            //如果有菜单显示,那么隐藏菜单
            if (FBUITowerPopup.Instance.IsPopShow)
            {
                SendEvent(FBConsts.E_TowerHide);
                return;
            }

            FBGrid grid = e.Grid;

            if (!grid.CanHold)
            {
                SendEvent(FBConsts.E_TowerHide);
                return;
            }

            if (grid.Data == null)
            {
                FBShowTowerCreatArgs args = new FBShowTowerCreatArgs()
                {
                    Position = f_map.GetPosition(grid),
                    UpSide   = grid.Index_Y < FBMap.RowCount / 2
                };
                SendEvent(FBConsts.E_ShowTowerCreat, args);
            }
            else
            {
                FBShowTowerUpgradeArgs args = new FBShowTowerUpgradeArgs()
                {
                    Tower = grid.Data as FBTower
                };
                SendEvent(FBConsts.E_ShowTowerUpgrade, args);
            }
        }
コード例 #8
0
 public FBGridClickEventArgs(int mouseButton, FBGrid grid)
 {
     this.MouseButton = mouseButton;
     this.Grid        = grid;
 }