Exemplo n.º 1
0
        /// <summary>
        /// 中心点外空闲的位置
        /// </summary>
        /// <param name="_pos"></param>
        /// <param name="_range"></param>
        /// <returns></returns>
        private Vector3Int?GetUnitRangeSpacePos(Vector3Int _pos, int _range)
        {
            var array = tileList
                        .Where(x => x.widthHeighValue.Vector3IntRangeValue(_pos) == _range).ToArray();

            // 优先左 右 上 下 右上 左下
            if (_range == 2)
            {
                Vector3Int   temp = _pos;
                TileSaveData a    = GetTileSaveData(temp + Vector3Int.up + Vector3Int.right);
                TileSaveData b    = GetTileSaveData(temp + Vector3Int.down + Vector3Int.left);
                if (a != null && !activitiesManager.GetUnitPosContains(a.widthHeighValue))
                {
                    return(a?.widthHeighValue);
                }
                else if (b != null && !activitiesManager.GetUnitPosContains(b.widthHeighValue))
                {
                    return(b?.widthHeighValue);
                }
            }

            foreach (var v in array.Where(v => !activitiesManager.GetUnitPosContains(v.widthHeighValue)))
            {
                return(v.widthHeighValue);
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 搜索该位置的可行性
        /// </summary>
        /// <param name="_currentData"></param>
        /// <param name="_data"></param>
        private void SearchAround(TileSaveData _currentData, TileSaveData _data)
        {
            if (_data == null)
            {
                return;
            }

            int value = _data.pixelValue[1] + _currentData.pixelValue[0];

            if (_data.pixelValue[0] != 0)
            {
                if (_data.isChange)
                {
                    if (value < _data.pixelValue[0])
                    {
                        _data.pixelValue[0] = value;
                        _data.path          = string.Concat(_currentData.path, ",", _data.aliasName);
                    }
                }
                else
                {
                    _data.isChange      = true;
                    _data.pixelValue[0] = value;
                    _data.path          = string.Concat(_currentData.path, ",", _data.aliasName);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 根据数据加载相关方格
        /// </summary>
        /// <param name="_stepInfo"></param>
        public void LoadCorrelationGrid(StepInfo _stepInfo)
        {
            if (_stepInfo.unit != null)
            {
                foreach (var v in tileList.Where(x => x.activitiesAllowUnit.moveSpriteRenderer.enabled == false))
                {
                    v.activitiesAllowUnit.SetMoveGrid(true);
                }

                _stepInfo.unit.currentPos         = _stepInfo.unitCurrentPos;
                _stepInfo.unit.transform.position = _stepInfo.unitCurrentPos;
                for (int i = 0; i < _stepInfo.tileCommand.Length; i++)
                {
                    TileSaveData temp = tileList.FirstOrDefault(x =>
                                                                x.widthHeighValue.Vector3IntRangeValue(_stepInfo.tileCommand[i].pos) == 0);
                    if (temp != null)
                    {
                        temp.aliasName = _stepInfo.tileCommand[i].aliasName;
                        temp.isChange  = _stepInfo.tileCommand[i].isChange;
                        temp.path      = _stepInfo.tileCommand[i].path;
                        temp.activitiesAllowUnit.SetMoveGrid(_stepInfo.tileCommand[i].moveEnable);
                    }
                }
                RefreshCommanderCircleGird(_stepInfo.unit);
            }
        }
Exemplo n.º 4
0
        private void InitCalculateValue()
        {
            // 长宽估测
            Vector3Int _vector3 = Vector3Int.zero;

            for (int i = 0; ; i++)
            {
                _vector3.x = i;
                if (ground.GetTile(_vector3) == null && supplement.GetTile(_vector3) == null)
                {
                    width = i;
                    break;
                }
            }

            _vector3   = Vector3Int.zero;
            _vector3.x = width - 1;
            for (int i = 0; ; i++)
            {
                _vector3.y = i;
                if (ground.GetTile(_vector3) == null && supplement.GetTile(_vector3) == null)
                {
                    height = i;
                    break;
                }
            }

            tileArray = new TileSaveData[height, width];
            for (int i = 0; i < height; i++)
            {
                _vector3.y = i;
                for (int j = 0; j < width; j++)
                {
                    _vector3.x      = j;
                    tileArray[i, j] = new TileSaveData();
                    tileArray[i, j].InfoEntry(this.GetTile(_vector3), GetSprite(_vector3), _vector3, Instantiate(moveSprite, _vector3, Quaternion.identity, activitiesAllowUnitRoot).GetComponent <AllowUnitInfo>());
                    tileList.Add(tileArray[i, j]);

                    if (tileArray[i, j].tile == null)
                    {
                        Debug.LogError("TileMap error");
                    }
                }
            }
        }