Beispiel #1
0
        void Start()
        {
            //添加挂在effect和buff的go.
            var effect = transform.Find("Effect");

            if (effect == null)
            {
                m_effectGo = new GameObject("Effect");
                CDarkUtil.AddChild(transform, m_effectGo.transform, Vector3.zero);
            }
            else
            {
                m_effectGo = effect.gameObject;
            }

            var buff = transform.Find("Buff");

            if (buff == null)
            {
                m_buffGo = new GameObject("Buff");
                CDarkUtil.AddChild(transform, m_buffGo.transform, Vector3.zero);
            }
            else
            {
                m_buffGo = buff.gameObject;
            }
        }
Beispiel #2
0
        //连接最低点到矩形边上的点, 形成一条直线
        //然后寻找这个直线上最高的点, 然后这个最高点和最低点之间的格子就是合理的池塘
        private void Quadrant(int x, int y)
        {
            var   highestSpot  = Vector2Int.zero;
            float highestValue = float.MinValue;

            CPondLine line = new CPondLine(m_lowestSpot, new Vector2Int(x, y));

            //获取直线上的最高点
            var v = line.NextStep();

            while (CDarkUtil.IsValidVec2Int(v))
            {
                if (v.y >= m_size.y || v.x >= m_size.x || v.y < 0 || v.x < 0)
                {
                    //Debug.Log("Error line at " + v.ToString());
                    v = line.NextStep();
                    continue;
                }
                float p = m_perlinMap[v.x, v.y];
                if (p > highestValue)
                {
                    highestValue = p;
                    highestSpot  = v;
                }

                v = line.NextStep();
            }

            //float split = highestValue + m_lowestValue;
            line = new CPondLine(m_lowestSpot, highestSpot);
            v    = line.NextStep();
            while (CDarkUtil.IsValidVec2Int(v))
            {
                if (v.y >= m_size.y || v.x >= m_size.x || v.y < 0 || v.x < 0)
                {
                    //Debug.Log("Error line at " + v.ToString());
                    v = line.NextStep();
                    continue;
                }

                m_pondMap[v.x, v.y] = 1;
                v = line.NextStep();
            }
        }
        /// <summary>
        /// 添加随机的位置到占位地图
        /// 如果位置不合理, 会重新寻找一个. 返回位置
        /// </summary>
        public Vector2Int AddUnitToDict(Vector2Int pos, int range = 2)
        {
            int key = GetKey(pos.x, pos.y);

            //如果位置已经被占用, 寻找一个最近的空位
            if (m_unitRangeDict.ContainsKey(key))
            {
                pos = FindFreeTileNear(pos);
                //如果找不到合适的位置就不添加了
                if (CDarkUtil.IsInvalidVec2Int(pos))
                {
                    return(pos);
                }
                key = GetKey(pos.x, pos.y);
            }

            m_unitPosDict[key] = true;
            if (range <= 0)
            {
                return(pos);
            }

            int minCol = pos.x - range;
            int maxCol = minCol + range * 2;
            int minRow = pos.y - range;
            int maxRow = minRow + range * 2;

            for (int row = minRow; row <= maxRow; row++)
            {
                for (int col = minCol; col <= maxCol; col++)
                {
                    key = GetKey(col, row);
                    m_unitRangeDict[key] = true;
                }
            }

            return(pos);
        }