Example #1
0
 private void OnTriggerExit2D(Collider2D collision)
 {
     if (collision.GetComponent <PlaceForImg>() == placeForImg)
     {
         placeForImg = null;
     }
 }
Example #2
0
        private void Awake()
        {
            scaleStart = transform.localScale;

            spriteRenderer = GetComponent <Image>();
            boxCollider    = GetComponent <BoxCollider2D>();

            placeForImg = GetComponent <PlaceForImg>();

            var drag = GetComponent <Drag.Drag>();

            drag.onEndDrag.AddListener(OnEndDrag);
            drag.onBeginDrag.AddListener(OnBeginDrag);
        }
Example #3
0
        private void OnTriggerStay2D(Collider2D targetCollider)
        {
            var targetPlaceForImg = targetCollider.GetComponent <PlaceForImg>();

            if (targetPlaceForImg == null || targetPlaceForImg.img != this)
            {
                return;
            }

            var transformParent = transform.parent;

            // Left - top
            var lt = new Vector2(
                Mathf.Max(boxCollider.bounds.min.x, targetCollider.bounds.min.x),
                Mathf.Max(boxCollider.bounds.min.y, targetCollider.bounds.min.y)
                );

            lt = transformParent.transform.InverseTransformPoint(lt);

            // Bottom - right
            var br = new Vector2(
                Mathf.Min(boxCollider.bounds.max.x, targetCollider.bounds.max.x),
                Mathf.Min(boxCollider.bounds.max.y, targetCollider.bounds.max.y)
                );

            br = transformParent.transform.InverseTransformPoint(br);

            var sVector = br - lt;

            var s = sVector.x * sVector.y;

            if (s >= sizeSquare)
            {
                placeForImg = targetCollider.gameObject.GetComponent <PlaceForImg>();
            }
            else
            {
                placeForImg = null;
            }
        }