示例#1
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);
                    }
                }
            };
        }
示例#2
0
 public static bool IsBeingDragged(this Collider collider)
 {
     return(PTGlobalInput.IsDragging(collider));
 }