Beispiel #1
0
    /// <summary>
    /// 更新领域范围
    /// </summary>
    /// <returns></returns>
    private void UpdateFieldRange()
    {
        if (GameScene.Instance.GameMode == GameMode.NORMAL)
        {
            return;
        }

        var newFieldRect = new RectInt();

        if (this.Field.Count > 0)
        {
            foreach (var block in this.Field)
            {
                newFieldRect.SetMinMax(block.Value.MapPosition, block.Value.MapPosition);
                break;
            }
        }
        else
        {
            return;
        }

        foreach (var block in this.Field)
        {
            newFieldRect.xMin = Mathf.Min(block.Value.MapPosition.x, newFieldRect.xMin);
            newFieldRect.xMax = Mathf.Max(block.Value.MapPosition.x, newFieldRect.xMax);
            newFieldRect.yMin = Mathf.Min(block.Value.MapPosition.y, newFieldRect.yMin);
            newFieldRect.yMax = Mathf.Max(block.Value.MapPosition.y, newFieldRect.yMax);
        }
        this.FieldRect = newFieldRect;

        StartCoroutine(this.MakeFieldMesh(this.Field.Values, this.FieldRect));// 异步更新领域网格

        return;
    }
Beispiel #2
0
        //public static void FillRect(this Texture2D img,Color[] colors, int x, int y, int width, int height, Color fillColor)
        //{
        //    int canvasWidth = img.width;
        //    int canvasHeight = img.height;
        //    y = canvasHeight - y;
        //    int xMin = x, xMax = x + width, yMin = y - height, yMax = y;
        //    xMin = Mathf.Max(xMin, 0);
        //    xMax = Mathf.Min(xMax, canvasWidth);
        //    yMin = Mathf.Max(yMin, 0);
        //    yMax = Mathf.Min(yMax, canvasHeight);

        //    for (int i = xMin; i < xMax; i++)
        //    {
        //        for (int j = yMin; j < yMax; j++)
        //        {
        //            colors[ img.SetPixel(i, j, fillColor);
        //        }
        //    }

        //    img.SetPixels(colors);

        //}

        public static RectInt ClampRect(this Texture2D img, RectInt rect)
        {
            int        width = img.width;
            int        height = img.height;
            Vector2Int min = rect.min, max = rect.max;

            min.x = Mathf.Max(min.x, 0);
            min.y = Mathf.Max(min.y, 0);
            max.x = Mathf.Min(max.x, width);
            max.y = Mathf.Min(max.y, height);
            rect.SetMinMax(min, max);
            return(rect);
        }
Beispiel #3
0
        private RotationInfo(List <Vector2> points, Collection collection, int index)
        {
            this.Points     = points;
            this.collection = collection;
            this.index      = index;

            Vector2Int?min = null;
            Vector2Int?max = null;

            foreach (Vector2 point in points)
            {
                Vector2Int p = new Vector2Int(Mathf.CeilToInt(point.x), Mathf.FloorToInt(point.y));
                this.Points0.Add(p);

                if (min == null)
                {
                    min = p;
                }
                if (max == null)
                {
                    max = p;
                }
                min = new Vector2Int(Mathf.Min(min.Value.x, p.x), Mathf.Min(min.Value.y, p.y));
                max = new Vector2Int(Mathf.Max(max.Value.x, p.x), Mathf.Max(max.Value.y, p.y));
            }

            if (min == null || max == null)
            {
                throw new Exception("min, max");
            }

            //Vector2Int size = max.Value - min.Value + Vector2Int.one;
            RectInt rect = new RectInt();

            rect.SetMinMax(min.Value, max.Value);
            this.Bounds = rect;
        }