当前位置: 首页>>代码示例>>C#>>正文


C# Slot.GetComponent方法代码示例

本文整理汇总了C#中Slot.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Slot.GetComponent方法的具体用法?C# Slot.GetComponent怎么用?C# Slot.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Slot的用法示例。


在下文中一共展示了Slot.GetComponent方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnEnable

	void OnEnable()
	{
		slot = (Slot)target;
		slot.GetComponent<SlotWins>().hideFlags = HideFlags.HideInInspector;
		slot.GetComponent<SlotCredits>().hideFlags = HideFlags.HideInInspector;
		slot.GetComponent<SlotCompute>().hideFlags = HideFlags.HideInInspector;
		slot.GetComponent<SlotComputeEditor>().hideFlags = HideFlags.HideInInspector;
		slot.GetComponent<SlotLines>().hideFlags = HideFlags.HideInInspector;
	}
开发者ID:jvifian,项目名称:slotMachine1,代码行数:9,代码来源:SlotEditor.cs

示例2: MoveItem

    public void MoveItem(GameObject clicked)
    {
        if (from == null)
        {
            if (!clicked.GetComponent<Slot>().IsEmpty)
            {
                from = clicked.GetComponent<Slot>();
                from.GetComponent<Image>().color = Color.grey;

                hoverObject = Instantiate(Resources.Load("Prefabs/HoverObject")) as GameObject;
                hoverObject.GetComponent<Image>().sprite = clicked.GetComponent<Image>().sprite;
                hoverObject.name = "Hover";

                RectTransform hoverTransform = hoverObject.GetComponent<RectTransform>();
                RectTransform clickedTransform = clicked.GetComponent<RectTransform>();

                hoverTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, clickedTransform.sizeDelta.x);
                hoverTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, clickedTransform.sizeDelta.y);

                hoverObject.transform.SetParent(GameObject.Find("Canvas").transform, true);
            }
        }
        else if (to == null)
        {
            to = clicked.GetComponent<Slot>();
            Destroy(GameObject.Find("Hover"));
        }

        if (to != null && from != null)
        {
            Stack<Item> tmpTo = new Stack<Item>(to.Items);

            to.AddItems(from.Items);

            if (tmpTo.Count == 0)
            {
                from.ClearSlot();
            }
            else
            {
                from.AddItems(tmpTo);
            }

            from.GetComponent<Image>().color = Color.white;

            to = null;
            from = null;
            hoverObject = null;
        }
    }
开发者ID:tsato1,项目名称:Ramen-Master,代码行数:50,代码来源:Controller.cs

示例3: MoveItem

    public void MoveItem(GameObject clicked)
    {
        if(from == null)
        {
            if(!clicked.GetComponent<Slot>().IsEmpty)
            {
                // Select an slot
                from = clicked.GetComponent<Slot>();
                // Set seleted slot color
                from.GetComponent<Image>().color = Color.gray;

            }
        }
        else if ( to == null)
        {
            to = clicked.GetComponent<Slot>();

        }

        if( to != null && from != null)
        {
            Stack<Item> tmpTo = new Stack<Item>(to.Items);
            to.AddItems(from.Items);

            if(tmpTo.Count == 0)
            {
                from.ClearSlot();

            }
            else
            {
                from.AddItems(tmpTo);
            }

            from.GetComponent<Image>().color = Color.white;
            to = null;
            from = null;
        }
    }
开发者ID:Avatarchik,项目名称:PolyPuzzelGame,代码行数:39,代码来源:ItemBar.cs

示例4: MoveItem

    /// <summary>
    /// Moves an item to another slot in the inventory
    /// </summary>
    /// <param name="clicked"></param>
    public void MoveItem(GameObject clicked)
    {
        if (from == null) //If we haven't picked up an item
        {
            if (!clicked.GetComponent<Slot>().IsEmpty) //If the slot we clicked sin't empty
            {
                from = clicked.GetComponent<Slot>(); //The slot we ar emoving from

                from.GetComponent<Image>().color = Color.gray; //Sets the from slots color to gray, to visually indicate that its the slot we are moving from

                hoverObject = (GameObject)Instantiate(iconPrefab); //Instantiates the hover object

                hoverObject.GetComponent<Image>().sprite = clicked.GetComponent<Image>().sprite; //Sets the sprite on the hover object so that it reflects the object we are moing

                hoverObject.name = "Hover"; //Sets the name of the hover object

                //Creates references to the transforms
                RectTransform hoverTransform = hoverObject.GetComponent<RectTransform>();
                RectTransform clickedTransform = clicked.GetComponent<RectTransform>();

                ///Sets the size of the hoverobject so that it has the same size as the clicked object
                hoverTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, clickedTransform.sizeDelta.x);
                hoverTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, clickedTransform.sizeDelta.y);

                //Sets the hoverobject's parent as the canvas, so that it is visible in the game
                hoverObject.transform.SetParent(GameObject.Find("Canvas").transform, true);

                //Sets the local scale to make usre that it has the correct size
                hoverObject.transform.localScale = from.gameObject.transform.localScale;

            }
        }
        else if (to == null) //Selects the slot we are moving to
        {
            to = clicked.GetComponent<Slot>(); //Sets the to object
            Destroy(GameObject.Find("Hover")); //Destroys the hover object
        }
        if (to != null && from != null) //If both to and from are null then we are done moving.
        {
            Stack<Item> tmpTo = new Stack<Item>(to.Items); //Stores the items from the to slot, so that we can do a swap

            to.AddItems(from.Items); //Stores the items in the "from" slot in the "to" slot

            if (tmpTo.Count == 0) //If "to" slot if 0 then we dont need to move anything to the "from " slot.
            {
                from.ClearSlot(); //clears the from slot
            }
            else
            {
                from.AddItems(tmpTo); //If the "to" slot contains items thne we need to move the to the "from" slot
            }

            //Resets all values
            from.GetComponent<Image>().color = Color.white;
            to = null;
            from = null;
            hoverObject = null;
        }
    }
开发者ID:yayunlo,项目名称:Zelda,代码行数:63,代码来源:Inventory.cs

示例5: AddItemIntoSlot

    public bool AddItemIntoSlot(Slot slot)
    {
        GameObject draggingItemGameObject = AttachedItem.DraggingItem;
        AttachedItem draggingItem = draggingItemGameObject.GetComponent<AttachedItem>();
        if (slot.GetComponentInChildren<AttachedItem>() == null)
        {
            if (slot.SlotType == SlotType.Inventory)
            {
                return true;
            }
            if (slot.SlotType == SlotType.Equipment && draggingItem.Item.IsEquipment && slot.GetComponent<EquipmentSlot>().EquipmentType.Equals(draggingItem.Item.ItemType))
            {
                InventoryEvents.EquipItem(draggingItem);
                return true;
            }
            if (slot.SlotType == SlotType.Hotbar)
            {
                draggingItem.CreateDuplicate(draggingItemGameObject);
                UpdateStacks(Inventory.Slots);
                return true;
            }
            draggingItem.CurrentSlot = slot.gameObject.transform;
        }
        else
        {
            GameObject itemFromSlotGameObject = slot.transform.GetChild(0).gameObject; ;
            AttachedItem itemFromSlot = itemFromSlotGameObject.GetComponent<AttachedItem>();
            RectTransform itemFromSlotRect = itemFromSlotGameObject.GetComponent<RectTransform>();
            bool sameItem = /*draggingItem.Item.Id*/ItemDatabase.GetID(draggingItem.Item) == /*itemFromSlot.Item.Id*/ItemDatabase.GetID(itemFromSlot.Item);
            if (slot.SlotType == SlotType.Inventory)
            {
                if (sameItem && itemFromSlot.Item.IsStackable)
                {
                    int stack = itemFromSlot.StackSize + draggingItem.StackSize;

                    if (stack <= itemFromSlot.Item.MaxStackSize)
                    {
                        itemFromSlot.StackSize = stack;
                        UpdateItemStack(itemFromSlot);
                        if (itemFromSlotGameObject != null && itemFromSlot.Duplicate != null)
                        {
                            itemFromSlot.Duplicate.GetComponent<AttachedItem>().StackSize = stack;
                            UpdateItemStack(itemFromSlot);
                        }
                        Destroy(draggingItemGameObject);

                        return true;
                    }
                    else
                    {
                        itemFromSlot.StackSize = itemFromSlot.Item.MaxStackSize;
                        UpdateItemStack(itemFromSlot);
                        if (itemFromSlotGameObject != null && itemFromSlot.Duplicate != null)
                        {
                            itemFromSlot.Duplicate.GetComponent<AttachedItem>().StackSize = stack;
                            UpdateItemStack(itemFromSlot);
                        }
                        draggingItem.StackSize = stack - itemFromSlot.Item.MaxStackSize;
                        UpdateItemStack(draggingItem);

                        return false;
                    }
                }
                else
                {
                    if (!draggingItem.Item.IsEquipment && draggingItem.LastSlot.GetComponent<Slot>() != null)
                    {
                        itemFromSlotGameObject.transform.SetParent(draggingItem.LastSlot);
                        itemFromSlotRect.localPosition = Vector2.zero;
                        return true;
                    }
                    else
                    {
                        if (itemFromSlot.Item.ItemType.Equals(draggingItem.Item.ItemType) && draggingItem.LastSlot.GetComponent<Slot>() != null)
                        {
                            itemFromSlotGameObject.transform.SetParent(draggingItem.LastSlot);
                            itemFromSlotRect.localPosition = Vector2.zero;
                            return true;
                        }
                    }
                }
                return false;
            }
            if (slot.SlotType == SlotType.Equipment)
            {
                if (slot.GetComponent<EquipmentSlot>().EquipmentType.Equals(draggingItem.Item.ItemType))
                {
                    itemFromSlotGameObject.transform.SetParent(draggingItem.LastSlot.transform);
                    itemFromSlotRect.localPosition = Vector2.zero;
                    return true;
                }
                return false;
            }
        }
        return false;
    }
开发者ID:gjrfytn,项目名称:planet-survival,代码行数:96,代码来源:InventoryManager.cs

示例6: MoveItem

    //Moves item to new slot in inventory/swap items
    public void MoveItem(Slot clickedSlot)
    {
        //If holding shift, make a splitStack window
        if (Input.GetKey(KeyCode.LeftShift) && !clickedSlot.IsEmpty() && !HoverIcon.hoverIcon)
        {
            from = clickedSlot;
            CreateSplitter();
            return;
        }

        if (clickedSlot.transform.parent.gameObject.Equals(GameControl.comboWindow.gameObject))
        {
            if (HoverIcon.hoverIcon != null)
            {
                if (HoverIcon.hoverIcon.GetComponent<Slot>().SlotItems().Type != BaseItem.ItemType.RELIC)
                {
                    return;
                }
            }
            else
            {
                if (clickedSlot.name.Equals("ResultSlot"))
                {
                    if (GameControl.comboWindow.Created)
                    {
                        from = clickedSlot;
                        CreateHoverIcon();
                        while (!from.IsEmpty())
                        {
                            HoverIcon.hoverIcon.GetComponent<Slot>().Items.Push(from.RemoveItem());
                        }
                        GameControl.comboWindow.Created = false;
                    }
                    return;
                }
            }
        }

        if (clickedSlot.transform.parent.gameObject.Equals(GameControl.equipment.gameObject))
        {
            if (HoverIcon.hoverIcon != null)
            {
                if (HoverIcon.hoverIcon.GetComponent<Slot>().SlotItems().Type == BaseItem.ItemType.EQUIPMENT)
                {
                    BaseEquipment item = (BaseEquipment)(HoverIcon.hoverIcon.GetComponent<Slot>().SlotItems());
                    if (!item.SubType.ToString().Equals(clickedSlot.name))
                    {
                        return;
                    }
                    GameControl.player.Stats.TransferStats(item.Stats);
                }
                else if (HoverIcon.hoverIcon.GetComponent<Slot>().SlotItems().Type == BaseItem.ItemType.WEAPON)
                {
                    if (clickedSlot.name.Equals("MAINHAND") || clickedSlot.name.Equals("OFFHAND"))
                    {
                        BaseWeapon item = (BaseWeapon)(HoverIcon.hoverIcon.GetComponent<Slot>().SlotItems());
                        if (item.Hand==2 && !clickedSlot.name.Equals("MAINHAND"))
                        {
                            return;
                        }
                        GameControl.player.Stats.TransferStats(item.Stats);
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
            else
            {
                if (!clickedSlot.IsEmpty())
                {
                    GameControl.player.Stats.RemoveStats(clickedSlot.GetComponent<Slot>().SlotItems().Stats);
                }
            }
        }
        //If from is null and slot has items in it, set from equal to slicked slot
        if (HoverIcon.hoverIcon == null)
        {
            if (!clickedSlot.IsEmpty())
            {
                from = clickedSlot;

                CreateHoverIcon();
                while (!from.IsEmpty())
                {
                    HoverIcon.hoverIcon.GetComponent<Slot>().Items.Push(from.RemoveItem());
                }
            }
        }
        //If the hoverIcon exists and has items in it, run code
        else if (HoverIcon.hoverIcon != null)
        {
            to = clickedSlot;

//.........这里部分代码省略.........
开发者ID:RAWeber,项目名称:Unity,代码行数:101,代码来源:Slot.cs

示例7: moveItem

    public void moveItem(GameObject slotClicked)
    {
        Inventory.slotClicked = slotClicked;

        if (!movingSlot.isEmpty)
        {
            Slot temp = slotClicked.GetComponent<Slot>();

            if (temp.isEmpty)
            {
                temp.addItems(movingSlot.Items);
                movingSlot.Items.Clear();
                Destroy(GameObject.Find("Hover"));
            }
            else if (!temp.isEmpty && movingSlot.currentItem.type == temp.currentItem.type && temp.spaceAvailable)
            {
                mergeStacks(movingSlot, temp);
            }
        }
        else if (from == null && canvasGroup.alpha == 1 && !Input.GetKey(KeyCode.LeftShift))
        {
            if (!slotClicked.GetComponent<Slot>().isEmpty)
            {
                from = slotClicked.GetComponent<Slot>();
                from.GetComponent<Image>().color = Color.green;

                createHoverIcon();
            }
        }
        else if(to == null && canvasGroup.alpha == 1 && !Input.GetKey(KeyCode.LeftShift))
        {
            to = slotClicked.GetComponent<Slot>();
            Destroy(GameObject.Find("Hover"));
        }

        if(from != null && to != null)
        {
            if(!to.isEmpty && from.currentItem.type == to.currentItem.type && to.spaceAvailable)
            {
                mergeStacks(from, to);
            }
            else
            {
                Stack<Item> tempTo = new Stack<Item>(to.Items);
                to.addItems(from.Items);

                if(tempTo.Count == 0)
                {
                    from.clearSlot();
                }
                else
                {
                    from.addItems(tempTo);
                }

                from.GetComponent<Image>().color = Color.white;
                to = null;
                from = null;
                Destroy(GameObject.Find("Hover"));
            }

        }
    }
开发者ID:B00058026,项目名称:Project,代码行数:63,代码来源:Inventory.cs

示例8: MoveItem

    public void MoveItem(GameObject clicked)
    {
        if (from == null)
        {
            if (!clicked.GetComponent<Slot> ().IsEmpty)
            {
                //Gray out the item you have clicked
                from = clicked.GetComponent<Slot> ();
                from.GetComponent<Image> ().color = Color.gray;
                from.itemSprite.GetComponent<Image>().color = Color.gray;
                from.stackText.color = Color.gray;
            }
        }
        else if (to == null)
        {
            to = clicked.GetComponent<Slot>();
        }

        if (to != null && from != null) {
            Stack<Item> tempTo = new Stack<Item> (to.Stack);
            to.AddItems (from.Stack);

            if (tempTo.Count == 0) {
                from.ClearSlot();
            }
            else {
                from.AddItems (tempTo);
            }
            //Set it back to full opacity;
            from.GetComponent<Image> ().color = Color.white;
            from.itemSprite.GetComponent<Image>().color = Color.white;
            from.stackText.color = Color.white;
            to = null;
            from = null;
        }
    }
开发者ID:cullenohara,项目名称:spectralbackpack,代码行数:36,代码来源:Inventory.cs


注:本文中的Slot.GetComponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。