Ejemplo n.º 1
0
        public void UpdateBackground(KeyValuePair <int, PTFlatGroupCollection> collection)
        {
            Collection = collection;
            int size = Collection.Value == null ? 0 : Collection.Value.Count;

            if (size > 0)
            {
                List <PTTouch> touchesDraggingThis = PTGlobalInput.FindTouchesDragging(GetComponent <Collider>());
                if (touchesDraggingThis == null || touchesDraggingThis.Count == 0)
                {
                    transform.SetLocalPosition(groups.GetComponent <PTZone>().TargetLocalPositionOf(groups.GetSiblingIndex(Collection.Value.content[0])), groups.timerAnimation);
                }
            }
            switch (size)
            {
            case 0:
                StartCoroutine(SetAppearance(false));
                break;

            case 1:
                if (backgroundSize == 0 || backgroundSize == 1)
                {
                    StartCoroutine(SetAppearance(true));
                }
                else
                {
                    StartCoroutine(SpriteSwap(false));
                }
                break;

            case 2:
                if (backgroundSize == 1)
                {
                    StartCoroutine(SpriteSwap(true));
                }
                else
                {
                    StartCoroutine(Stretch(size));
                }
                break;

            default:
                StartCoroutine(Stretch(size));
                break;
            }
            backgroundSize = size;
        }
Ejemplo n.º 2
0
        private void Awake()
        {
            gesture = GetComponent <PTLocalInput>();

            gesture.OnDragBegin += (PTTouch touch) =>
            {
                if (gameObject &&
                    groups &&
                    !groups.GetComponent <PTZone>().IsArranging &&
                    !groups.isDragging &&
                    touch.hitsBegin.ContainsKey(gesture.GetComponent <Collider>()))
                {
                    if (Collection.Value != null && Collection.Value.isGroup && Collection.Value.Count == 1)
                    {
                        //ungroup for a single tile
                        groups.UnGroup(this);
                    }
                    if (groups.OnDragBegan != null)
                    {
                        groups.OnDragBegan(touch);
                    }
                }
            };
            gesture.OnDrag += (PTTouch touch) =>
            {
                if (gameObject && PTGlobalInput.IsDragging(gesture.GetComponent <Collider>()) && touch.hitsBegin.ContainsKey(gesture.GetComponent <Collider>()))
                {
                    if ((transform.position - groups.transform.position).z > groups.height)
                    {
                        //Ungroup when too high
                        groups.UnGroup(this);
                    }

                    if (Collection.Key == CollectionHover.Key)
                    {
                        //arrange inside the group
                        groups.SwapElements(transform.GetSiblingIndex(), SiblingIndexExpected);
                    }
                    else
                    {
                        if (CollectionHover.Key != Collection.Key && Collection.Value.isGroup)
                        {
                            //ungroup
                            groups.UnGroup(this);
                        }
                        else
                        {
                            //swap collections
                            groups.SwapCollections(Collection.Key, CollectionExpected.Key);
                        }
                    }
                }
            };
            gesture.OnTouchEnd_BeginOnThis += (PTTouch touch) =>
            {
                if (gameObject &&
                    groups &&
                    (groups.isDragging || groups.GetComponent <PTZone>().IsArranging) &&
                    gesture.enableDrag)
                {
                    if (groups.OnDragEnd != null)
                    {
                        groups.OnDragEnd(touch);
                    }
                }
            };
            gesture.OnLongHoldBegin += (PTTouch touch) =>
            {
                if (groups)
                {
                    //Become a group
                    if (Collection.Key == CollectionHover.Key && Collection.Value.Count == 1)
                    {
                        Vector3 positionExpected   = PositionExpected;
                        Vector2 positionExpected2D = new Vector2(positionExpected.x, positionExpected.z);
                        Vector2 position2D         = new Vector2(transform.position.x, transform.position.z);
                        float   distance2D         = (positionExpected2D - position2D).magnitude;

                        //If the distance is close enough from the expected position
                        if (distance2D < groups.maxCreateGroupDistance)
                        {
                            groups.SetIsGroupIfSingle(Collection.Key, !Collection.Value.isGroupIfSingle);
                        }
                    }
                    //Merge with another group
                    else
                    {
                        groups.Merge(Collection.Key, CollectionHover.Key);
                    }
                }
            };
        }
Ejemplo n.º 3
0
 public static bool IsBeingDragged(this Collider collider)
 {
     return(PTGlobalInput.IsDragging(collider));
 }