示例#1
0
        /// <summary>
        /// Helper used to rotate images to match orientation but only if it is for grid.
        /// Equipment is ignored since it doesn't affect anything non-visual.
        /// </summary>
        void OrientIcon(PGISlotItem item)
        {
            if (!this.IsEquipmentSlot)
            {
                UIRotate rotateEffect = IconImage.GetComponent <UIRotate>();
                if (rotateEffect != null)
                {
                    switch (item.RotatedDir)
                    {
                    case PGISlotItem.RotateDirection.None:
                    {
                        rotateEffect.EulerAngles = Vector3.zero;
                        break;
                    }

                    case PGISlotItem.RotateDirection.CW:
                    {
                        rotateEffect.EulerAngles = new Vector3(0.0f, 0.0f, 270.0f);
                        break;
                    }

                    case PGISlotItem.RotateDirection.CCW:
                    {
                        rotateEffect.EulerAngles = new Vector3(0.0f, 0.0f, 90.0f);
                        break;
                    }

                    default:
                    {
                        break;
                    }
                    } //end switch
                }     //end null check
            }         //end if
        }
        /// <summary>
        /// Assigns the item to this slot. This will set both the <see cref="PGISlot.Item"/>
        /// property and <see cref="PGISlot.IconImage"/>'s sprite or <see cref="PGISlot.IconMesh"/>'s mesh and material property.
        /// </summary>
        /// <param name="item">The <see cref="PGISlotItem"/> to assign.</param>
        public virtual void AssignItem(PGISlotItem item, bool setIcon = true)
        {
            if (!Ready)
            {
                return;
            }
            //TODO: We probably can skip this entire process if the incoming item matches
            //the one already stored in this slot. This needs testing though!

            var oldItem = Item;

            Item = item;

            //set the icon
            if (Item == null)
            {
                //if (!Blocked && View != null) this.HighlightColor = this.View.NormalColor;
                SetDefaultIcon();
            }
            else
            {
                //make sure default color is removed - otherwise we might tint our icon incorrectly
                IconImage.color = Color.white;

                //we need to check for this so we don't override another color set by the view.
                //if (!Blocked && oldItem == null) this.HighlightColor = item.Highlight;

                //trigger stacksize UI element to update
                if (this._Item != null)
                {
                    StackCount = _Item.StackCount;
                }
                else if (LastStackCount != 0)
                {
                    //this will reset our stack count when the slot goes empty
                    StackCount = 0;
                }

                //set icon data
                if (item.IconType == PGISlotItem.IconAssetType.Sprite && IconImage != null)
                {
                    Icon = item.Icon;
                    IconMesh.material = null;
                    IconMesh.Rotation = item.IconOrientation;
                    Icon3D            = null;

                    IconImage.enabled = true;
                    IconMesh.enabled  = false;

                    //the second instance of this component is for the rotation of the slot item
                    //regardless of the orientation in the model (i.e. arbitrary visual rotation)
                    UIRotate[] rot = IconImage.GetComponents <UIRotate>();
                    if (rot != null && rot.Length > 1)
                    {
                        rot[1].EulerAngles = item.IconOrientation;
                    }
                }
                else if (item.IconType == PGISlotItem.IconAssetType.Mesh && IconMesh != null)
                {
                    Icon = null;
                    IconMesh.material = item.IconMaterial;
                    IconMesh.Rotation = item.IconOrientation;
                    Icon3D            = item.Icon3D;

                    IconImage.enabled = false;
                    IconMesh.enabled  = true;
                }

                //fallback in case we are somehow missing a sprite *and* a mesh for this item's icon.
                else
                {
                    SetDefaultIcon();
                }

                //rotate image to match orientation but only if it is for grid
                if (!this.IsEquipmentSlot)
                {
                    UIRotate rotateEffect = IconImage.GetComponent <UIRotate>();
                    if (rotateEffect != null)
                    {
                        switch (item.RotatedDir)
                        {
                        case PGISlotItem.RotateDirection.None:
                        {
                            rotateEffect.EulerAngles = Vector3.zero;
                            break;
                        }

                        case PGISlotItem.RotateDirection.CW:
                        {
                            rotateEffect.EulerAngles = new Vector3(0.0f, 0.0f, 270.0f);
                            break;
                        }

                        case PGISlotItem.RotateDirection.CCW:
                        {
                            rotateEffect.EulerAngles = new Vector3(0.0f, 0.0f, 90.0f);
                            break;
                        }

                        default:
                        {
                            break;
                        }
                        } //end switch
                    }     //end null check
                }         //end if
            }
        }