コード例 #1
0
        // 关闭角色范围显示
        public void CloseRangeView(int gid)
        {
            ActionRangeView view = null;

            if (m_RangeViewDic.TryGetValue(gid, out view))
            {
                view.Release();
            }
        }
コード例 #2
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);
        }