コード例 #1
0
        // 显示角色范围
        public void ShowRangeViewAtPoint(IPoint point, int gid, int locomotivity, int attackDistance)
        {
            Character ch = this[point.X, point.Y].GetActor <Character>();

            if (ch == null)
            {
                Debug.LogError("this cell don't have any characters that x:" + point.X + " y:" + point.Y);
                return;
            }
            ActionRangeView view = null;

            if (!m_RangeViewDic.TryGetValue(gid, out view))
            {
                view = new ActionRangeView();
                m_RangeViewDic.Add(gid, view);
            }
            view.Release();
            ActionRangeData rangeData = new ActionRangeData();
            int             cost      = 0;
            IPoint          p         = new IPoint();

            for (int y = -locomotivity - attackDistance - 1; y <= locomotivity + attackDistance + 1; ++y)
            {
                for (int x = -locomotivity - attackDistance - 1; x <= locomotivity + attackDistance + 1; ++x)
                {
                    p.X = x + point.X;
                    p.Y = y + point.Y;
                    if (!m_MapData.IsAvailable(p.X, p.Y))
                    {
                        continue;
                    }
                    cost = Mathf.Abs(x) + Mathf.Abs(y);
                    if (cost <= locomotivity)
                    {
                        //Debug.Log(string.Format("x:{0} y:{1} px:{2} py:{3} cost:{4}", x, y, p.X, p.Y, cost));
                        rangeData.MovingList.Add(new Data.ActionCellData(p.X, p.Y));
                    }
                    else if (cost <= locomotivity + attackDistance)
                    {
                        rangeData.AttackingList.Add(new Data.ActionCellData(p.X, p.Y));
                    }
                }
            }
            view.Create(rangeData, m_RangeCellsParent);
        }
コード例 #2
0
        public void Create(ActionRangeData data, Transform parent)
        {
            GridMap2D map = SLG.SLGGame.Instance.MapData;

            foreach (ActionCellData cellData in data.MovingList)
            {
                ActionRangeCellObj obj = new ActionRangeCellObj(parent);
                obj.SetMoving();
                Vector3 pos = map.CellToWorldSpacePos(cellData.X, cellData.Y);
                obj.SetWorldPos(pos);
                m_ObjList.Add(obj);
            }

            foreach (ActionCellData cellData in data.AttackingList)
            {
                ActionRangeCellObj obj = new ActionRangeCellObj(parent);
                obj.SetAttacking();
                Vector3 pos = map.CellToWorldSpacePos(cellData.X, cellData.Y);
                obj.SetWorldPos(pos);
                m_ObjList.Add(obj);
            }
        }