示例#1
0
 private bool InRange(GuideItem item, RectTransform parent)
 {
     return(item.AnchorPosition.X > parent.anchoredPosition.x - parent.rect.size.x / 2 &&
            item.AnchorPosition.X < parent.anchoredPosition.x + parent.rect.size.x / 2 &&
            item.AnchorPosition.Y > parent.anchoredPosition.y - parent.rect.size.y / 2 &&
            item.AnchorPosition.Y < parent.anchoredPosition.y + parent.rect.size.y / 2);
 }
示例#2
0
    private List <RectTransform> GenerateMask(GuideItem item, RectTransform parent)
    {
        var result = new List <RectTransform>();

        if (item.AnchorPosition.X - item.Size.X / 2 > parent.anchoredPosition.x - parent.rect.size.x / 2)
        {
            var left = Instantiate(Resources.Load <RectTransform>(GuideMask), maskContainer);
            left.name             = parent.name + "_1";
            left.anchoredPosition = new Vector2(
                (item.AnchorPosition.X - item.Size.X / 2 + (parent.anchoredPosition.x - parent.rect.size.x / 2)) / 2,
                (item.AnchorPosition.Y - item.Size.Y / 2 + (parent.anchoredPosition.y + parent.rect.size.y / 2)) / 2);
            left.sizeDelta = new Vector2(
                Mathf.Abs(item.AnchorPosition.X - item.Size.X / 2 - (parent.anchoredPosition.x - parent.rect.size.x / 2)),
                Mathf.Abs(item.AnchorPosition.Y - item.Size.Y / 2 - (parent.anchoredPosition.y + parent.rect.size.y / 2)));
            result.Add(left);
        }

        if (item.AnchorPosition.Y - item.Size.Y / 2 > parent.anchoredPosition.y - parent.rect.size.y / 2)
        {
            var bottom = Instantiate(Resources.Load <RectTransform>(GuideMask), maskContainer);
            bottom.name             = parent.name + "_2";
            bottom.anchoredPosition = new Vector2(
                (item.AnchorPosition.X + item.Size.X / 2 + (parent.anchoredPosition.x - parent.rect.size.x / 2)) / 2,
                (item.AnchorPosition.Y - item.Size.Y / 2 + (parent.anchoredPosition.y - parent.rect.size.y / 2)) / 2);
            bottom.sizeDelta = new Vector2(
                Mathf.Abs(item.AnchorPosition.X + item.Size.X / 2 - (parent.anchoredPosition.x - parent.rect.size.x / 2)),
                Mathf.Abs(item.AnchorPosition.Y - item.Size.Y / 2 - (parent.anchoredPosition.y - parent.rect.size.y / 2)));
            result.Add(bottom);
        }

        if (item.AnchorPosition.X + item.Size.X / 2 < parent.anchoredPosition.x + parent.rect.size.x / 2)
        {
            var right = Instantiate(Resources.Load <RectTransform>(GuideMask), maskContainer);
            right.name             = parent.name + "_3";
            right.anchoredPosition = new Vector2(
                (item.AnchorPosition.X + item.Size.X / 2 + (parent.anchoredPosition.x + parent.rect.size.x / 2)) / 2,
                (item.AnchorPosition.Y + item.Size.Y / 2 + (parent.anchoredPosition.y - parent.rect.size.y / 2)) / 2);
            right.sizeDelta = new Vector2(
                Mathf.Abs(item.AnchorPosition.X + item.Size.X / 2 - (parent.anchoredPosition.x + parent.rect.size.x / 2)),
                Mathf.Abs(item.AnchorPosition.Y + item.Size.Y / 2 - (parent.anchoredPosition.y - parent.rect.size.y / 2)));
            result.Add(right);
        }

        if (item.AnchorPosition.Y + item.Size.Y / 2 < parent.anchoredPosition.y + parent.rect.size.y / 2)
        {
            var top = Instantiate(Resources.Load <RectTransform>(GuideMask), maskContainer);
            top.name             = parent.name + "_4";
            top.anchoredPosition = new Vector2(
                (item.AnchorPosition.X - item.Size.X / 2 + (parent.anchoredPosition.x + parent.rect.size.x / 2)) / 2,
                (item.AnchorPosition.Y + item.Size.Y / 2 + (parent.anchoredPosition.y + parent.rect.size.y / 2)) / 2);
            top.sizeDelta = new Vector2(
                Mathf.Abs(item.AnchorPosition.X - item.Size.X / 2 - (parent.anchoredPosition.x + parent.rect.size.x / 2)),
                Mathf.Abs(item.AnchorPosition.Y + item.Size.Y / 2 - (parent.anchoredPosition.y + parent.rect.size.y / 2)));
            result.Add(top);
        }

        return(result);
    }