コード例 #1
0
ファイル: AbilityInfoPanel.cs プロジェクト: coconut1z/GDS1
 // Update is called once per frame
 void Update()
 {
     abi = transform.GetChild(3).GetComponent <AbilityDraggable>();
     if (abi != null)
     {
         nameT.text = abi.nameUI;
         extra.text = abi.extraUI;
         if (abi.passive)
         {
             typeT.text  = "PASSIVE";
             typeT.color = new Color(1, 0.5f, 1, 1);
         }
         else
         {
             typeT.text  = "ACTIVE";
             typeT.color = new Color(0, 1, 0, 1);
             GetComponent <Image>().color = new Color(136f / 255f, 169f / 255f, 143f / 255f);
         }
         if (abi.passive)
         {
             abi.gameObject.tag = "UIDraggableP";
         }
     }
 }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            moduleToDrag = GetDraggableTransformUnderMouse();
            if (moduleToDrag != null)
            {
                dragging = true;
                moduleToDrag.SetAsLastSibling();
                //originalPosition = moduleToDrag.position;
                originalPosition  = moduleToDrag.localPosition;
                moduleToDragImage = moduleToDrag.GetComponent <Image>();
                moduleToDragImage.raycastTarget = false;
            }
        }

        if (dragging)
        {
            moduleToDrag.position = Input.mousePosition;
        }

        if (Input.GetMouseButtonUp(0))
        {
            if (moduleToDrag != null)
            {
                Transform moduleToReplace = GetDraggableTransformUnderMouse();
                if (moduleToReplace != null && moduleToReplace.tag == moduleToDrag.tag)
                {
                    //moduleToDrag.position = moduleToReplace.position;
                    //moduleToReplace.position = originalPosition;
                    //Vector2 dragPos = moduleToDrag.localPosition;
                    Vector2 replacePos = moduleToReplace.localPosition;
                    //moduleToDrag.localPosition = moduleToReplace.InverseTransformPoint(moduleToReplace.position);
                    //moduleToReplace.localPosition = moduleToDrag.InverseTransformPoint(originalPosition);

                    AbilityDraggable Drag    = moduleToDrag.gameObject.GetComponent <AbilityDraggable>();
                    AbilityDraggable Replace = moduleToReplace.gameObject.GetComponent <AbilityDraggable>();
                    if (Replace.equipped && !Drag.equipped)
                    {
                        tutDrag          = true;
                        Drag.equipped    = true;
                        Replace.equipped = false;
                        Drag.slot        = Replace.slot;
                        Replace.slot     = -1;
                        Transform panel = moduleToDrag.parent;
                        moduleToDrag.parent    = moduleToReplace.parent;
                        moduleToReplace.parent = panel;
                        ip.RemoveEquipped(Replace.getAbilityId());
                        ip.AddEquipped(Drag.getAbilityId());
                        ip.RemoveAbility(Drag.getAbilityId());
                        ip.AddAbility(Replace.getAbilityId());

                        abilityNameText[Drag.slot - 1].text = Drag.nameUI;

                        if (Drag.passive)
                        {
                            controlsText[Drag.slot - 1].text = "Passive";
                        }
                        else
                        {
                            if (Drag.slot - 1 == 0)
                            {
                                controlsText[Drag.slot - 1].text = "Right Click";
                            }
                            else if (Drag.slot - 1 == 1)
                            {
                                controlsText[Drag.slot - 1].text = "Q";
                            }
                            else if (Drag.slot - 1 == 2)
                            {
                                controlsText[Drag.slot - 1].text = "E";
                            }
                            else if (Drag.slot - 1 == 3)
                            {
                                controlsText[Drag.slot - 1].text = "R";
                            }
                        }
                    }
                    else if (!Replace.equipped && Drag.equipped)
                    {
                        Drag.equipped    = false;
                        Replace.equipped = true;
                        Replace.slot     = Drag.slot;
                        Drag.slot        = -1;
                        Transform panel = moduleToDrag.parent;
                        moduleToDrag.parent    = moduleToReplace.parent;
                        moduleToReplace.parent = panel;
                        ip.RemoveEquipped(Drag.getAbilityId());
                        ip.AddEquipped(Replace.getAbilityId());
                        ip.RemoveAbility(Replace.getAbilityId());
                        ip.AddAbility(Drag.getAbilityId());

                        abilityNameText[Replace.slot - 1].text = Replace.nameUI;

                        if (Replace.passive)
                        {
                            controlsText[Replace.slot - 1].text = "Passive";
                        }
                        else
                        {
                            if (Replace.slot - 1 == 0)
                            {
                                controlsText[Replace.slot - 1].text = "Right Click";
                            }
                            else if (Replace.slot - 1 == 1)
                            {
                                controlsText[Replace.slot - 1].text = "Q";
                            }
                            else if (Replace.slot - 1 == 2)
                            {
                                controlsText[Replace.slot - 1].text = "E";
                            }
                            else if (Replace.slot - 1 == 3)
                            {
                                controlsText[Replace.slot - 1].text = "R";
                            }
                        }
                    }
                    else if (Replace.equipped && Drag.equipped)
                    {
                        int dragSlot = Drag.slot;
                        Drag.slot    = Replace.slot;
                        Replace.slot = dragSlot;

                        abilityNameText[Drag.slot - 1].text    = Drag.nameUI;
                        abilityNameText[Replace.slot - 1].text = Replace.nameUI;

                        if (Drag.passive)
                        {
                            controlsText[Drag.slot - 1].text = "Passive";
                        }
                        else
                        {
                            if (Drag.slot - 1 == 0)
                            {
                                controlsText[Drag.slot - 1].text = "Right Click";
                            }
                            else if (Drag.slot - 1 == 1)
                            {
                                controlsText[Drag.slot - 1].text = "Q";
                            }
                            else if (Drag.slot - 1 == 2)
                            {
                                controlsText[Drag.slot - 1].text = "E";
                            }
                            else if (Drag.slot - 1 == 3)
                            {
                                controlsText[Drag.slot - 1].text = "R";
                            }
                        }

                        if (Replace.passive)
                        {
                            controlsText[Replace.slot - 1].text = "Passive";
                        }
                        else
                        {
                            if (Replace.slot - 1 == 0)
                            {
                                controlsText[Replace.slot - 1].text = "Right Click";
                            }
                            else if (Replace.slot - 1 == 1)
                            {
                                controlsText[Replace.slot - 1].text = "Q";
                            }
                            else if (Replace.slot - 1 == 2)
                            {
                                controlsText[Replace.slot - 1].text = "E";
                            }
                            else if (Replace.slot - 1 == 3)
                            {
                                controlsText[Replace.slot - 1].text = "R";
                            }
                        }
                    }
                    else if (!Replace.equipped && !Drag.equipped)
                    {
                        Transform panel = moduleToDrag.parent;
                        moduleToDrag.parent    = moduleToReplace.parent;
                        moduleToReplace.parent = panel;
                    }
                    moduleToDrag.localPosition    = replacePos;
                    moduleToReplace.localPosition = originalPosition;
                }
                else
                {
                    moduleToDrag.localPosition = originalPosition;
                }

                moduleToDragImage.raycastTarget = true;
                moduleToDrag = null;
            }
            dragging = false;
        }
    }