本文整理汇总了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);
}
示例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);
});
}
示例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();
}
}
示例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 ();
}
示例5: SetSelectItem
public void SetSelectItem(Item i)
{
selectedItem = i;
itemNameText.text = i.name;
itemCostText.text = i.buildCost.ToString();
itemImage.sprite = i.GetComponent<SpriteRenderer>().sprite;
}
示例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;
}
}
示例7: Drop
bool Drop(Item item)
{
if (bannedColor == null) {
return true;
}
var key = item.GetComponent<Key>();
return key != null && key.keyColor == bannedColor;
}
示例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;
}
示例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);
}
}
示例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;
}
}
示例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);
}
示例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;
}
示例13: Connect
public override void Connect(Item item)
{
connectedTank = item.GetComponent<Tank>();
Close();
}
示例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);
}
示例15: setItem
public void setItem(Item i)
{
itemPrefab = i;
image.sprite = i.GetComponent<SpriteRenderer>().sprite;
}