//Assign new Item/Spell to the Button
    public ActionBarInfo SetInfo(ActionBarInfo ButtonInformation)
    {
        if (ButtonInformation == null)
        {
            RemoveInfo();
            return(null);
        }
        ActionBarInfo temp = Info;

        Info = ButtonInformation;
        Info.Buttons.Add(this);
        CooldownSprite.fillDirection = Info.FillDirection;
        SetTexture(ActionBarSettings.Instance.Atlas[Info.Atlas], Info.Icon);
        if (ButtonInformation.Stackable)
        {
            Stack = ButtonInformation.Stack;
        }
        else
        {
            Stack = 0;
        }
        if (temp != null)
        {
            temp.Buttons.Remove(this);
        }
        return(temp);
    }
 //Remove Item from button
 public void RemoveInfo()
 {
     StackLabel.text           = "";
     Icon.atlas                = null;
     Icon.spriteName           = "";
     Info.CoolDownFill         = CooldownSprite.fillAmount;
     CooldownLabel.text        = "";
     CooldownSprite.fillAmount = 0F;
     Info.Buttons.Remove(this);
     Info = null;
 }
 void Start()
 {
     Info            = null;
     PermissionCheck = true;
     isHovered       = false;
     mTrans          = transform;
     mSprite         = GetComponentInChildren <UISprite>();
     mSprite.depth   = 100;
     if (UICamera == null)
     {
         UICamera = NGUITools.FindCameraForLayer(gameObject.layer);
     }
     UICamera.GetComponent <UICamera>().stickyPress = false;
 }
 //Set item being held
 public void Set(ActionBarInfo ButtonInfo, Vector2 IconSize)
 {
     if (Instance != null)
     {
         if (ButtonInfo != null)
         {
             Instance.mSprite.transform.localScale = new Vector3(IconSize.x, IconSize.y, 1F);
             Info                        = ButtonInfo;
             Instance.mAtlas             = ActionBarSettings.Instance.Atlas[ButtonInfo.Atlas];
             Instance.mSprite.atlas      = Instance.mAtlas;
             Instance.mSprite.spriteName = ButtonInfo.Icon;
             Instance.Update();
         }
         else
         {
             Info = null;
             Instance.mSprite.atlas      = null;
             Instance.mSprite.spriteName = "";
             Instance.Update();
         }
     }
 }
    //Creates a clone of the item/spell.  This will be a seperate instance than the original.
    //It will share the same cooldown, yet will not share the same stacks.
    public static ActionBarInfo Clone(ActionBarInitialization ItemSlot)
    {
        ActionBarInfo tempObject = new ActionBarInfo();

        tempObject.SetActionBarInfo(ActionBarItem.Instance.ItemList[ItemSlot.InfoNumber].Atlas,
                                    ActionBarItem.Instance.ItemList[ItemSlot.InfoNumber].Icon,
                                    ActionBarItem.Instance.ItemList[ItemSlot.InfoNumber].GroupID,
                                    false,
                                    ActionBarItem.Instance.ItemList[ItemSlot.InfoNumber].CooldownAmount);
        tempObject.FillDirection = ActionBarItem.Instance.ItemList[ItemSlot.InfoNumber].FillDirection;
        if (ActionBarItem.Instance.ItemList[ItemSlot.InfoNumber].Stackable == true)
        {
            tempObject.Stack = ItemSlot.Stacks;
        }
        tempObject.ActivateAbility       = ActionBarItem.Instance.ItemList[ItemSlot.InfoNumber].ActivateAbility;
        tempObject.PlayCooldownAnimation = ActionBarItem.Instance.ItemList[ItemSlot.InfoNumber].PlayCooldownAnimation;
        tempObject.DestroyOnZeroStacks   = ActionBarItem.Instance.ItemList[ItemSlot.InfoNumber].DestroyOnZeroStacks;
        tempObject.Target           = ActionBarItem.Instance.ItemList[ItemSlot.InfoNumber].Target;
        tempObject.Function         = ActionBarItem.Instance.ItemList[ItemSlot.InfoNumber].Function;
        tempObject.SeperateInstance = ActionBarItem.Instance.ItemList[ItemSlot.InfoNumber].SeperateInstance;

        return(tempObject);
    }
    //NGUI OnPress Event
    void OnPress(bool isPressed)
    {
        // Left Clicking an item, thus activating it
        if (Input.GetMouseButtonUp(0) && (Info != null) && (ActionBarCursor.Instance.ButtonInfo == null))
        {
            IsClicked();
        }
        //Dropping Item onto Button
        else if (Input.GetMouseButtonUp(0) && (Info == null) && (ActionBarCursor.Instance.ButtonInfo != null))
        {
            //If Action bar allows multiple instances of same item
            if (BarRow.MultipleInstances == true)
            {
                //checks to see if Group IDs of Row and Button match
                if (CheckGroupID(ActionBarCursor.Instance.ButtonInfo.GroupID, BarRow.GroupID))
                {
                    //Set Info of Held item to the Button and then clear Cursor
                    SetInfo(ActionBarCursor.Instance.ButtonInfo);
                    ActionBarCursor.Instance.Clear();
                    NGUITools.PlaySound(ActionBarSettings.Instance.ButtonClickSound_Success);
                }
                else
                {
                    NGUITools.PlaySound(ActionBarSettings.Instance.ButtonClickSound_Disable);
                }
            }
            else            //If only one instance per row
            {
                //Check group ID to make sure they item and row matches
                if (CheckGroupID(ActionBarCursor.Instance.ButtonInfo.GroupID, BarRow.GroupID))
                {
                    //Loop through each button in the row for multiple instances
                    foreach (ActionBarButton button in BarRow.ButtonList)
                    {
                        if (button.Info != null)
                        {
                            if (button.Info.InstanceNumber == ActionBarCursor.Instance.ButtonInfo.InstanceNumber)
                            {
                                button.RemoveInfo();
                            }
                        }
                    }
                    //Set Held item to button and clear held item
                    SetInfo(ActionBarCursor.Instance.ButtonInfo);
                    ActionBarCursor.Instance.Clear();
                    NGUITools.PlaySound(ActionBarSettings.Instance.ButtonClickSound_Success);                     //Play Success sound
                }
                else
                {
                    NGUITools.PlaySound(ActionBarSettings.Instance.ButtonClickSound_Disable);
                }
            }
        }
        //Swapping Held Item with Button's Item
        else if (Input.GetMouseButtonUp(0) && (Info != null) && (ActionBarCursor.Instance.ButtonInfo != null))
        {
            //Check to make sure the Group ID on the item matches the row's
            if (CheckGroupID(ActionBarCursor.Instance.ButtonInfo.GroupID, BarRow.GroupID))
            {
                if (BarRow.isLocked == false)
                {
                    if (BarRow.MultipleInstances == true)
                    {
                        ActionBarCursor.Instance.PermissionCheck = false;
                        ActionBarInfo temp = ActionBarCursor.Instance.ButtonInfo;
                        ActionBarCursor.Instance.Set(Info, BarRow.ButtonSize);
                        SetInfo(temp);
                        ActionBarCursor.Instance.PermissionCheck = true;
                        NGUITools.PlaySound(ActionBarSettings.Instance.ButtonSound_Swap);
                    }
                    else                    //Only one instance per row
                    {
                        foreach (ActionBarButton button in BarRow.ButtonList)
                        {
                            if (button.Info != null)
                            {
                                //Loop through row and eliminate multiple instances of the item
                                if ((button.Info.InstanceNumber == ActionBarCursor.Instance.ButtonInfo.InstanceNumber))
                                {
                                    button.RemoveInfo();                                     //Remove the multiple
                                }
                            }
                        }
                        ActionBarCursor.Instance.PermissionCheck = false;                               //Temporarily Disable auto-destroy for cursor on click
                        ActionBarInfo temp = ActionBarCursor.Instance.ButtonInfo;
                        ActionBarCursor.Instance.Set(Info, BarRow.ButtonSize);
                        SetInfo(temp);
                        CooldownSprite.fillAmount = 0F;
                        ActionBarCursor.Instance.PermissionCheck = true;
                        NGUITools.PlaySound(ActionBarSettings.Instance.ButtonSound_Swap);
                    }
                }
            }
            else
            {
                if (BarRow.isLocked == true)
                {
                    ActionBarCursor.Instance.Clear();
                }

                //ActionBarCursor.Instance.Clear();   //Clear if placing item and it is mismatching ID
                NGUITools.PlaySound(ActionBarSettings.Instance.ButtonClickSound_Disable);
            }
        }

        else if (Input.GetMouseButtonUp(0) && (Info == null) && (ActionBarCursor.Instance.ButtonInfo == null))          //Clicking Empty button
        {
            NGUITools.PlaySound(ActionBarSettings.Instance.ButtonClickSound_Disable);
        }
    }