private void Activate(ItemPlaceholder placeholder)
 {
     if (!CanHandleEvent(placeholder))
     {
         return;
     }
     m_toPlaceholder = placeholder;
 }
        private void Deactivate(ItemPlaceholder placeholder)
        {
            if (!CanHandleEvent(placeholder))
            {
                return;
            }

            if (m_toPlaceholder == placeholder)
            {
                m_toPlaceholder = null;
            }
        }
Exemplo n.º 3
0
        public ItemContainer BindContainer(ItemContainer container, ItemPlaceholder placeholder)
        {
            ItemContainer movedContainer = GetComponentInChildren <ItemContainer>();

            container.transform.SetParent(gameObject.transform);
            container.transform.position = gameObject.transform.position;

            if (movedContainer != null && movedContainer != container)
            {
                placeholder.BindContainer(movedContainer, this);
            }

            return(movedContainer);
        }
        private void OnActivate(object s, CancelEventArgs e)
        {
            ItemPlaceholder placeholder = (ItemPlaceholder)s;

            if (!CanHandleEvent(placeholder))
            {
                return;
            }
            if (m_isDragging)
            {
                Activate(placeholder);
            }
            else
            {
                e.Cancel = true;
            }
        }
        private void BeginDrag(ItemContainer container)
        {
            if (!CanHandleEvent(container))
            {
                return;
            }


            m_fromPlaceholder = container.transform.parent.GetComponent <ItemPlaceholder>();

            if (m_fromPlaceholder != null)
            {
                m_isDragging = true;

                container.transform.SetParent(m_dragSurface.transform);

                m_fromPlaceholder.StartHover();
            }
        }
        private int IndexOf(ItemContainer container)
        {
            ItemPlaceholder placeholder = container.transform.parent.GetComponent <ItemPlaceholder>();

            if (placeholder == null)
            {
                if (m_isDragging)
                {
                    placeholder = m_fromPlaceholder;
                }
            }

            int count = Math.Min(MaxItemsCount, Math.Min(m_placeholders.Length, m_items.Count));

            for (int i = 0; i < count; ++i)
            {
                if (m_placeholders[i] == placeholder)
                {
                    return(i);
                }
            }

            return(-1);
        }
 private bool CanHandleEvent(ItemPlaceholder placeholder)
 {
     return(placeholder.transform.IsChildOf(transform));
 }
        private void Drop(ItemContainer container)
        {
            if (!CanHandleEvent(container))
            {
                return;
            }

            if (!m_isDragging)
            {
                return;
            }

            m_isDragging = false;

            if (m_toPlaceholder == null)
            {
                m_toPlaceholder = m_fromPlaceholder;
            }

            ItemContainer displacedContainer = m_toPlaceholder.GetComponentInChildren <ItemContainer>();

            container.transform.SetParent(m_toPlaceholder.transform);
            container.MoveTo(m_toPlaceholder.transform.position);

            if (displacedContainer != null && displacedContainer != container)
            {
                displacedContainer.transform.SetParent(m_fromPlaceholder.transform);
                displacedContainer.MoveTo(m_fromPlaceholder.transform.position);

                if (ItemDropSound != null)
                {
                    ItemDropSound.Play();
                }
            }


            m_toPlaceholder.StopHover();

            if (m_items == null)
            {
                return;
            }

            if (displacedContainer == null)
            {
                return;
            }


            int fromIndex = IndexOf(displacedContainer);
            int toIndex   = IndexOf(container);

            object tmp = Items[fromIndex];

            Items[fromIndex] = Items[toIndex];
            Items[toIndex]   = tmp;

            if (ItemsArranged != null)
            {
                ItemsArranged(this, EventArgs.Empty);
            }

            m_fromPlaceholder = null;
        }
        private void DataBind()
        {
            if (m_placeholders == null)
            {
                return;
            }

            if (m_items != null)
            {
                for (int i = m_items.Count; i < Math.Min(m_placeholders.Length, MaxItemsCount); ++i)
                {
                    m_items.Add(null);
                }

                int count = Math.Min(MaxItemsCount, Math.Min(m_placeholders.Length, m_items.Count));
                for (int i = 0; i < count; ++i)
                {
                    ItemPlaceholder placeholder = m_placeholders[i];
                    GameObject      container   = (GameObject)Instantiate(ItemContainerPrefab);
                    container.transform.SetParent(placeholder.gameObject.transform, false);
                    ItemContainer itemContainer = container.GetComponent <ItemContainer>();

                    //not sure if we should do this way
                    // GameContoller.Instance.ItemContainers.Add(itemContainer);
                    Debug.Log("ArrangeItemsControl::Databind::Burasý çalýþýyor");

                    if (itemContainer == null)
                    {
                        itemContainer = container.AddComponent <ItemContainer>();
                    }

                    itemContainer.Interactable = m_interactable;

                    object item = m_items[i];
                    if (item == null)
                    {
                        GameObject presenter = (GameObject)Instantiate(EmptyPresenterPrefab);
                        presenter.transform.SetParent(container.transform, false);
                        presenter.transform.SetAsFirstSibling();

                        if (EmptyDataBinding != null)
                        {
                            ItemDataBindingEventArgs args = new ItemDataBindingEventArgs(null, presenter);
                            EmptyDataBinding(this, args);
                            itemContainer.CanDrag = args.CanDrag;
                        }
                        else
                        {
                            itemContainer.CanDrag = false;
                        }
                    }
                    else
                    {
                        GameObject presenter = (GameObject)Instantiate(ItemPresenterPrefab);
                        presenter.transform.SetParent(container.transform, false);
                        presenter.transform.SetAsFirstSibling();

                        if (container != null)
                        {
                            if (ItemDataBinding != null)
                            {
                                ItemDataBindingEventArgs args = new ItemDataBindingEventArgs(item, presenter);
                                ItemDataBinding(this, args);

                                itemContainer.CanDrag = args.CanDrag;
                            }
                            else
                            {
                                itemContainer.CanDrag = true;
                            }
                        }
                    }
                }
            }
        }
 public void SetupItem(ItemPlaceholder itemPlaceholder)
 {
     //when we setup a Item this function handles the setup
 }