コード例 #1
0
 /// <summary>
 /// On any item drag start need to disable all items raycast for correct drop operation
 /// </summary>
 /// <param name="item"> dragged item </param>
 private void OnAnyItemDragStart(DragAndDropItem item)
 {
     UpdateMyItem();
     if (myDadItem != null)
     {
         myDadItem.MakeRaycast(false);                                   // Disable item's raycast for correct drop handling
         if (myDadItem == item)                                          // If item dragged from this cell
         {
             // Check cell's type
             switch (cellType)
             {
             case CellType.DropOnly:
                 DragAndDropItem.icon.SetActive(false);                  // Item can not be dragged. Hide icon
                 break;
             }
         }
     }
 }
コード例 #2
0
    /// <summary>
    /// This item is dropped
    /// </summary>
    /// <param name="eventData"></param>
    public void OnEndDrag(PointerEventData eventData)
    {
        MouseInput mouseInput = GameObject.FindObjectOfType <MouseInput> ();

        mouseInput.isDragging = false;
        if (icon != null)
        {
            Destroy(icon);                                                          // Destroy icon on item drop
        }
        MakeVisible(true);                                                          // Make item visible in cell
        if (OnItemDragEndEvent != null)
        {
            OnItemDragEndEvent(this);                                               // Notify all cells about item drag end
        }
        draggedItem = null;
        icon        = null;
        sourceCell  = null;
    }
コード例 #3
0
    /// <summary>
    /// Put item into this cell.
    /// </summary>
    /// <param name="item">Item.</param>
    private void PlaceItem(DragAndDropItem item)
    {
        if (item != null)
        {
            DestroyItem();                                                              // Remove current item from this cell
            myDadItem = null;
            DragAndDropCell cell = item.GetComponentInParent <DragAndDropCell>();
            if (cell != null)
            {
                if (cell.unlimitedSource == true)
                {
                    string itemName = item.name;
                    item      = Instantiate(item);                                              // Clone item from source cell
                    item.name = itemName;
                }
            }
            item.transform.SetParent(transform, false);
            item.transform.localPosition = Vector3.zero;
            item.MakeRaycast(true);

            myDadItem = item;
            myDadItem.GetComponent <CanvasGroup>().alpha = 0.5f; //Hace que el item no sea visible cuando llega a la boca

            GameObject       canvas    = gameObject.transform.parent.gameObject;
            AtributosMascota atributos = canvas.transform.Find("MANAGER CANVAS").GetComponent <AtributosMascota>();

            Animator anim = LINCE.GetComponent <Animator>();
            anim.SetInteger("estaComiendo", 2);

            GestionComida gestorComida = canvas.transform.Find("Plato").GetComponent <GestionComida>();
            GameObject    comida       = canvas.transform.Find("Plato").gameObject.transform.Find("Comida").gameObject;
            TMP_Text      porcentaje   = canvas.transform.Find("Plato").gameObject.transform.Find("Porcentaje").gameObject.GetComponent <TMP_Text>();
            comida.GetComponent <DragAndDropItem>().enabled = false;;
            atributos.subirHambre(int.Parse(porcentaje.text));
            gestorComida.EliminarItem(item.gameObject);
            Image imagen = comida.GetComponent <Image>();
            imagen.color = new Color(imagen.color.r, imagen.color.g, imagen.color.b, 0.5f); //Item del plato

            StartCoroutine(ExecuteAfterTime(3));
        }

        UpdateBackgroundState();
    }
コード例 #4
0
 /// <summary>
 /// Destroy item in this cell
 /// </summary>
 private void DestroyItem()
 {
     UpdateMyItem();
     if (myDadItem != null)
     {
         DropEventDescriptor desc = new DropEventDescriptor();
         // Fill event descriptor
         desc.triggerType     = TriggerType.ItemWillBeDestroyed;
         desc.item            = myDadItem;
         desc.sourceCell      = this;
         desc.destinationCell = this;
         SendNotification(desc);                                         // Notify application about item destruction
         if (myDadItem != null)
         {
             Destroy(myDadItem.gameObject);
         }
     }
     myDadItem = null;
 }
コード例 #5
0
    public DragAndDropItem CreateBox(KeyValuePair <int, Color32> item, RectTransform rect)
    {
        DragAndDropItem it = Instantiate(box, rect, false);

        it.GetComponent <Image>().color = item.Value;

        RectTransform r = it.GetComponent <RectTransform>();

        r.sizeDelta = GetMenuSize();

        it.GetComponentInChildren <Text>().text = LayersConstants.LAYER_NAMES[item.Key];

        it.GetComponentInChildren <Text>().color = new Color32(255, 255, 255, 255);

        it.name = LayersConstants.LAYER_NAMES[item.Key];

        it.isIcon = true;

        return(it);
    }
コード例 #6
0
        private void OnAnyItemDragStart(DragAndDropItem item, PointerEventData eventData)
        {
            float num = NewModulesScreenUIComponent.OVER_SCREEN_Z_OFFSET;

            if (!ModulesTutorialUtil.TUTORIAL_MODE)
            {
                this.background.SetActive(true);
                this.background.transform.SetAsLastSibling();
                Vector3 vector = this.background.GetComponent <RectTransform>().anchoredPosition3D;
                vector.z = (num * 0.5f) - 0.01f;
                this.background.GetComponent <RectTransform>().anchoredPosition3D = vector;
            }
            this.HighlightPossibleSlots();
            this.MoveDraggingCardInFronfOfAll(num + OVER_ITEM_Z_OFFSET);
            DragAndDropItem.draggedItemContentCopy.transform.GetChild(0).GetComponent <Animator>().SetInteger("colorCode", 1);
            if (DragAndDropItem.sourceCell.GetComponent <SlotView>() is CollectionSlotView)
            {
                this.changeSize = true;
            }
        }
コード例 #7
0
    private void _RemoveLine(DragAndDropItem layer)
    {
        List <string> keys = new List <string>();

        if (layer.ancestor != null)
        {
            keys.Add(this._MakeKeyString(layer.id, layer.ancestor.id));
        }

        if (layer.children != null)
        {
            keys.Add(this._MakeKeyString(layer.id, layer.children.id));
        }

        foreach (string key in keys)
        {
            Destroy(this.LineLookUp[key]);
            this.LineLookUp.Remove(key);
        }
    }
コード例 #8
0
 public void OnBeginDrag(PointerEventData eventData)
 {
     if (eventData.button != PointerEventData.InputButton.Right)
     {
         sourceCell             = base.GetComponentInParent <DragAndDropCell>();
         draggedItem            = this;
         draggedItemContentCopy = this.GetCopy(this.itemContent);
         Canvas componentInParent = sourceCell.transform.parent.GetComponentInParent <Canvas>();
         if (componentInParent != null)
         {
             draggedItemContentCopy.transform.SetParent(componentInParent.transform, false);
             draggedItemContentCopy.transform.SetAsLastSibling();
         }
         this.MakeVisible(false);
         if (OnItemDragStartEvent != null)
         {
             OnItemDragStartEvent(this, eventData);
         }
     }
 }
コード例 #9
0
 /// <summary>
 /// This item is dropped
 /// </summary>
 /// <param name="eventData"></param>
 public void OnEndDrag(PointerEventData eventData)
 {
     if (icon != null)
     {
         source.Play();
         var screenPoint = Input.mousePosition;
         screenPoint.z           = 10.0f;
         icon.transform.position = Camera.main.ScreenToWorldPoint(screenPoint);
         GameManager.instance.CreatePower(power, icon.transform.position);
         Destroy(icon);                                                          // Destroy icon on item drop
         SetBackgroundState(false);
     }
     MakeVisible(true);                                                          // Make item visible in cell
     if (OnItemDragEndEvent != null)
     {
         OnItemDragEndEvent(this);                                               // Notify all cells about item drag end
     }
     draggedItem = null;
     icon        = null;
 }
コード例 #10
0
    private static bool isCyclicUtil(int id, bool[] isVisited, int parent)
    {
        isVisited[id] = true;
        DragAndDropItem curNode = getNodeByID(id);
        int             childID = curNode.children.id;

        if (!isVisited[childID])
        {
            if (isCyclicUtil(childID, isVisited, id))
            {
                return(true);
            }
        }
        else if (childID != parent)
        {
            return(true);
        }

        return(false);
    }
コード例 #11
0
    /// <summary>
    /// This item is dropped
    /// </summary>
    /// <param name="eventData"></param>
    public void OnEndDrag(PointerEventData eventData)
    {
        if (icon != null)
        {
            Destroy(icon);                                                          // Destroy icon on item drop
        }
        MakeVisible(true);                                                          // Make item visible in cell
        if (OnItemDragEndEvent != null)
        {
            OnItemDragEndEvent(this);                                               // Notify all cells about item drag end
        }
        GameObject child      = draggedItem.transform.GetChild(0).gameObject;
        GameObject parentCell = draggedItem.transform.parent.gameObject;

        draggedItem.GetComponent <RectTransform> ().sizeDelta = parentCell.GetComponent <RectTransform> ().sizeDelta;
        child.GetComponent <RectTransform> ().sizeDelta       = parentCell.GetComponent <RectTransform> ().sizeDelta;
        draggedItem = null;
        icon        = null;
        sourceCell  = null;
    }
コード例 #12
0
    /// <summary>
    /// Put new item in this cell
    /// </summary>
    /// <param name="itemObj"> New item's object with DragAndDropItem script </param>
    public void PlaceItem(GameObject itemObj)
    {
        //RemoveItem();                                                       // Remove current item from this cell
        if (itemObj != null)
        {
            itemObj.transform.SetParent(transform, false);
            itemObj.transform.localPosition = Vector3.zero;
            DragAndDropItem item = itemObj.GetComponent <DragAndDropItem>();
            if (item != null)
            {
                item.MakeRaycast(true);
            }
            SetBackgroundState(true);
        }

        foreach (Transform child in transform)
        {
            print("Foreach loop: " + child);
        }//foreach
        print("Done");
    }
コード例 #13
0
    /// <summary>
    /// Swap items between two cells
    /// </summary>
    /// <param name="firstCell"> Cell </param>
    /// <param name="secondCell"> Cell </param>
    public void SwapItems(DragAndDropCell firstCell, DragAndDropCell secondCell)
    {
        if ((firstCell != null) && (secondCell != null))
        {
            DragAndDropItem firstItem  = DragAndDropItem.draggedItem;       // Get item from first cell
            DragAndDropItem secondItem = secondCell.GetItem();              // Get item from second cell
                                                                            // Swap items
            if (secondItem != null)
            {
                if (secondItem.transform.parent != null)
                {
                    secondItem.transform.parent.DetachChildren();
                    DragAndDropItem tempItem = Instantiate(secondItem);
                    tempItem.GetComponent <PorteScript>().SetEntree1(false);
                    tempItem.GetComponent <PorteScript>().SetEntree2(false);
                    tempItem.GetComponent <PorteScript>().SetSortie(false);

                    Destroy(secondItem.gameObject);
                    secondItem = null;
                    secondItem = tempItem;
                }
                secondItem.transform.SetParent(firstCell.transform, false);
                secondItem.transform.localPosition = Vector3.zero;
                secondItem.MakeRaycast(true);
            }
            if (firstItem != null)
            {
                firstItem.transform.SetParent(secondCell.transform, false);
                firstItem.transform.localPosition = Vector3.zero;
                firstItem.MakeRaycast(true);
            }

            // Update states
            firstCell.UpdateMyItem();
            secondCell.UpdateMyItem();
            //Debug.Log(secondItem.GetComponent<PorteScript>().IsSortie());
            //firstCell.UpdateBackgroundState();
            //secondCell.UpdateBackgroundState();
        }
    }
コード例 #14
0
    /// <summary>
    /// Put item into this cell.
    /// </summary>
    /// <param name="item">Item.</param>
    private void PlaceItem(DragAndDropItem item)
    {
        if (item != null)
        {
            /*DestroyItem();                                                // Remove current item from this cell
             *          myDadItem = null;
             *          DragAndDropCell cell = item.GetComponentInParent<DragAndDropCell>();
             *          if (cell != null)
             *          {
             *                  if (cell.unlimitedSource == true)
             *                  {
             *                          string itemName = item.name;
             *                          item = Instantiate(item);                               // Clone item from source cell
             *                          item.name = itemName;
             *                  }
             *          }*/
            if (item.transform.parent != null)
            {
                item.transform.parent.DetachChildren();
                DragAndDropItem tempItem = Instantiate(item);
                tempItem.GetComponent <PorteScript>().SetEntree1(false);
                tempItem.GetComponent <PorteScript>().SetEntree2(false);
                tempItem.GetComponent <PorteScript>().SetSortie(false);

                Destroy(item.gameObject);
                item = null;
                item = tempItem;
            }

            item.transform.SetParent(this.transform, false);
            item.transform.localPosition = Vector3.zero;
            item.MakeRaycast(true);

            /*item.transform.SetParent(transform, false);
             *          item.transform.localPosition = Vector3.zero;
             *          item.MakeRaycast(true);
             *          myDadItem = item;*/
        }
        UpdateBackgroundState();
    }
コード例 #15
0
    /// <summary>
    /// Swap items between to cells
    /// </summary>
    /// <param name="firstCell"> Cell </param>
    /// <param name="secondCell"> Cell </param>
    public void SwapItems(DragAndDropCell firstCell, DragAndDropCell secondCell)
    {
        if ((firstCell != null) && (secondCell != null))
        {
            DragAndDropItem firstItem  = firstCell.GetItem();               // Get item from first cell
            DragAndDropItem secondItem = secondCell.GetItem();              // Get item from second cell

            ItemSlot slot1 = firstCell.GetComponent <ItemSlot>();
            ItemSlot slot2 = secondCell.GetComponent <ItemSlot>();

            Item  item1  = slot1.item;
            Image image1 = slot1.image;
            Text  text1  = slot1.counterText;

            Item  item2  = slot2.item;
            Image image2 = slot2.image;
            Text  text2  = slot2.counterText;

            if (firstItem != null)
            {
                slot1.item        = item2;
                slot1.image       = image2;
                slot1.counterText = text2;
                // Place first item into second cell
                firstItem.transform.SetParent(secondCell.transform, false);
                firstItem.transform.localPosition = Vector3.zero;
                secondCell.SetBackgroundState(true);
            }
            if (secondItem != null)
            {
                slot2.item        = item1;
                slot2.image       = image1;
                slot2.counterText = text1;
                // Place second item into first cell
                secondItem.transform.SetParent(firstCell.transform, false);
                secondItem.transform.localPosition = Vector3.zero;
                firstCell.SetBackgroundState(true);
            }
        }
    }
コード例 #16
0
 /// <summary>
 /// Put item into this cell.
 /// </summary>
 /// <param name="item">Item.</param>
 private void PlaceItem(DragAndDropItem item)
 {
     if (item != null)
     {
         DestroyItem();                                              // Remove current item from this cell
         myDadItem = null;
         DragAndDropCell cell = item.GetComponentInParent <DragAndDropCell>();
         if (cell != null)
         {
             if (cell.unlimitedSource == true)
             {
                 string itemName = item.name;
                 item      = Instantiate(item);                          // Clone item from source cell
                 item.name = itemName;
             }
         }
         item.transform.SetParent(transform, false);
         item.transform.localPosition = Vector3.zero;
         item.MakeRaycast(true);
         myDadItem = item;
     }
 }
コード例 #17
0
 /// <summary>
 /// Swap items between to cells
 /// </summary>
 /// <param name="firstCell"> Cell </param>
 /// <param name="secondCell"> Cell </param>
 public void SwapItems(DragAndDropCell firstCell, DragAndDropCell secondCell)
 {
     if ((firstCell != null) && (secondCell != null))
     {
         DragAndDropItem firstItem  = firstCell.GetItem();               // Get item from first cell
         DragAndDropItem secondItem = secondCell.GetItem();              // Get item from second cell
         if (firstItem != null)
         {
             // Place first item into second cell
             firstItem.transform.SetParent(secondCell.transform, false);
             firstItem.transform.localPosition = Vector3.zero;
             secondCell.SetBackgroundState(true);
         }
         if (secondItem != null)
         {
             // Place second item into first cell
             secondItem.transform.SetParent(firstCell.transform, false);
             secondItem.transform.localPosition = Vector3.zero;
             firstCell.SetBackgroundState(true);
         }
     }
 }
コード例 #18
0
        public void AttackwithCard(DragAndDropCell cardSlot, DragAndDropItem draggedCardImage)
        {
            //Not sure why I have to re-apply the image??
            Image  cardImage  = draggedCardImage.GetComponentInChildren <Image>();
            string spriteName = cardImage.sprite.name;

            draggedCardImage.GetComponentInChildren <Image>().sprite = Resources.Load <Sprite>("PlayingCards/" + spriteName);

            int cardNumber  = Convert.ToInt32(Regex.Replace(spriteName, "_.*", ""));
            int suiteNumber = GetSuiteNumber(Regex.Replace(spriteName, ".*_", ""));

            CardConstants.Card  card      = (CardConstants.Card)cardNumber;
            CardConstants.Suite suite     = (CardConstants.Suite)suiteNumber;
            CardValue           cardValue = new CardValue(card, suite);

            Debug.Log("CardNumber: " + cardNumber + " SuiteNumber: " + suiteNumber);

            GameObject.Destroy(cardSlot.gameObject);
            Deck.Singleton.DiscardPlayedCard(cardValue);

            //Send Match message that an attack was made <cardNum>:<suiteName>
            if (!gameTesting)
            {
                MatchController.Singleton.SendMatchData(4, cardNumber + ":" + suiteNumber);
            }

            StartCoroutine(ShowDamage(oppDamageCG));
            GameData.Singleton.OpponentHealth      -= cardNumber;
            GameData.Singleton.PlayerScore         += (cardNumber * 10) / currentRound;
            GameData.Singleton.PlayerDamage        += cardNumber;
            GameData.Singleton.OpponentDamageTaken += cardNumber;
            if (GameData.Singleton.OpponentHealth < 1)
            {
                OpponentDied();
            }

            NewTurn(oppNumber);
            MatchController.Singleton.SendMatchData(oppNumber, "");
        }
コード例 #19
0
    /// <summary>
    /// Resets all temporary conditions.
    /// </summary>
    private void ResetConditions()
    {
        if (icon != null)
        {
            Destroy(icon);                                                                      // Destroy icon on item drop
        }

        if (draggedItem != null && draggedItem.transform.parent == null)
        {
            draggedItem.transform.SetParent(sourceCell.transform, false);
            draggedItem.transform.localPosition = Vector3.zero;
        }

        if (OnItemDragEndEvent != null)
        {
            OnItemDragEndEvent(this);                                                                   // Notify all cells about item drag end
        }

        draggedItem = null;
        icon        = null;
        sourceCell  = null;
    }
コード例 #20
0
    /// <summary>
    /// This item started to drag.
    /// </summary>
    /// <param name="eventData"></param>
    public void OnBeginDrag(PointerEventData eventData)
    {
        if (dragDisabled == false)
        {
            sourceCell  = GetCell();                                                                    // Remember source cell
            draggedItem = this;                                                                         // Set as dragged item
            // Create item's icon
            icon = new GameObject();
            icon.transform.SetParent(canvas.transform);
            icon.name = "Icon";
            Image myImage = GetComponent <Image>();

            myImage.raycastTarget = false;                                                      // Disable icon's raycast for correct drop handling
            Image iconImage = icon.AddComponent <Image>();
            iconImage.raycastTarget = false;
            iconImage.sprite        = myImage.sprite;


            float r = myImage.color.r;
            float g = myImage.color.g;
            float b = myImage.color.b;
            myImage.color = new Color(r, g, b, 0);


            RectTransform iconRect = icon.GetComponent <RectTransform>();
            // Set icon's dimensions
            RectTransform myRect = GetComponent <RectTransform>();
            iconRect.pivot     = new Vector2(0.5f, 0.5f);
            iconRect.anchorMin = new Vector2(0.5f, 0.5f);
            iconRect.anchorMax = new Vector2(0.5f, 0.5f);
            iconRect.sizeDelta = new Vector2(myRect.rect.width, myRect.rect.height);

            if (OnItemDragStartEvent != null)
            {
                OnItemDragStartEvent(this);                                                                     // Notify all items about drag start for raycast disabling
            }
        }
    }
コード例 #21
0
ファイル: InventoryScreen.cs プロジェクト: ThePerian/FTR
    void AddItemToCell(InventoryItem item, DragAndDropCell cell)
    {
        if (cell == null)
        {
            return;
        }

        if (item == null)
        {
            DragAndDropItem itemController = cell.GetComponentInChildren <DragAndDropItem>();
            if (itemController != null)
            {
                Destroy(itemController.gameObject);
            }
            return;
        }

        GameObject newItem = Instantiate(inventoryItemPrefab);

        newItem.GetComponent <DragAndDropItem>().item = item;
        newItem.GetComponent <Image>().sprite         = item.icon ?? defaultSprite;
        newItem.GetComponent <Transform>().SetParent(cell.GetComponent <Transform>());
    }
コード例 #22
0
 /// <summary>
 /// Swap items between two cells
 /// </summary>
 /// <param name="firstCell"> Cell </param>
 /// <param name="secondCell"> Cell </param>
 public void SwapItems(DragAndDropCell firstCell, DragAndDropCell secondCell)
 {
     if ((firstCell != null) && (secondCell != null))
     {
         DragAndDropItem firstItem  = firstCell.GetItem();               // Get item from first cell
         DragAndDropItem secondItem = secondCell.GetItem();              // Get item from second cell
                                                                         // Swap items
         if (firstItem != null)
         {
             firstItem.transform.SetParent(secondCell.transform, false);
             firstItem.transform.localPosition = Vector3.zero;
             firstItem.MakeRaycast(true);
         }
         if (secondItem != null)
         {
             secondItem.transform.SetParent(firstCell.transform, false);
             secondItem.transform.localPosition = Vector3.zero;
             secondItem.MakeRaycast(true);
         }
         // Update states
         firstCell.UpdateMyItem();
         secondCell.UpdateMyItem();
     }
 }
コード例 #23
0
 /// <summary>
 /// This item is dragged
 /// </summary>
 /// <param name="eventData"></param>
 public void OnBeginDrag(PointerEventData eventData)
 {
     sourceCell = GetComponentInParent<DragAndDropCell>();                       // Remember source cell
     draggedItem = this;                                                         // Set as dragged item
     icon = new GameObject("Icon");                                              // Create object for item's icon
     Image image = icon.AddComponent<Image>();
     image.sprite = GetComponent<Image>().sprite;
     image.raycastTarget = false;                                                // Disable icon's raycast for correct drop handling
     RectTransform iconRect = icon.GetComponent<RectTransform>();
     // Set icon's dimensions
     iconRect.sizeDelta = new Vector2(   GetComponent<RectTransform>().sizeDelta.x,
                                         GetComponent<RectTransform>().sizeDelta.y);
     Canvas canvas = GetComponentInParent<Canvas>();                             // Get parent canvas
     if (canvas != null)
     {
         // Display on top of all GUI (in parent canvas)
         icon.transform.SetParent(canvas.transform, true);                       // Set canvas as parent
         icon.transform.SetAsLastSibling();                                      // Set as last child in canvas transform
     }
     if (OnItemDragStartEvent != null)
     {
         OnItemDragStartEvent(this);                                             // Notify all about item drag start
     }
 }
コード例 #24
0
    private void Start()
    {
        KeyValuePair <int, Color32> kv = new KeyValuePair <int, Color32>(
            Constants.LayersConstants.INPUT,
            Constants.LayersConstants.LAYER_COLORS[Constants.LayersConstants.INPUT]
            );

        DragAndDropItem item = GenerateLayers.Instance.CreateBox(kv, ContentSpace.instance.MyRect);

        item.id     = ++DragAndDropItem.count;
        item.isIcon = false;
        item.tag    = DragAndDropItem.myTag;
        item.transform.GetChild(0).tag = DragAndDropItem.myTag;

        RectTransform rec = item.GetComponent <RectTransform>();

        rec.anchorMin = new Vector2(0.5f, .5f);
        rec.anchorMax = new Vector2(0.5f, .5f);
        rec.SetParent(ContentSpace.instance.transform);

        rec.anchoredPosition3D = new Vector3(0f, 200f, -10f);

        StateManager.Instance.LayerLookUp[item.id.ToString()] = item.gameObject;
    }
コード例 #25
0
 /// <summary>
 /// Updates my item
 /// </summary>
 public void UpdateMyItem()
 {
     myDadItem = GetComponentInChildren <DragAndDropItem>();
 }
コード例 #26
0
    /// <summary>
    /// Item is dropped in this cell
    /// </summary>
    /// <param name="data"></param>
    public void OnDrop(PointerEventData data)
    {
        if (DragAndDropItem.icon != null)
        {
            DragAndDropItem item       = DragAndDropItem.draggedItem;
            DragAndDropCell sourceCell = DragAndDropItem.sourceCell;
            if (DragAndDropItem.icon.activeSelf == true)                    // If icon inactive do not need to drop item into cell
            {
                if ((item != null) && (sourceCell != this))
                {
                    // if (item.equipmentType.Equals(equipmentType) || equipmentType.Equals(EquipmentType.Generic))
                    // {

                    DropEventDescriptor desc = new DropEventDescriptor();
                    switch (cellType)                                       // Check this cell's type
                    {
                    case CellType.Swap:                                     // Item in destination cell can be swapped
                        UpdateMyItem();
                        switch (sourceCell.cellType)
                        {
                        case CellType.Swap:                                 // Item in source cell can be swapped
                                                                            // Fill event descriptor
                            desc.item            = item;
                            desc.sourceCell      = sourceCell;
                            desc.destinationCell = this;
                            SendRequest(desc);                            // Send drop request
                            StartCoroutine(NotifyOnDragEnd(desc));        // Send notification after drop will be finished
                            if (desc.permission == true)                  // If drop permitted by application
                            {
                                if (myDadItem != null)                    // If destination cell has item
                                {
                                    // Fill event descriptor
                                    DropEventDescriptor descAutoswap = new DropEventDescriptor();
                                    descAutoswap.item            = myDadItem;
                                    descAutoswap.sourceCell      = this;
                                    descAutoswap.destinationCell = sourceCell;
                                    SendRequest(descAutoswap);                              // Send drop request
                                    StartCoroutine(NotifyOnDragEnd(descAutoswap));          // Send notification after drop will be finished
                                    if (descAutoswap.permission == true)                    // If drop permitted by application
                                    {
                                        SwapItems(sourceCell, this);                        // Swap items between cells
                                    }
                                    else
                                    {
                                        PlaceItem(item);                    // Delete old item and place dropped item into this cell
                                    }
                                }
                                else
                                {
                                    PlaceItem(item);                        // Place dropped item into this empty cell
                                }
                            }
                            break;

                        default:                                            // Item in source cell can not be swapped
                                                                            // Fill event descriptor
                            desc.item            = item;
                            desc.sourceCell      = sourceCell;
                            desc.destinationCell = this;
                            SendRequest(desc);                              // Send drop request
                            StartCoroutine(NotifyOnDragEnd(desc));          // Send notification after drop will be finished
                            if (desc.permission == true)                    // If drop permitted by application
                            {
                                PlaceItem(item);                            // Place dropped item into this cell
                            }
                            break;
                        }
                        break;

                    case CellType.DropOnly:                                 // Item only can be dropped into destination cell
                                                                            // Fill event descriptor
                        desc.item            = item;
                        desc.sourceCell      = sourceCell;
                        desc.destinationCell = this;
                        SendRequest(desc);                                  // Send drop request
                        StartCoroutine(NotifyOnDragEnd(desc));              // Send notification after drop will be finished
                        if (desc.permission == true)                        // If drop permitted by application
                        {
                            PlaceItem(item);                                // Place dropped item in this cell
                        }
                        break;

                    default:
                        break;
                    }
                }
                //}
            }
            if (item != null)
            {
                if (item.GetComponentInParent <DragAndDropCell>() == null)  // If item have no cell after drop
                {
                    Destroy(item.gameObject);                               // Destroy it
                }
            }
            UpdateMyItem();
            UpdateBackgroundState();
            sourceCell.UpdateMyItem();
            sourceCell.UpdateBackgroundState();
        }
    }
コード例 #27
0
 /// <summary>
 /// This item is dragged
 /// </summary>
 public void OnDragStart()
 {
     dragedItem = null;
     sourceCell = null;
     if (dragEnabled == true)
     {
         sourceCell = GetComponentInParent<DragAndDropCell>();                   // Remember source cell
         dragedItem = this;                                                      // Set as dragged item
         MakeRaycast(false);                                                     // Disable raycast
         Canvas canvas = GetComponentInParent<Canvas>();                         // Get parent canvas
         if (canvas != null)
         {
             // Displya on top of all GUI (in current canvas)
             canvasTransform = canvas.transform;                                 // Remember parent canvas transform
             transform.SetParent(canvasTransform, true);                         // Set canvas as parent
             transform.SetAsLastSibling();                                       // Set as last child in canvas transform
         }
         if (OnItemDragStartEvent != null)
         {
             OnItemDragStartEvent();                                             // Notify all about item drag start
         }
         if (sourceCell != null)
         {
             sourceCell.ItemDragStart();                                         // Notify source cell about item drag start
         }
     }
 }
コード例 #28
0
    /// <summary>
    /// Item is dropped in this cell
    /// </summary>
    /// <param name="data"></param>
    public void OnDrop(PointerEventData data)
    {
        if (DragAndDropItem.icon != null)
        {
            DragAndDropItem item       = DragAndDropItem.draggedItem;
            DragAndDropCell sourceCell = DragAndDropItem.sourceCell;
            if (DragAndDropItem.icon.activeSelf == true)
            {
                if ((item != null) && (sourceCell != this))
                {
                    DropEventDescriptor desc = new DropEventDescriptor();
                    switch (cellType)
                    {
                    case CellType.Swap:                                     // Item in destination cell can be swapped
                        UpdateMyItem();
                        switch (sourceCell.cellType)
                        {
                        case CellType.Swap:                                 // Item in source cell can be swapped
                            // Fill event descriptor
                            desc.item            = item;
                            desc.sourceCell      = sourceCell;
                            desc.destinationCell = this;
                            SendRequest(desc);                             // Send drop request
                            StartCoroutine(NotifyOnDragEnd(desc));         // Send notification after drop will be finished
                            if (desc.permission == true)                   // If drop permitted by application
                            {
                                if (myDadItem != null)                     // If destination cell has item
                                // Fill event descriptor
                                {
                                    DropEventDescriptor descAutoswap = new DropEventDescriptor();
                                    descAutoswap.item            = myDadItem;
                                    descAutoswap.sourceCell      = this;
                                    descAutoswap.destinationCell = sourceCell;
                                    SendRequest(descAutoswap);                              // Send drop request
                                    StartCoroutine(NotifyOnDragEnd(descAutoswap));          // Send notification after drop will be finished
                                    if (descAutoswap.permission == true)                    // If drop permitted by application
                                    // stack or swap
                                    {
                                        var movingCell  = this.myDadItem.gameObject;
                                        var currentCell = sourceCell.transform.GetChild(0).gameObject;
                                        if (!InventoryService.CanStack(currentCell, movingCell))
                                        {
                                            SwapItems(sourceCell, this);                     // Swap items between cells
                                        }
                                    }
                                    else
                                    {
                                        PlaceItem(item);                    // Delete old item and place dropped item into this cell
                                    }
                                }
                                else
                                {
                                    PlaceItem(item);                        // Place dropped item into this empty cell
                                }
                            }
                            InventoryService.RefreshToolBar();
                            break;

                        default:                                            // Item in source cell can not be swapped
                            // Fill event descriptor
                            desc.item            = item;
                            desc.sourceCell      = sourceCell;
                            desc.destinationCell = this;
                            SendRequest(desc);                              // Send drop request
                            StartCoroutine(NotifyOnDragEnd(desc));          // Send notification after drop will be finished
                            if (desc.permission == true)                    // If drop permitted by application
                            {
                                PlaceItem(item);                            // Place dropped item into this cell
                            }
                            break;
                        }
                        break;

                    case CellType.DropOnly:                                 // Item only can be dropped into destination cell
                        // Fill event descriptor
                        desc.item            = item;
                        desc.sourceCell      = sourceCell;
                        desc.destinationCell = this;
                        SendRequest(desc);                                  // Send drop request
                        StartCoroutine(NotifyOnDragEnd(desc));              // Send notification after drop will be finished
                        if (desc.permission == true)                        // If drop permitted by application
                        {
                            PlaceItem(item);                                // Place dropped item in this cell
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            if (item != null)
            {
                if (item.GetComponentInParent <DragAndDropCell>() == null)  // If item have no cell after drop
                {
                    Destroy(item.gameObject);                               // Destroy it
                }
            }
            UpdateMyItem();
            UpdateBackgroundState();
            sourceCell.UpdateMyItem();
            sourceCell.UpdateBackgroundState();
        }
    }
コード例 #29
0
    public void Remove(DragAndDropItem layer)
    {
        LayerLookUp.Remove(layer.id.ToString());

        _RemoveLine(layer);
    }
コード例 #30
0
    void ShortcutParser(SqlDataReader reader)
    {
        GameObject[] temp = Shortcut.GetComponent <Shortcut>().ShortCutArray;
        UIController ctrl = skill.GetComponent <UIController>();
        Shop         shop = shopObject.GetComponent <Shop>();

        for (int i = 0; i < reader.FieldCount; i++)
        {
            if (reader.GetValue(i) != null)
            {
                switch (reader.GetName(i).ToLower())
                {
                case "shortcut_1_id":
                    if (reader.GetInt32(i) > 200 && reader.GetInt32(i) < 300)
                    {
                        temp[0].GetComponent <DragAndDropCell>().PlaceItem(Instantiate(ctrl.FindSkillDADItemByID(reader.GetInt32(i))));
                    }
                    else if (reader.GetInt32(i) != -1)
                    {
                        Item            item         = shop.findItemByID(reader.GetInt32(i));
                        GameObject      itemTemplate = Instantiate(TemplateItem);
                        DragAndDropItem tempDadItem  = itemTemplate.transform.GetChild(0).GetComponent <DragAndDropItem>();
                        tempDadItem.gameObject.GetComponent <Image>().sprite = item.sprite;
                        tempDadItem.item = item;
                        temp[0].GetComponent <DragAndDropCell>().PlaceItem(tempDadItem);
                    }
                    break;

                case "shortcut_2_id":
                    if (reader.GetInt32(i) > 200 && reader.GetInt32(i) < 300)
                    {
                        temp[1].GetComponent <DragAndDropCell>().PlaceItem(Instantiate(ctrl.FindSkillDADItemByID(reader.GetInt32(i))));
                    }
                    else if (reader.GetInt32(i) != -1)
                    {
                        Item            item         = shop.findItemByID(reader.GetInt32(i));
                        GameObject      itemTemplate = Instantiate(TemplateItem);
                        DragAndDropItem tempDadItem  = itemTemplate.transform.GetChild(0).GetComponent <DragAndDropItem>();
                        tempDadItem.gameObject.GetComponent <Image>().sprite = item.sprite;
                        tempDadItem.item = item;
                        temp[1].GetComponent <DragAndDropCell>().PlaceItem(tempDadItem);
                    }
                    break;

                case "shortcut_3_id":
                    if (reader.GetInt32(i) > 200 && reader.GetInt32(i) < 300)
                    {
                        temp[2].GetComponent <DragAndDropCell>().PlaceItem(Instantiate(ctrl.FindSkillDADItemByID(reader.GetInt32(i))));
                    }
                    else if (reader.GetInt32(i) != -1)
                    {
                        Item            item         = shop.findItemByID(reader.GetInt32(i));
                        GameObject      itemTemplate = Instantiate(TemplateItem);
                        DragAndDropItem tempDadItem  = itemTemplate.transform.GetChild(0).GetComponent <DragAndDropItem>();
                        tempDadItem.gameObject.GetComponent <Image>().sprite = item.sprite;
                        tempDadItem.item = item;
                        temp[2].GetComponent <DragAndDropCell>().PlaceItem(tempDadItem);
                    }
                    break;

                case "shortcut_4_id":
                    if (reader.GetInt32(i) > 200 && reader.GetInt32(i) < 300)
                    {
                        temp[3].GetComponent <DragAndDropCell>().PlaceItem(Instantiate(ctrl.FindSkillDADItemByID(reader.GetInt32(i))));
                    }
                    else if (reader.GetInt32(i) != -1)
                    {
                        Item            item         = shop.findItemByID(reader.GetInt32(i));
                        GameObject      itemTemplate = Instantiate(TemplateItem);
                        DragAndDropItem tempDadItem  = itemTemplate.transform.GetChild(0).GetComponent <DragAndDropItem>();
                        tempDadItem.gameObject.GetComponent <Image>().sprite = item.sprite;
                        tempDadItem.item = item;
                        temp[3].GetComponent <DragAndDropCell>().PlaceItem(tempDadItem);
                    }
                    break;

                case "shortcut_5_id":
                    if (reader.GetInt32(i) > 200 && reader.GetInt32(i) < 300)
                    {
                        temp[4].GetComponent <DragAndDropCell>().PlaceItem(Instantiate(ctrl.FindSkillDADItemByID(reader.GetInt32(i))));
                    }
                    else if (reader.GetInt32(i) != -1)
                    {
                        Item            item         = shop.findItemByID(reader.GetInt32(i));
                        GameObject      itemTemplate = Instantiate(TemplateItem);
                        DragAndDropItem tempDadItem  = itemTemplate.transform.GetChild(0).GetComponent <DragAndDropItem>();
                        tempDadItem.gameObject.GetComponent <Image>().sprite = item.sprite;
                        tempDadItem.item = item;
                        temp[4].GetComponent <DragAndDropCell>().PlaceItem(tempDadItem);
                    }
                    break;

                case "shortcut_6_id":
                    if (reader.GetInt32(i) > 200 && reader.GetInt32(i) < 300)
                    {
                        temp[5].GetComponent <DragAndDropCell>().PlaceItem(Instantiate(ctrl.FindSkillDADItemByID(reader.GetInt32(i))));
                    }
                    else if (reader.GetInt32(i) != -1)
                    {
                        Item            item         = shop.findItemByID(reader.GetInt32(i));
                        GameObject      itemTemplate = Instantiate(TemplateItem);
                        DragAndDropItem tempDadItem  = itemTemplate.transform.GetChild(0).GetComponent <DragAndDropItem>();
                        tempDadItem.gameObject.GetComponent <Image>().sprite = item.sprite;
                        tempDadItem.item = item;
                        temp[5].GetComponent <DragAndDropCell>().PlaceItem(tempDadItem);
                    }
                    break;

                case "shortcut_7_id":
                    if (reader.GetInt32(i) > 200 && reader.GetInt32(i) < 300)
                    {
                        temp[6].GetComponent <DragAndDropCell>().PlaceItem(Instantiate(ctrl.FindSkillDADItemByID(reader.GetInt32(i))));
                    }
                    else if (reader.GetInt32(i) != -1)
                    {
                        Item            item         = shop.findItemByID(reader.GetInt32(i));
                        GameObject      itemTemplate = Instantiate(TemplateItem);
                        DragAndDropItem tempDadItem  = itemTemplate.transform.GetChild(0).GetComponent <DragAndDropItem>();
                        tempDadItem.gameObject.GetComponent <Image>().sprite = item.sprite;
                        tempDadItem.item = item;
                        temp[6].GetComponent <DragAndDropCell>().PlaceItem(tempDadItem);
                    }
                    break;
                }
            }
        }
    }
コード例 #31
0
 /// <summary>
 /// This item is droped
 /// </summary>
 public void OnDragEnd()
 {
     bool placed = false;
     if (OnItemDragEndEvent != null)
     {
         OnItemDragEndEvent();                                                   // Notify all about item drag end
     }
     if (transform.parent == canvasTransform)                                    // If item did not put in cell
     {
         if (sourceCell != null)
         {
             sourceCell.ItemReturn();                                            // Return item to source cell
         }
         else
         {
             Debug.Log("Something wrong");
         }
     }
     else
     {
         placed = true;
     }
     dragedItem = null;
     sourceCell = null;
     if (placed == true)
     {
         // Notify parents about item placed in new cell
         gameObject.SendMessageUpwards("OnItemPlace", this, SendMessageOptions.DontRequireReceiver);
     }
 }
コード例 #32
0
 private bool DraggedItemWasntDrop(DragAndDropItem item) =>
 DragAndDropItem.sourceCell.Equals(item.GetComponentInParent <DragAndDropCell>());
コード例 #33
0
 public void OnDrop(DragAndDropCell cellFrom, DragAndDropCell cellTo, DragAndDropItem item)
 {
     if ((item != null) && (cellFrom != cellTo))
     {
         DropDescriptor descriptor2 = new DropDescriptor {
             item            = item,
             sourceCell      = cellFrom,
             destinationCell = cellTo
         };
         DropDescriptor descriptor = descriptor2;
         if (!this.CellIsTankSlot(cellTo))
         {
             descriptor.destinationCell.PlaceItem(descriptor.item);
             if (this.onDrop != null)
             {
                 descriptor2 = new DropDescriptor();
                 this.onDrop(descriptor, descriptor2);
             }
         }
         else if (this.CellIsTankSlot(cellFrom))
         {
             descriptor2 = new DropDescriptor {
                 destinationCell = descriptor.sourceCell,
                 item            = descriptor.destinationCell.GetItem(),
                 sourceCell      = descriptor.destinationCell
             };
             DropDescriptor descriptor3 = descriptor2;
             descriptor.destinationCell.PlaceItem(descriptor.item);
             if (descriptor3.item != null)
             {
                 descriptor.sourceCell.PlaceItem(descriptor3.item);
             }
             if (this.onDrop != null)
             {
                 this.onDrop(descriptor, descriptor3);
             }
         }
         else
         {
             DragAndDropItem item2     = descriptor.destinationCell.GetItem();
             DragAndDropCell component = null;
             if (item2 != null)
             {
                 ModuleItem moduleItem = item2.GetComponent <SlotItemView>().ModuleItem;
                 component = CollectionView.slots[moduleItem].GetComponent <DragAndDropCell>();
             }
             descriptor2 = new DropDescriptor {
                 destinationCell = component,
                 item            = item2,
                 sourceCell      = descriptor.destinationCell
             };
             DropDescriptor descriptor4 = descriptor2;
             descriptor.destinationCell.PlaceItem(descriptor.item);
             if (descriptor4.item != null)
             {
                 descriptor4.destinationCell.PlaceItem(descriptor4.item);
             }
             if (this.onDrop != null)
             {
                 this.onDrop(descriptor, descriptor4);
             }
         }
     }
 }
コード例 #34
0
 /// <summary>
 /// On any item drag end enable all items raycast
 /// </summary>
 /// <param name="item"> dragged item </param>
 private void OnAnyItemDragEnd(DragAndDropItem item)
 {
     DragAndDropItem myItem = GetComponentInChildren<DragAndDropItem>(); // Get item from current cell
     if (myItem != null)
     {
         if (myItem == item)
         {
             SetBackgroundState(true);
         }
         myItem.MakeRaycast(true);                                       // Enable item's raycast
     }
     else
     {
         SetBackgroundState(false);
     }
 }
コード例 #35
0
 /// <summary>
 /// On any item drag start need to disable all items raycast for correct drop operation
 /// </summary>
 /// <param name="item"> dragged item </param>
 private void OnAnyItemDragStart(DragAndDropItem item)
 {
     DragAndDropItem myItem = GetComponentInChildren<DragAndDropItem>(); // Get item from current cell
     if (myItem != null)
     {
         myItem.MakeRaycast(false);                                      // Disable item's raycast for correct drop handling
         if (myItem == item)                                             // If item dragged from this cell
         {
             // Check cell's type
             switch (cellType)
             {
                 case CellType.DropOnly:
                     DragAndDropItem.icon.SetActive(false);              // Item will not be dropped
                     break;
                 case CellType.UnlimitedSource:
                     // Nothing to do
                     break;
                 default:
                     item.MakeVisible(false);                            // Hide item in cell till dragging
                     SetBackgroundState(false);
                     break;
             }
         }
     }
 }
コード例 #36
0
 /// <summary>
 /// This item is dropped
 /// </summary>
 /// <param name="eventData"></param>
 public void OnEndDrag(PointerEventData eventData)
 {
     if (icon != null)
     {
         Destroy(icon);                                                          // Destroy icon on item drop
     }
     MakeVisible(true);                                                          // Make item visible in cell
     if (OnItemDragEndEvent != null)
     {
         OnItemDragEndEvent(this);                                               // Notify all cells about item drag end
     }
     draggedItem = null;
     icon = null;
     sourceCell = null;
 }