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


C# Item.GetComponent方法代码示例

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


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

示例1: Init

    public void Init(Inventory inventory, Item item) {
        if (this.inventory != inventory) {
            if (this.inventory != null) {
                Unsubscribe(this.inventory);
            }
            Subscribe(inventory);
        }

        this.inventory = inventory;
        this.item = item;
        item.inventorySlot = this;

        transform.SetParent(inventory.line.transform);
        item.transform.SetParent(transform, worldPositionStays: false);
        item.transform.localPosition = Vector3.zero;
        item.transform.localRotation = Quaternion.identity;

        if (item.GetComponent<Rigidbody>() != null) {
            item.GetComponent<Rigidbody>().isKinematic = true;
        } 
        if (item.GetComponent<LastPositionKeeper>() != null) {
            item.GetComponent<LastPositionKeeper>().Reset();
        }

        transform.localPosition = TargetPosition();
        transform.localScale = TargetScale();
        transform.localRotation = Quaternion.Euler(0, 90, 0);
    }
开发者ID:craus,项目名称:UnityTest,代码行数:28,代码来源:InventorySlot.cs

示例2: PushItem

 void PushItem(Item item, Vector3 pushPosition, Vector3 force)
 {
     item.transform.position = pushPosition;
     if (item.GetComponent<LastPositionKeeper>() != null) {
         item.GetComponent<LastPositionKeeper>().Reset();
     }
     item.GetComponent<Rigidbody>().AddForce(force / 50f, ForceMode.Impulse);
     TimeManager.WaitFor(0.01f).Then(() => {
         Debug.LogFormat("Item pushed at velocity {0}", item.GetComponent<Rigidbody>().velocity);
     });
 }
开发者ID:craus,项目名称:UnityTest,代码行数:11,代码来源:ThrowAbility.cs

示例3: AddElement

    public void AddElement(Item item)
    {
        bool result =  inventory.Add(ref item);

        if (result)
        {

            IEnumerator enumerator = inventory.WeaponsList.GetEnumerator();
            while (enumerator.MoveNext())
            {
                if (object.ReferenceEquals(item, enumerator.Current))
                    Debug.Log("KURWAAAAAAAAAAAAAAAAA****************");
            }

            RectTransform Stuff = Instantiate < RectTransform > (item.GetComponent<RectTransform>());

            Stuff.parent = StuffBackground;

            Stuff.GetComponent<Button>().onClick.AddListener(() => setDialogBox(DialogBox, Stuff.gameObject, ref item));

            Stuff.sizeDelta = CelSize;

            SetPosition(Stuff);
            Stuff = AnchorOpertion.SetAnchor(Stuff);

            Stuffs.Add(Stuff);
            CalculatePointer();
        }
    }
开发者ID:Lukasz199312,项目名称:SmithCrafter,代码行数:29,代码来源:StuffMenu.cs

示例4: PickUp

    public void PickUp(Item item)
    {
        Color color = item.GetComponent<SpriteRenderer> ().color;

        if (item.article == "hat") {
            Drop (hat);
            hat = item;
            hatBorder.color = color;
        } else if (item.article == "staff") {
            Drop (staff);
            staff = item;
            staffBorder.color = color;
        } else if (item.article == "boots") {
            Drop (boots);
            boots = item;
            bootsBorder.color = color;
        } else {
            Debug.Log ("Can't pick up " + item + ". Invalid article.");
            return;
        }

        spellController.UpdateAvailableSpells (new Item[] {hat, staff, boots});

        item.Disable ();
    }
开发者ID:skip-thurm,项目名称:wizard-game,代码行数:25,代码来源:Inventory.cs

示例5: SetSelectItem

 public void SetSelectItem(Item i)
 {
     selectedItem = i;
     itemNameText.text = i.name;
     itemCostText.text = i.buildCost.ToString();
     itemImage.sprite = i.GetComponent<SpriteRenderer>().sprite;
 }
开发者ID:RUSDGaming,项目名称:spacerpg,代码行数:7,代码来源:ShopManagerScript.cs

示例6: SetUpWeapon

    public void SetUpWeapon(Item wep)
    {
        //Debug.Log("setting up item");

        if (wep)
        {
            Collider2D col = wep.GetComponent<Collider2D>();
            if (col)
                col.enabled = false;
            ItemJuice juice = wep.GetComponent<ItemJuice>();
            if (juice)
            {
                juice.enabled = false;
            }
            //Debug.Log("Initing Weapon" + wep);
            wep.gameObject.SetActive(true);

            // tell s the stored prefab wher it is
            weaponScript = wep.GetComponent<Weapon>();
            if (!weaponScript)
            {
                Debug.LogError("You are trying to set up an item that is not a weapon!");
                return;
            }
            weaponScript.Init(playerStats,playerOwned);

            // gets the sprite from the game object.
            SpriteRenderer weaponSprite = wep.GetComponent<SpriteRenderer>();

            if (aboveShip)
            {
                weaponSprite.sortingOrder = 3;
            }
            else
            {
                weaponSprite.sortingOrder = 1;
            }

        }
        else
        {

            //SpriteRenderer slotSprite = GetComponent<SpriteRenderer>();
            //slotSprite.sprite = null;
        }
    }
开发者ID:RUSDGaming,项目名称:spacerpg,代码行数:46,代码来源:WeaponInventory.cs

示例7: Drop

 bool Drop(Item item)
 {
     if (bannedColor == null) {
         return true;
     }
     var key = item.GetComponent<Key>();
     return key != null && key.keyColor == bannedColor;
 }
开发者ID:craus,项目名称:UnityTest,代码行数:8,代码来源:CleanHands.cs

示例8: addItem

    public bool addItem(Item item)
    {
        bool added = false;
        if(item.GetComponent<Backpack>() != null)
        {
            capacity += 8;
        }

        //Check for a stackable Item
        if(item.stackable)
        {
            Item stackable = inventory.Where(i => i.type == item.type).First();
            if (stackable != null)
            {
                stackable.addStack();
                added = true;
            }
        }

        //Check if the item is a weapon that can be picked up
        Weapon weapon = item.GetComponent<Weapon>();
        if(weapon != null)
        {
            avatar.weapon = weapon;
            weapon.gameObject.SetActive(false);
            weapon.transform.SetParent(gameObject.transform);
        }

        if(getSize() < capacity && !added)
        {
            inventory.Add(item);
            item = null;
            added = true;
        }

        drawSlots();

        return added;
    }
开发者ID:thunder033,项目名称:MansionEscape,代码行数:39,代码来源:Inventory.cs

示例9: addIngredientToCombination

    public void addIngredientToCombination(Item item)
    {
        IngredientType type = item is Ingredient ? (item as Ingredient).ingredientType : IngredientTypeTools.getRandomIngredientType();

        if (!addIngredientToCombination(type))
        {
            item.gameObject.AddComponent<Rigidbody>();
            item.GetComponent<Collider>().enabled = true;
            placeProduct(item.gameObject);
        } else
        {
            Destroy(item.gameObject);
        }
    }
开发者ID:Snoothy,项目名称:ggj16,代码行数:14,代码来源:CombinationTable.cs

示例10: pickUpItem

    public void pickUpItem(Item it)
    {
        it.GetComponent<Item>().enabled = true;
        it.gameObject.GetComponent<Item>().isThrown = false;
        int theIndex = this.gameObject.GetComponentInParent<Character>().inventory.addItem(it);

        if(theIndex != -1)
        {
            pickupSound.Play();
            it.gameObject.GetComponent<Rigidbody>().isKinematic = true;
            it.gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.None;
            WIHolder temp = this.gameObject.GetComponentInParent<Character>().GetComponentInChildren<WIHolder>();
            temp.objects[theIndex + temp.itemOffset] = it.gameObject;
            temp.objects[theIndex + temp.itemOffset].transform.rotation = temp.transform.rotation;
            temp.objects[theIndex + temp.itemOffset].transform.SetParent(temp.hTransform);
            it.gameObject.transform.localPosition = Vector3.zero;
            temp.objects[theIndex + temp.itemOffset].SetActive(false);
        }
        else
        {
            it.gameObject.GetComponent<Item>().enabled = false;
            it.gameObject.GetComponent<Item>().isThrown = true;
        }
    }
开发者ID:VictorCode,项目名称:BattleProject,代码行数:24,代码来源:Pickup.cs

示例11: animateEnter

    public void animateEnter (Item item)
    {
        GrabController grabController = GameObject.FindObjectOfType<GrabController>();
        if (grabController.getGrabbedObject() == item.gameObject)
        {
            grabController.StopGrab();
        }

        Destroy(item.GetComponent<Rigidbody>());
        item.GetComponent<Collider>().enabled = false;

        GameObject spinParent = new GameObject("SpinParent");
        spinParent.transform.parent = enterPoolParent;
        spinParent.transform.localScale = Vector3.one;
        spinParent.transform.localRotation = Quaternion.identity;
        spinParent.transform.localPosition = Vector3.zero;
        spinParent.transform.position = spinParent.transform.position.LayerManagementSetY(spinParent.transform.position.y + this.spinConfigurations.fromHeight);

        item.transform.parent = spinParent.transform;
        spinParent.AddComponent<RotateBy>().runActionWith(new RotateByInfo(spinConfigurations.rotationSpeed, new Vector3(0, -1, 0)));

        item.gameObject.AddComponent<MoveToVectorByTime>().runActionWith(new MoveToVectorByTimeInfo(spinConfigurations.downTime, Vector3.zero, true, 0));
        spinParent.AddComponent<MoveToVectorByTime>().runActionWith(new MoveToVectorByTimeInfo(spinConfigurations.downTime, Vector3.zero, true, 0));

        ScaleToByTime scale = item.gameObject.AddComponent<ScaleToByTime>();
        scale.delegates += a =>
        {
            addIngredientToCombination(item);
            Destroy(spinParent);
            Destroy(item.gameObject.GetComponent<MoveToVectorByTime>());
            Destroy(a);
        };
        scale.runActionWith(new ScaleToByTimeInfo(spinConfigurations.downTime, Vector3.zero, 0));
        addingItemToPool(item);
    }
开发者ID:Snoothy,项目名称:ggj16,代码行数:35,代码来源:CombinationTable.cs

示例12: Drop

	public bool Drop(Item drop_item, bool being_stolen = false)
	{
		InventorySlot slot;
		if(this.retrieveSlot(drop_item.Slot, out slot)) {
			if(!being_stolen || (m_CanBeStolenFrom && drop_item.CanBeStolen)) {
				if(slot.Items.Contains(drop_item)) {
					slot.Items.Remove(drop_item);

					Transform anchor = slot.GetAnchorFromItem(drop_item);
					if(anchor) {
						List<Item> available_items = slot.GetUnanchoredItems();

						if(available_items.Count > 0) {
							slot.AnchorRelations[anchor] = available_items[0];
						} else {
							slot.AnchorRelations.Remove(anchor);
						}
					}

					drop_item.transform.SetParent(null, true);
					drop_item.Owner = null;

					if(DropLocation) {
						Rigidbody player_body = GetComponent<Rigidbody>();
						Rigidbody body = drop_item.GetComponent<Rigidbody>();

						drop_item.transform.position = DropLocation.position;
						drop_item.transform.localRotation = DropLocation.rotation;

						if(body) {
							if(player_body) {
								body.AddForce(player_body.velocity, ForceMode.VelocityChange);
							}

							body.AddForce(DropPuntForce*drop_item.transform.forward);
						}
					}

					return true;
				}
			}
		}

		return false;
	}
开发者ID:dreac0nic,项目名称:1gam.crystalcaves,代码行数:45,代码来源:Inventory.cs

示例13: Connect

 public override void Connect(Item item)
 {
     connectedTank = item.GetComponent<Tank>();
     Close();
 }
开发者ID:Booljayj,项目名称:BREACH,代码行数:5,代码来源:TankHolder.cs

示例14: DrawItem

    protected void DrawItem(Item item, Vector2 position)
    {
        GUI.depth = 0;

        SpriteRenderer spriteRenderer = item.GetComponent<SpriteRenderer>();

        if (!spriteRenderer || !spriteRenderer.sprite)
        {
            Debug.LogError("Cannot render " + item + " at position (" + position.x + "," + position.y + "), because its sprite is not set.");
            return;
        }

        Texture2D texture = spriteRenderer.sprite.texture;
        Rect rectangle = spriteRenderer.sprite.textureRect;
        Rect coordinates = new Rect(
            rectangle.x / texture.width,
            rectangle.y / texture.height,
            rectangle.width / texture.width,
            rectangle.height / texture.height
        );

        Vector2 positionOnCamera = PositionToCameraSpace(position);

        GUI.DrawTextureWithTexCoords(new Rect(positionOnCamera.x * scale, positionOnCamera.y * scale, itemSize.x * scale, itemSize.y * scale), texture, coordinates);
    }
开发者ID:thijsdaniels,项目名称:Metroidvania,代码行数:25,代码来源:Inventory.cs

示例15: setItem

 public void setItem(Item i)
 {
     itemPrefab = i;
     image.sprite = i.GetComponent<SpriteRenderer>().sprite;
 }
开发者ID:RUSDGaming,项目名称:spacerpg,代码行数:5,代码来源:ShopItemButtonScript.cs


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