예제 #1
0
        /// <summary>
        /// Removes an object from the zone.
        /// </summary>
        public bool RemoveObject(DragObject inDragObject, bool inbForce = false)
        {
            if (!inbForce)
            {
                if (!AllowRemoveObject(inDragObject))
                {
                    return(false);
                }
            }
            else
            {
                Assert.True(m_Objects.Count > MinAllowed, "Valid to remove this object.");
            }

            Assert.True(inDragObject != null, "DragObject is not null.", "Cannot remove null DragObject from a DropZone.");
            Assert.True(m_Objects.Contains(inDragObject), "DragObject has not been removed.", "Cannot remove a DragObject twice.");

            m_Objects.Remove(inDragObject);
            inDragObject.SetIndex(-1);

            for (int i = 0; i < m_Objects.Count; ++i)
            {
                DragObject obj = m_Objects[i];
                obj.SetIndex(i, true);
            }

            if (OnObjectRemoved != null)
            {
                OnObjectRemoved(this, inDragObject);
            }

            return(true);
        }
예제 #2
0
        /// <summary>
        /// Adds an object to the zone.
        /// </summary>
        public bool AddObject(DragObject inDragObject, bool inbForce = false)
        {
            if (!inbForce)
            {
                if (!AllowAddObject(inDragObject))
                {
                    return(false);
                }
            }
            else
            {
                Assert.True(m_Objects.Count < MaxAllowed, "Valid to add this object.");
            }

            Assert.True(inDragObject != null, "DragObject is not null.", "Cannot add null DragObject to a DragZone.");
            Assert.True(!m_Objects.Contains(inDragObject), "DragObject has not been added.", "Cannot add a DragObject twice.");

            m_Objects.Add(inDragObject);
            int objectIndex = m_Objects.Count - 1;

            if (AutoSort && SortMethod != null)
            {
                m_Objects.Sort(SortMethod);
                for (int i = 0; i < m_Objects.Count; ++i)
                {
                    DragObject obj = m_Objects[i];
                    if (obj == inDragObject)
                    {
                        objectIndex = i;
                    }
                    else
                    {
                        obj.SetIndex(i, true);
                    }
                }
            }
            inDragObject.SetIndex(objectIndex, false);

            if (OnObjectAdded != null)
            {
                OnObjectAdded(this, inDragObject);
            }

            return(true);
        }
예제 #3
0
        /// <summary>
        /// Removes an object at the given index from the zone.
        /// </summary>
        public DragObject RemoveObjectAt(int inIndex)
        {
            Assert.True(inIndex >= 0 && inIndex < m_Objects.Count, "Index is valid.", "Cannot remove DragObject at {0} - only {1} exist.", inIndex, m_Objects.Count);

            DragObject objectAt = m_Objects[inIndex];

            m_Objects.RemoveAt(inIndex);
            objectAt.SetIndex(-1);

            for (int i = 0; i < m_Objects.Count; ++i)
            {
                DragObject obj = m_Objects[i];
                obj.SetIndex(i, true);
            }

            if (OnObjectRemoved != null)
            {
                OnObjectRemoved(this, objectAt);
            }

            return(objectAt);
        }