示例#1
0
        public static bool TryAddItem(DragDropItem item, DragDropTarget target)
        {
            if (item.attachedTarget != null)
            {
                return(false);
            }
            if (!IsChannelMatch(target, item))
            {
                return(false);
            }
            if (target.currentItemCount >= target.maxItemCount)
            {
                return(false);
            }

            DragDropEventData eventData = new DragDropEventData();

            eventData.Reset();
            eventData.external = true;
            eventData.target   = target;
            eventData.item     = item;
            target.OnItemEnter(eventData);
            item.OnItemEnter(eventData);
            target.OnItemAttach(eventData);
            item.OnItemAttach(eventData);
            return(true);
        }
        public static bool TryAddItem(DragDropItem item, DragDropTarget target, bool sendCallback = true)
        {
            if (item == null || target == null)
            {
                return(false);
            }
            if (!(item.isActiveAndEnabled && target.isActiveAndEnabled))
            {
                return(false);
            }
            if (item.attachedTarget != null)
            {
                return(false);
            }
            if (!IsChannelMatch(target, item))
            {
                return(false);
            }

            DragDropEventData eventData = new DragDropEventData(!sendCallback);

            eventData.Reset();
            eventData.target = target;
            eventData.item   = item;
            target.OnItemAttach(eventData);
            item.OnItemAttach(eventData);
            return(true);
        }
        protected bool HandleEventForType(DragDropEventTriggerType type, DragDropEventData eventData)
        {
            //Debug.LogError(string.Format("name={0} event={1}",name,type));

            bool handleEvent = false;

            if (callbacks.ContainsKey(type))
            {
                callbacks[type](eventData);
                handleEvent = true;
            }
            return(handleEvent);
        }
        public static int RemoveAllItems(DragDropTarget target, bool sendCallback = true)
        {
            var items = target.GetAllAttachedItems();
            DragDropEventData eventData = new DragDropEventData(!sendCallback);

            eventData.Reset();
            eventData.target = target;
            for (int count = items.Count, i = count - 1; i >= 0; --i)
            {
                DragDropItem item = items[i];
                eventData.item = item;
                target.OnItemDetach(eventData);
                item.OnItemDetach(eventData);
                item.OnSetFree(eventData);
            }
            return(items.Count);
        }
示例#5
0
 public void OnSetFree(DragDropEventData eventData)
 {
     if (lastTarget && attachBackWhenSetFree)
     {
         eventData.target = lastTarget;
         eventData.target.OnItemAttach(eventData);
         OnItemAttach(eventData);
     }
     else
     {
         if (fallbackParent)
         {
             transform.SetParent(fallbackParent, false);
         }
         HandleEventForType(DragDropEventTriggerType.ItemSetFree, eventData);
     }
 }
示例#6
0
        protected bool HandleEventForType(DragDropEventTriggerType type, DragDropEventData eventData)
        {
            //Debug.LogError(string.Format("name={0} event={1}",name,type));

            if (eventData.dummy)
            {
                return(false);
            }

            var evt = GetEvent(type);

            if (evt != null)
            {
                evt.Invoke(eventData);
                return(true);
            }
            return(false);
        }
        internal bool CheckCanAttachItem(DragDropEventData eventData, out DragDropItem replacedItem)
        {
            replacedItem = null;

            if (attachedItems.Count >= maxItemCount)
            {
                if (replaceItem)
                {
                    replacedItem = attachedItems[0];
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
示例#8
0
 public void OnSetFree(DragDropEventData eventData)
 {
     if (lastTarget && lastTarget.isActiveAndEnabled && !eventData.external)
     {
         eventData.target = lastTarget;
         eventData.target.OnItemAttach(eventData);
         OnItemAttach(eventData);
     }
     else if (fallbackTarget && fallbackTarget.isActiveAndEnabled && !eventData.external)
     {
         eventData.target = lastTarget;
         eventData.target.OnItemAttach(eventData);
         OnItemAttach(eventData);
     }
     else
     {
         HandleEventForType(DragDropEventTriggerType.ItemSetFree, eventData);
     }
 }
        public static int RemoveAllItems(DragDropTarget target)
        {
            var items = target.GetAllAttachedItems();
            DragDropEventData eventData = new DragDropEventData();

            eventData.Reset();
            eventData.external = true;
            eventData.target   = target;
            foreach (var item in items)
            {
                eventData.item = item;
                target.OnItemDetach(eventData);
                item.OnItemDetach(eventData);
                target.OnItemExit(eventData);
                item.OnItemExit(eventData);
                item.OnSetFree(eventData);
            }
            return(items.Length);
        }
示例#10
0
        protected bool HandleEventForType(DragDropEventTriggerType type, DragDropEventData eventData)
        {
            //Debug.LogError(string.Format("name={0} event={1}",name,type));

            bool handleEvent = false;

            if (csCallbacks.ContainsKey(type))
            {
                csCallbacks[type](eventData);
                handleEvent = true;
            }
#if USE_LUA_FRAMEWORK
            if (luaCallbacks.ContainsKey(type))
            {
                luaCallbacks[type].Call(eventData);
                handleEvent = true;
            }
#endif
            return(handleEvent);
        }
 public static bool TryRemoveItem(DragDropItem item, DragDropTarget target)
 {
     if (item.attachedTarget == target && target.HasItemAttached(item))
     {
         DragDropEventData eventData = new DragDropEventData();
         eventData.Reset();
         eventData.external = true;
         eventData.target   = target;
         eventData.item     = item;
         target.OnItemDetach(eventData);
         item.OnItemDetach(eventData);
         target.OnItemExit(eventData);
         item.OnItemExit(eventData);
         item.OnSetFree(eventData);
         return(true);
     }
     else
     {
         return(false);
     }
 }
        public static bool TryRemoveItem(DragDropItem item, DragDropTarget target, bool sendCallback = true)
        {
            if (item == null || target == null)
            {
                return(false);
            }

            if (item.attachedTarget == target && target.HasItemAttached(item))
            {
                DragDropEventData eventData = new DragDropEventData(!sendCallback);
                eventData.Reset();
                eventData.target = target;
                eventData.item   = item;
                target.OnItemDetach(eventData);
                item.OnItemDetach(eventData);
                item.OnSetFree(eventData);
                return(true);
            }
            else
            {
                return(false);
            }
        }
 public void OnItemDetach(DragDropEventData eventData)
 {
     attachedTarget = null;
     HandleEventForType(DragDropEventTriggerType.ItemDetach, eventData);
 }
示例#14
0
 public void OnItemAttach(DragDropEventData eventData)
 {
     attachedTarget = eventData.target;
     transform.SetParent(attachedTarget.targetParent, false);
     HandleEventForType(DragDropEventTriggerType.ItemAttach, eventData);
 }
 public void OnItemDragged(DragDropEventData eventData)
 {
     HandleEventForType(DragDropEventTriggerType.ItemDrag, eventData);
 }
 public void OnItemDetach(DragDropEventData eventData)
 {
     attachedItems.Remove(eventData.item);
     HandleEventForType(DragDropEventTriggerType.ItemDetach, eventData);
 }
 public void OnItemAttach(DragDropEventData eventData)
 {
     HandleEventForType(DragDropEventTriggerType.ItemAttach, eventData);
     attachedItems.Add(eventData.item);
 }
 public void OnItemEnter(DragDropEventData eventData)
 {
     HandleEventForType(DragDropEventTriggerType.ItemEnter, eventData);
 }
 public void OnSetFree(DragDropEventData eventData)
 {
     HandleEventForType(DragDropEventTriggerType.ItemSetFree, eventData);
 }
 public void OnClick(DragDropEventData eventData)
 {
     HandleEventForType(DragDropEventTriggerType.ItemClick, eventData);
 }
示例#21
0
 public void OnItemExit(DragDropEventData eventData)
 {
     HandleEventForType(DragDropEventTriggerType.ItemExit, currentEventData);
 }