context: using UnityEngine;
  using UnityEngine.UI;
  using UnityEngine.Events;
  using UnityEngine.EventSystems;
  using System;
  using System.Collections;
  using System.Collections.Generic;
  
  namespace UnityEngine.UI
  {
  	[AddComponentMenu("UI/Icon Slots/Item Slot", 12)]
  	public class UIItemSlot : UISlotBase {
  		
          [Serializable] public class OnRightClickEvent : UnityEvent<UIItemSlot> { }
          [Serializable] public class OnDoubleClickEvent : UnityEvent<UIItemSlot> { }
  		[Serializable] public class OnAssignEvent : UnityEvent<UIItemSlot> { }
  		[Serializable] public class OnUnassignEvent : UnityEvent<UIItemSlot> { }
  		
  		[SerializeField] private UIItemSlot_Group m_SlotGroup = UIItemSlot_Group.None;
  		[SerializeField] private int m_ID = 0;
  		
  		/// <summary>
  		/// Gets or sets the slot group.
  		/// </summary>
  		/// <value>The slot group.</value>
  		public UIItemSlot_Group slotGroup
  		{
  			get { return this.m_SlotGroup; }
  			set { this.m_SlotGroup = value; }
  		}
  		
  		/// <summary>
  		/// Gets or sets the slot ID.
  		/// </summary>
  		/// <value>The I.</value>
  		public int ID
  		{
  			get { return this.m_ID; }
  			set { this.m_ID = value; }
  		}
  		
  		/// <summary>
  		/// The assigned item info.
  		/// </summary>
  		private UIItemInfo m_ItemInfo;
  
          /// <summary>
          /// The right click event delegate.
          /// </summary>
          public OnRightClickEvent onRightClick = new OnRightClickEvent();
  
          /// <summary>
          /// The double click event delegate.
          /// </summary>
          public OnDoubleClickEvent onDoubleClick = new OnDoubleClickEvent();
  
          /// <summary>
          /// The assign event delegate.
          /// </summary>
          public OnAssignEvent onAssign = new OnAssignEvent();
  		
  		/// <summary>
  		/// The unassign event delegate.
  		/// </summary>
  		public OnUnassignEvent onUnassign = new OnUnassignEvent();
  		
  		/// <summary>
  		/// Gets the item info of the item assigned to this slot.
  		/// </summary>
  		/// <returns>The spell info.</returns>
  		public UIItemInfo GetItemInfo()
  		{
  			return this.m_ItemInfo;
  		}
  
  		/// <summary>
  		/// Determines whether this slot is assigned.
  		/// </summary>
  		/// <returns><c>true</c> if this instance is assigned; otherwise, <c>false</c>.</returns>
  		public override bool IsAssigned()
  		{
  			return (this.m_ItemInfo != null);
  		}
  		
  		/// <summary>
  		/// Assign the slot by item info.
  		/// </summary>
  		/// <param name="itemInfo">The item info.</param>
  		public bool Assign(UIItemInfo itemInfo)
  		{
  			if (itemInfo == null)
  				return false;
  			
  			// Make sure we unassign first, so the event is called before new assignment
  			this.Unassign();
  			
  			// Use the base class assign to set the icon
  			this.Assign(itemInfo.Icon);
  			
  			// Set the spell info
  			this.m_ItemInfo = itemInfo;
  			
  			// Invoke the on assign event
  			if (this.onAssign != null)
  				this.onAssign.Invoke(this);
  			
  			// Success
  			return true;
  		}
  		
  		/// <summary>
  		/// Assign the slot by the passed source slot.
  		/// </summary>
  		/// <param name="source">Source.</param>
  		public override bool Assign(Object source)
  		{
  			if (source is UIItemSlot)
  			{
  				UIItemSlot sourceSlot = source as UIItemSlot;
  				
  				if (sourceSlot != null)
  					return this.Assign(sourceSlot.GetItemInfo());
  			}
  			else if (source is UIEquipSlot)
  			{
  				UIEquipSlot sourceSlot = source as UIEquipSlot;
  				
  				if (sourceSlot != null)
  					return this.Assign(sourceSlot.GetItemInfo());
  			}
  			
  			// Default
  			return false;
  		}
  		
  		/// <summary>
  		/// Unassign this slot.
  		/// </summary>
  		public override void Unassign()
  		{
  			// Remove the icon
  			base.Unassign();
  			
  			// Clear the spell info
  			this.m_ItemInfo = null;
  			
  			// Invoke the on unassign event
  			if (this.onUnassign != null)
  				this.onUnassign.Invoke(this);
  		}
  		
  		/// <summary>
  		/// Determines whether this slot can swap with the specified target slot.
  		/// </summary>
  		/// <returns><c>true</c> if this instance can swap with the specified target; otherwise, <c>false</c>.</returns>
  		/// <param name="target">Target.</param>
  		public override bool CanSwapWith(Object target)
  		{
  			if ((target is UIItemSlot) || (target is UIEquipSlot))
  			{
  				// Check if the equip slot accpets this item
  				if (target is UIEquipSlot)
  				{
  					return (target as UIEquipSlot).CheckEquipType(this.GetItemInfo());
  				}
  				
  				// It's an item slot
  				return true;
  			}
  			
  			// Default
  			return false;
  		}
  		
  		// <summary>
  		/// Performs a slot swap.
  		/// </summary>
  		/// <returns><c>true</c>, if slot swap was performed, <c>false</c> otherwise.</returns>
  		/// <param name="sourceSlot">Source slot.</param>
  		public override bool PerformSlotSwap(Object sourceObject)
  		{
  			// Get the source slot
  			UISlotBase sourceSlot = (sourceObject as UISlotBase);
  			
  			// Get the source item info
  			UIItemInfo sourceItemInfo = null;
  			bool assign1 = false;
  			
  			// Check the type of the source slot
  			if (sourceSlot is UIItemSlot)
  			{
  				sourceItemInfo = (sourceSlot as UIItemSlot).GetItemInfo();
  				
  				// Assign the source slot by this one
  				assign1 = (sourceSlot as UIItemSlot).Assign(this.GetItemInfo());
  			}
  			else if (sourceSlot is UIEquipSlot)
  			{
  				sourceItemInfo = (sourceSlot as UIEquipSlot).GetItemInfo();
  				
  				// Assign the source slot by this one
  				assign1 = (sourceSlot as UIEquipSlot).Assign(this.GetItemInfo());
  			}
  			
  			// Assign this slot by the source slot
  			bool assign2 = this.Assign(sourceItemInfo);
  			
  			// Return the status
  			return (assign1 && assign2);
  		}
  		
  		/// <summary>
  		/// Raises the tooltip event.
  		/// </summary>
  		/// <param name="show">If set to <c>true</c> show.</param>
  		public override void OnTooltip(bool show)
  		{
  			// Make sure we have spell info, otherwise game might crash
  			if (this.m_ItemInfo == null)
  				return;
  			
  			// If we are showing the tooltip
  			if (show)
  			{
                  UITooltip.InstantiateIfNecessary(this.gameObject);
  
                  // Prepare the tooltip
                  UIItemSlot.PrepareTooltip(this.m_ItemInfo);
  				
  				// Anchor to this slot
  				UITooltip.AnchorToRect(this.transform as RectTransform);
  				
  				// Show the tooltip
  				UITooltip.Show();
  			}
  			else
  			{
  				// Hide the tooltip
  				UITooltip.Hide();
  			}
  		}
  
          /// <summary>
  		/// Raises the pointer click event.
  		/// </summary>
  		/// <param name="eventData">Event data.</param>
          public override void OnPointerClick(PointerEventData eventData)
          {
              base.OnPointerClick(eventData);
  
              // Make sure the slot is assigned
              if (!this.IsAssigned())
                  return;
  
              // Check for left double click
              if (eventData.button == PointerEventData.InputButton.Left && eventData.clickCount == 2)
              {
                  // Reset the click count
                  eventData.clickCount = 0;
  
                  // Invoke the double click event
                  if (this.onDoubleClick != null)
                      this.onDoubleClick.Invoke(this);
              }
  
              // Check for right click
              if (eventData.button == PointerEventData.InputButton.Right)
              {
                  // Invoke the double click event
  
gt:                 if (this.onRightClick != null)