コード例 #1
0
        //static Color white = Color.white;
        // その場所が空き地かどうか調べる
        static public bool IsEmptyField(Vector3 pos, Liver.Entity.AreaMap areaMap, Vector3 offset)
        {
            // 画像上の位置
            var tpos = pos - offset;
            //Debug.Log($"{pos.x}, {pos.z} -> {tpos.x}, {tpos.z}");
            int x = (int)tpos.x;
            int y = (int)tpos.z;

            if (!areaMap.Contain(x, y))
            {
                return(false);
            }

            var color = areaMap.GetPixel(x, y);

            return(!(color.g > 0));
            //return ExtendedColor.FastEqual(ref color, ref white);
        }
コード例 #2
0
        public int EmptyAreaSize(Liver.Entity.AreaMap areaMap, int x, int y, int step, int max)
        {
            int current = step;

            while (current < max)
            {
                // 四方向調べる
                // NOTE 建物が四角いので4端を調査
                if (!areaMap.Contain(x - current, y - current))
                {
                    return(current - step);
                }

                if (!areaMap.Contain(x - current, y + current))
                {
                    return(current - step);
                }

                if (!areaMap.Contain(x + current, y - current))
                {
                    return(current - step);
                }

                if (!areaMap.Contain(x + current, y + current))
                {
                    return(current - step);
                }

                var leftup = areaMap.GetPixel(x - current, y - current);

                if ((leftup.r > 0))
                {
                    return(current - step);
                }

                //if (!ExtendedColor.FastEqual(ref up, ref white)) return current - step;
                var leftdown = areaMap.GetPixel(x - current, y + current);

                if ((leftdown.r > 0))
                {
                    return(current - step);
                }

                //if (!ExtendedColor.FastEqual(ref down, ref white)) return current - step;
                var rightup = areaMap.GetPixel(x + current, y - current);

                if ((rightup.r > 0))
                {
                    return(current - step);
                }

                //if (!ExtendedColor.FastEqual(ref left, ref white)) return current - step;
                var rightdown = areaMap.GetPixel(x + current, y + current);

                if ((rightdown.r > 0))
                {
                    return(current - step);
                }

                //if (!ExtendedColor.FastEqual(ref right, ref white)) return current - step;
                current += step;
            }

            return(max);
        }