public void Awake() { // get components _animator = GetComponent<Animator>(); _body = GetComponent<Rigidbody2D>(); _collider = GetComponent<CircleCollider2D>(); _pickable = GetComponent<Pickable>(); _sinner = GetComponent<Sinner>(); }
/** * Consume the ingestible */ protected override void Consume(Pickable pickable) { Focuser user = pickable.GetFocuser(); if (user == null) { return; } if (user is ICanModify == false) { return; } ((ICanModify)user).SetArmorModifier(_modifier); }
/** * Use the item */ public override bool Use(Pickable pickable) { Focuser user = pickable.GetFocuser(); if (user == null) { return(false); } Initialize(); Consume(pickable); SoundManager.PlayIngestibleSound(user.transform.position, .6f); return(true); }
public override void _Ready() { _camera = GetNode <DraggableCamera>("DraggableCamera"); _goblin = GetNode <Controllable>("Goblin"); _animationPlayer = GetNode <AnimationPlayer>("AnimationPlayer"); _animationPlayer.Connect("animation_finished", this, nameof(OnAnimationFinished)); _gameManager = GetNode <GameManager>("GameManager"); _exitButton = GetNode <Pickable>("ExitButton"); _exitButton.Connect("OnPickedUp", this, nameof(OnExitButtonPickedUp)); _exit = GetNode <Pickable>("Exit"); _exit.Connect("OnPickedUp", this, nameof(OnExitPickedUp)); _exit.Visible = false; _exit.PickedUp = true; ConnectAllControllables(); }
public bool OnPick(Pickable pick) { if (pick.pickableType == Pickable.PickableType.leaves) { AddToInventory(pick.pickableType, pick.quantity); } else if (pick.pickableType == Pickable.PickableType.wood) { } if (pick.pickableType == Pickable.PickableType.leaves) { } return(true); }
public void PlantSeed(Pickable newSeed) { if (seed != null || newSeed.type != Pickable.TYPE.SEED) { return; } seed = newSeed as Seed; seed.ChangeState(); seed.rigidbody.simulated = false; seed.transform.parent = this.transform; seed.transform.localPosition = Vector3.zero; ChangeState(); transform.GetChild(0).gameObject.SetActive(true); }
public void OnTriggerStay(Collider other) { Triggerable triggerable = other.GetComponent <Triggerable>(); if (triggerable == null) { return; } Pickable toChange = triggerable.asPickable(); if (!countdowns.ContainsKey(toChange)) { countdowns.Add(toChange, new ChangingState(secondsToChange, toChange.holder.held != toChange)); } }
private void Action() { if (item && item.type == Pickable.TYPE.BAT) { if (canDropBat) { isHolding = false; item = null; speedMalus = 0; } return; } if (isHolding) { RemoveItem(); return; } Debug.Log("Action"); RaycastHit2D hit = Physics2D.Raycast(transform.GetChild(0).GetChild(0).position, transform.GetChild(0).GetChild(0).position - transform.position, pickDistance); if (!hit || hit.transform.tag != "Pickable") { hit = TryRaycast(pickDistance); } if (hit && hit.transform.tag == "Pickable") { item = hit.transform.GetComponent <Pickable>(); item.transform.parent = transform.GetChild(2); item.transform.localPosition = Vector3.zero; item.isHolding = true; isHolding = true; animator.SetBool("isHolding", isHolding); speedMalus = item.speedMalus / 100.0f; item.rigidbody.simulated = false; if (item.type == Pickable.TYPE.PUMPKIN) { (item as Pumpkin).Steal(team); } if (item.type == Pickable.TYPE.BUCKET) { item.rigidbody.constraints = RigidbodyConstraints2D.FreezeRotation; } } else if (isOnPump) { tryPump = true; } }
public override void OnHitByProjectile(CellFace cellFace, WorldItem worldItem) { //收集掉落物 ++ll; if (ll >= 2) { ll = 0; return; } int value = subsystemTerrain.Terrain.GetCellValueFast(cellFace.Point.X, cellFace.Point.Y, cellFace.Point.Z); int level = ILibrary.getItemId(value); int maxcnt = (int)Math.Pow((double)2, (double)level) * 128; //计算最大容量 if (Terrain.ExtractContents(value) == HandledBlocks[0]) { try { ComponentBlockEntity componentBlockEntity = subsystemBlockEntities.GetBlockEntity(cellFace.X, cellFace.Y, cellFace.Z); if (componentBlockEntity == null) { toast("没有找到Blockentity"); return; } ComponentSingleChest singleChestData = componentBlockEntity.Entity.FindComponent <ComponentSingleChest>(true); if (singleChestData == null) { toast("没有找到componentchest"); return; } if (worldItem.ToRemove) { return; } Pickable pickable = worldItem as Pickable; int num = pickable?.Count ?? 1; int num2 = saveInventory(singleChestData, worldItem.Value, num, maxcnt); if (num2 < num) { subsystemAudio.PlaySound("Audio/PickableCollected", 1f, 0f, worldItem.Position, 3f, autoDelay: true); } if (num2 <= 0) { worldItem.ToRemove = true; } else if (pickable != null) { pickable.Count = num2; } } catch (Exception e) { toast(e.ToString()); } } }
public void Load(SaveData data) { ClearList(); int count = int.Parse(data.Get("count")); for (int i = 0; i < count; i++) { data.Prefix = "pick_" + i + "_"; string path = data.Get("path"); if (path == null) { continue; } Vector3 pos = new Vector3().FromSaveData(data, "pos"); Quaternion rot = Quaternion.Euler(new Vector3().FromSaveData(data, "rot")); GameObject prefab = Resources.Load(path) as GameObject; if (prefab == null) { Debug.LogWarning("Loading Pickables : Failed to load \"" + path + "\""); continue; } GameObject instance = Instantiate(prefab, pos, rot) as GameObject; instance.transform.parent = transform; string userDataType = data.Get("userDataType"); //UserData can be anything, deserializing it from string to load it if (userDataType != null) { Pickable pick = instance.GetComponent <Pickable>(); System.Type dataType = System.Type.GetType(userDataType); string userDataSerialized = data.Get("userData"); StringReader textReader = new StringReader(userDataSerialized); XmlSerializer xmlSerializer = new XmlSerializer(dataType); pick.UserData = xmlSerializer.Deserialize(textReader); } } }
public static void WritePickable(this NetworkWriter writer, Pickable pickable) { // This code will not work, if the pickable can be modified at runtime. Consider // adding a bool flag to check if the pickable can be edited at runtime and then // transmit all modified values. if (pickable == null) { writer.WriteByte(0); writer.WriteUInt16(0); } else { writer.WriteByte((byte)pickable.PickableType); writer.WriteUInt16(pickable.Id); } }
private void OnPickUp(Pickable pickable) { var type = pickable.Type; if (type == PickableTypes.Shotgun) { hand.Hold(Instantiate(shotgunPrefab)); } else if (type == PickableTypes.Uzi) { hand.Hold(Instantiate(uziPrefab)); } pickable.Use(gameObject); Destroy(pickable.transform.parent.gameObject); }
/// <summary> /// Register a pickable with this manager to allow lookup by id via <see cref="GetPickable"/>. /// </summary> /// <param name="pickable">The pickable to register.</param> internal static bool Add([NotNull] Pickable pickable) { if (instance == null) { Debug.LogWarning("A Pickable tried to register with the PickableManager, but no instance exists. Pickable has been disabled."); pickable.enabled = false; return(false); } if (!instance.entries.ContainsKey(GetPickableId(pickable))) { instance.entries.Add(GetPickableId(pickable), pickable); } return(true); }
private List <Pickable> getPickablesInChildren() { List <Pickable> items = new List <Pickable>(); foreach (Transform t in transform) { Pickable pickable = t.GetComponent <Pickable>(); if (pickable != null) { items.Add(pickable); } } return(items); }
public void TryPick(Pickable target) { if (pickable != null) { target.ResolvePick(false); return; } target.ResolvePick(true); pickable = target; pickable.OnHit.AddListener(ResetCollision); pickable.transform.SetParent(PickedPoint); pickable.transform.rotation = PickedPoint.rotation; pickable.transform.localPosition = Vector3.zero; }
public static void RegisterPickable(Pickable pickable) { if (instance == null) { Debug.LogError("Can't register pickable, PickablesManager not initialized"); return; } if (pickable == null) { Debug.LogWarning("Trying to register a null pickable. Registering cancelled."); return; } instance.pickables.Add(pickable); }
// Use this for initialization void Start() { ammoStockpileText = GameObject.Find("Canvas").transform.FindChild("AmmoStockpile").GetComponent <Text>(); currentClipText = GameObject.Find("Canvas").transform.FindChild("AmmoClip").GetComponent <Text>(); FireRateReset = FireRate; FireRate = 0; //for ammo currentClip = ClipSize; maxAmmo = ClipSize * 6; ammoStockpile = ClipSize * 3; FOVzoom = FOVzoom; myAudioSource = GetComponent <AudioSource> (); thisP = GetComponent <Pickable>(); }
public static ItemPrefab InstantiatePickable(Vector3 position, Pickable item, SpawnerAbstract spawn) { if (pickablePrefab == null) { pickablePrefab = Resources.Load <ItemPrefab>("Prefab/GameObject/Interactable/DropableItemPrefab"); } ItemPrefab newGm = GameObject.Instantiate <ItemPrefab>(pickablePrefab); newGm.Init(new Vector3(position.x, position.y, 5), item, spawn); newGm.transform.SetParent(backGround.transform, true); BoxCollider2D box = newGm.gameObject.AddComponent <BoxCollider2D>(); box.isTrigger = true; return(newGm); }
private void SpawnSequenceObject(Bounds solution, Color color, Other.PickableType type) { foreach (var t in _transportablesPrefab) { if (t.GetComponent <Arm.Pickable>().GetType() == type) { Quaternion randomRotation = Quaternion.Euler(0, _random.Next(0, 360), 0); GameObject gameobject = PhotonNetwork.Instantiate(t.name, solution.center, randomRotation); Pickable pickable = gameobject.GetComponent <Arm.Pickable>(); pickable.Color = color; pickable.Furnace = _furnace; pickable.SetEmissionVisibleBy(_emissionVisibleBy); _spawnedPickable.Add(new Tuple <Vector3, Quaternion, Pickable>(solution.center, randomRotation, pickable)); break; } } }
private void Update() { releasing = false; if (held == null) { return; } if (Input.GetKeyDown(KeyCode.E) && !becomingHeld) { Debug.Log("Releasing"); onRelease.Invoke(held); held.GetComponent <Rigidbody>().isKinematic = false; held = null; releasing = true; } becomingHeld = false; }
public void UnHideMe() { transform.parent = null; cantKillMe = true; boxCollider2D.enabled = true; itemRigidbody2D.simulated = true; itemRigidbody2D.velocity = Vector2.zero; if (pickable == null) { pickable = gameObject.AddComponent <Pickable>(); } foreach (var mr in GetComponentsInChildren <MeshRenderer>()) { mr.enabled = true; } }
public void TryPick(Pickable target) { if (pickable != null) { //target.ResolvePick(null); return; } target.ResolvePick(this); pickable = target; pickable.OnThrowFinished = ResetCollision; pickable.transform.SetParent(PickedPoint); pickable.transform.rotation = PickedPoint.rotation; pickable.transform.localPosition = Vector3.zero; OnPick.Invoke(); }
static string[] SaveItemPrefabs() { StringBuilder aItemsSB = new StringBuilder("\"resources\" : [\n"); StringBuilder aItemGUIDs = new StringBuilder("\"mItemGUIDs\" : [\n"); foreach (AssetMetaData aAsset in mCurrentAssets[AssetMetaData.AssetType.PrefabAsset]) { string aAssetPath = AssetDatabase.GUIDToAssetPath(aAsset.mGUID); if (AssetDatabase.GetMainAssetTypeAtPath(aAssetPath) != typeof(Item)) { continue; } StringBuilder aItemJSON = new StringBuilder("{\n"); Item aItem = AssetDatabase.LoadAssetAtPath <Item>(aAssetPath); string aItemFilePath = "/Assets/Resources/Prefabs/" + aItem.mName + ".json"; aAsset.mAssetFilePath = ".." + aItemFilePath; if (!IsAssetInResources(Application.dataPath + aItemFilePath)) { aItemJSON.Append("\"name\" : \"" + aItem.mName + "\",\n"); Pickable aPickable = new Pickable(); aPickable.mType = aItem.mItemType; GPolygonCollider aCollider = new GPolygonCollider(true); GSprite aSprite = new GSprite(aItem.mDisplaySprite.rect, aItem.mTextureGUID, aItem.mDisplaySprite.texture.height, (int)aItem.mRenderLayer); SaveAssetData(GetAssetFromGUID(aItem.mTextureGUID, AssetMetaData.AssetType.TextureAsset), ref aItemsSB); aItemJSON.Append("\"Components\" : [\n"); aItemJSON.Append(aSprite.ToString() + ",\n"); aItemJSON.Append(aPickable.ToString() + ",\n"); aItemJSON.Append(aCollider.ToString() + "\n"); aItemJSON.Append("]\n"); aItemJSON.Append("}\n"); SaveToFile(aItemJSON.ToString(), Application.dataPath + aItemFilePath); SaveToFile(aAsset.ToString(), Application.dataPath + aItemFilePath + ".json"); } if (!IsPathInResources(aItemsSB, aAsset.mAssetFilePath + ".json")) { aItemsSB.Append("\"" + aAsset.mAssetFilePath + ".json\","); aItemGUIDs.Append("\"" + aAsset.mGUID + "\","); } } aItemsSB.Remove(aItemsSB.Length - 1, 1); aItemsSB.Append("]\n"); aItemGUIDs.Remove(aItemGUIDs.Length - 1, 1); aItemGUIDs.Append("]\n"); return(new[] { aItemsSB.ToString(), aItemGUIDs.ToString() }); }
private void AddInventoryItem(Pickable pck, int idx) { switch (pck.itemType) { case ItemType.Handgun: case ItemType.Shotgun: case ItemType.M416: case ItemType.Magnum: AddWeapon(pck, idx); break; case ItemType.HandgunAmmo: case ItemType.ShotgunAmmo: case ItemType.M416Ammo: case ItemType.MagnumAmmo: AddAmmo(pck, idx); break; case ItemType.Health: AddHealth(pck, idx); break; } }
private void PickupObject() { if (CanPick && PickedGameObject == null) { MyAnimator.SetTrigger("Pick Up"); PickedGameObject = PickableGameObject; PickedGameObject.transform.rotation = Quaternion.Euler(0, 0, 0); PickedGameObject.transform.SetParent(gameObject.transform); PickedGameObject.transform.localPosition = new Vector3(0, 5, 0); Destroy(PickedGameObject.GetComponent <Rigidbody2D>()); Pickable pickable = PickedGameObject.GetComponent <Pickable>(); pickable.Rotate = false; pickable.MyPlayer = MyPlayer; MyAnimator.SetBool("IsHoldingThrowable", true); } }
public virtual Pickable Pick(PointF pt) { Pickable r = null; const float threshold = 25f; float mind2 = float.MaxValue; foreach (Pickable p in Pickables()) { float d2 = (p.X - pt.X) * (p.X - pt.X) + (p.Y - pt.Y) * (p.Y - pt.Y); if (d2 <= mind2) { r = p; mind2 = d2; } } return(mind2 <= threshold ? r : null); }
void Pick(Pickable pickable) { switch (pickable.Type) { case PickableType.Coin: var coin = pickable.GetComponent <Coin>(); Level.RemoveCoin(coin); break; case PickableType.Gem: var gem = pickable.GetComponent <Gem>(); Level.RemoveGem(gem); break; default: break; } pickable.Pick(); }
void TakeItem(Pickable pickup) { if (pickup.CompareTag("SGrape")) { hasSquashedGrapes = true; } if (pickup.CompareTag("Yeast")) { hasYeast = true; } if (!pickup.CompareTag("Bottle")) { worktop.Take(); pickup.Respawn(); } }
void CheckPickables(Vector3Int coords) { Pickable pickable = GetPickableAt(coords); if (pickable != null) { _pickables.Remove(pickable); Destroy(pickable.gameObject); if (pickable.ItemType == PickableType.Treasure) { _acquiredTreasures++; if (_treasurePanel != null) { _treasurePanel.AddPickablePanel(pickable.UIIcon); } } } }
/** * Return the index of the given item */ public int GetIndexOf(Pickable pickable) { if (pickable is Weapon) { if (_weapons.Contains((Weapon)pickable)) { return(_weapons.IndexOf((Weapon)pickable)); } else if (pickable is Ingestible) { if (_ingestibles.Contains((Ingestible)pickable)) { return(_ingestibles.IndexOf((Ingestible)pickable)); } } } throw new Exception("Unsupported pickable type."); }
/** * Use the item */ public override bool Use(Pickable pickable) { Focuser user = pickable.GetFocuser(); if (user == null) { return(false); } if (user is ICanEquip <Weapon> == false) { return(false); } ((ICanEquip <Weapon>)user).Equip((Weapon)pickable); SoundManager.PlaySelectWeaponSound(user.transform.position); return(true); }
public void Awake() { // get components _body = GetComponent<Rigidbody2D>(); _pickable = GetComponent<Pickable>(); }
public void Awake() { // get components _sinner = GetComponent<Sinner>(); _pickable = GetComponent<Pickable>(); }