Inheritance: MonoBehaviour
Esempio n. 1
0
    public void AgePlant()
    {
        daysToGrow = Mathf.Clamp(daysToGrow - 1, 0, 1000);

        if (daysToGrow == 0)
        {
            // Check if the plant is seed. If seed, grow it to plant
            PickUpItem plantItem = PickUpTypeList.Instance.GetPickUpItem(plant);
            if (plantItem is Seed)
            {
                GameObject newPlantOb = SpawnPlant(((Seed)plantItem).growToPrefab);
                Plant      p          = (Plant)newPlantOb.GetComponent <PickUpItem>();
                p.onDirtPlotID = ID;
                FarmingController.Instance.AddPlant(ID, p);

                plant      = PickUpItem.ItemTypes.Empty;
                daysToGrow = 0;

                SpriteRenderer ren = plantImg.GetComponent <SpriteRenderer>();
                if (ren != null)
                {
                    ren.sprite = null;
                }
            }
        }
    }
Esempio n. 2
0
    // Use this for initialization
    void Start()
    {
        directionalLight = GetComponent <Light>();
        Transform glowTransform = transform.Find("GlowArea");

        if (glowTransform != null)
        {
            glowLight = glowTransform.GetComponent <Light>();
        }

        if (glowTransform != null)
        {
            glowObject = glowTransform.gameObject;
        }

        if (GameManager.instance.playerObject == null)
        {
            return;
        }

        playerInventory        = GameManager.instance.playerObject.GetComponent <Inventory>();
        currentLightIntenisity = maxLightIntensity;

        flashLightOnOff = GetComponent <AudioSource>();

        playerCharacter = GameManager.instance.playerObject.GetComponent <Character>();

        torchItem = transform.parent.GetComponent <PickUpItem>();
    }
Esempio n. 3
0
 private void ItemIsPickedUp(PickUpItem pickUpItem, Rectangle targetRectangel)
 {
     if (pickUpItem.GetFloorRec().Intersects(targetRectangel) && pickUpItem.Sprite.Alive)
     {
         PickUpAction(pickUpItem);
     }
 }
Esempio n. 4
0
    public void Load(int saveSlot)
    {
        if (saveSlot == 1 || saveSlot == 2 || saveSlot == 3)
        {
            PickUpTypeList list = PickUpTypeList.Instance;
            FarmingController.Instance.EmptyDirtPlotList();

            JsonUtility.FromJsonOverwrite(PlayerPrefs.GetString(SAVE_KEY + saveSlot), this);
            for (int i = 0; i < IDs.Count; i++)
            {
                PickUpItem item = list.GetPickUpItem(items[i]);
                if (item != null)
                {
                    DirtPlot plot = FarmingController.Instance.GetDirtPlot(IDs[i]);
                    if (plot != null)
                    {
                        if (item is Plant)
                        {
                            FarmingController.Instance.AddPlant(plot, ((Plant)item));
                        }
                        else
                        {
                            plot.AddPlant(item, days2Grows[i]);
                        }
                    }
                }
            }
        }
        else
        {
            Debug.Log("Save slot number invalid!");
        }
    }
Esempio n. 5
0
    public PickUpItem CreatePickUpItem(Item item, Vector3 position)
    {
        PickUpItem pickUp = Instantiate(pickUpItem, position, Quaternion.identity);

        pickUp.SetUp(item);
        return(pickUp);
    }
    // Use this for initialization
    void Start()
    {
        inventoryItemList = (ItemDataBaseList)Resources.Load("ItemDatabase");

        while (counter < amountOfLoot)
        {
            counter++;

            int randomNumber = Random.Range(1, inventoryItemList.itemList.Count - 1);

            Terrain terrain = Terrain.activeTerrain;

            float x = Random.Range(5, terrain.terrainData.size.x - 5);
            float z = Random.Range(5, terrain.terrainData.size.z - 5);


            if (inventoryItemList.itemList[randomNumber].itemModel == null)
            {
                counter--;
            }
            else
            {
                GameObject randomLootItem = (GameObject)Instantiate(inventoryItemList.itemList[randomNumber].itemModel);
                PickUpItem item           = randomLootItem.AddComponent <PickUpItem>();
                item.item = inventoryItemList.itemList[randomNumber];

                randomLootItem.transform.localPosition = new Vector3(x, 0, z);
            }
        }
    }
 public Item(PickUpItem pickUpItem)
 {
     sprite = pickUpItem.GetComponent <SpriteRenderer>().sprite;
     name   = instance.CleanItemName(pickUpItem.name);
     info   = pickUpItem.info;
     id     = pickUpItem.id;
 }
Esempio n. 8
0
 public void RemoveItem(PickUpItem item, int itemGUIIndex)
 {
     items.Remove (item);
     itemGUIs.transform.GetChild(itemGUIIndex).GetComponent<Button>().onClick.RemoveAllListeners();
     itemGUIs.transform.GetChild(itemGUIIndex).GetChild(1).GetComponent<Text>().text = "None";
     itemGUIs.transform.GetChild(itemGUIIndex).GetChild(0).GetComponent<Image>().sprite = null;
 }
Esempio n. 9
0
        void ShowPickupItem(object obj)
        {
            float animTime = 0.3f;
            float waitTime = 0.3f;

            if (PickUpItem.Count > 0)
            {
                SoundManager.Instance.PlaySoundEffect("Sound_UIEff_AppraisalFields");
                int showItem = PickUpItem[0];
                PickUpItem.RemoveAt(0);
                SingleRewardItem_V3 newItem = CreatObjectToNGUI.InstantiateObj(SingleRewardItemPrefab, PickupItemTransform).GetComponent <SingleRewardItem_V3>();
                DoForTime.DoFunForTime(0.3f, ShowPickupEffect, null);
                newItem.Init(showItem, 1);
                if (PickupItemObjList.Count >= 3)
                {
                    var removeObj = PickupItemObjList[2];
                    Destroy(removeObj);
                    PickupItemObjList.RemoveAt(2);
                }
                for (int i = 0; i < PickupItemObjList.Count; i++)
                {
                    Vector3 fromPosition = new Vector3(0, 32 * i, 0);
                    Vector3 toPosition   = new Vector3(0, 32 + 32 * i, 0);
                    TweenPosition.Begin(PickupItemObjList[i], animTime, fromPosition, toPosition);
                }
                PickupItemObjList.Insert(0, newItem.gameObject);
                Vector3 newItemFromPos = new Vector3(-138, 0, 0);
                Vector3 newItemToPos   = new Vector3(0, 0, 0);
                TweenPosition.Begin(newItem.gameObject, animTime, newItemFromPos, newItemToPos, PlayGetItemSound);
                DoForTime.DoFunForTime(waitTime, ShowPickupItem, null);
            }
        }
Esempio n. 10
0
 private void PickUpAction(PickUpItem pickUpItem)
 {
     _soundEffect.Play();
     _success.Play();
     ScoreHandler.AddPoint();
     pickUpItem.Sprite.Alive = false;
 }
Esempio n. 11
0
    public void ExchangeWeapon(PickUpItem playersItem, PlayerController player)
    {
        // this refers to the item lying on the ground
        // playersItem refers to item in the hands of the player

        // ----soundeffect---
        AudioSource audio = Instantiate(PickUpSound);       //play pickupsound

        Destroy(audio.gameObject, 1);                       //destory it after 1 sec

        // -----exchange-----
        Transform  parent   = playersItem.transform.parent;         // set a reference for parent of players item
        Vector3    position = playersItem.transform.localPosition;  // set a reference for players items position
        Quaternion rotation = playersItem.transform.localRotation;  // set a reference for players items rotation

        playersItem.transform.parent   = null;                      // remove parent from players item
        playersItem.transform.position = this.transform.position;   // set players items position to the items position on the ground
        playersItem.transform.rotation = this.transform.rotation;   // set players items rotation to the items rotation on the ground

        playersItem.Drop();

        this.interactionCollider.enabled = false;
        this.PickUpIndicator.SetActive(false);

        player.interactionTrigger.RemoveAllListeners();             // stop all functions from listening to instructions from the player

        OnTriggerEnter(player.GetComponent <Collider>());           // simulate the item from the hands being triggered by the player

        this.transform.SetParent(parent);                           // set parent of the item on the ground to the reference set
        this.transform.localPosition = position;                    // set position of item on the ground to the reference set
        this.transform.localRotation = rotation;                    // set rotation of item on the ground to the reference set

        try { parent.GetComponent <Caller>().link.UpdateAmmoVisuals(); } catch { /*Debug.LogError(parent);*/ }
    }
Esempio n. 12
0
    public void AnimationEvent_ExchangeItem()
    {
        PickUpItem myItem = GetComponentInChildren <PickUpItem>();

        Debug.Log("Initialize WeaponExchange");
        interactionTrigger.Invoke(myItem, this);
    }
Esempio n. 13
0
    protected override void OnInteractableStart(GameObject invokerObject)
    {
        base.OnInteractableStart(invokerObject);

        if (invokerObject == null)
        {
            LightFire();
            return;
        }

        if (playerInventory.GetHolding())
        {
            playerItem = player.GetComponentInChildren <PickUpItem>();

            if (fuel >= 0.9f)
            {
                GameManager.instance.Notify("Fire is fully fueled!", 3);
            }
            else
            {
                if (playerItem.itemDefinition == PickUpItem.items.WOODPILE && fuel <= 0.1f)
                {
                    LightFire();
                    playerInventory.DestroyHeldItem();
                }
                else if (playerItem.itemDefinition == PickUpItem.items.WOODPILE && fuel >= 0.1f)
                {
                    playerInventory.DestroyHeldItem();
                    fuel += 0.3f;
                }
            }
        }
    }
Esempio n. 14
0
    private void Drop(Item item)
    {
        PickUpItem pickupItem = Instantiate(item.pickUpPrefab, Player.Character.transform.position, Quaternion.Euler(0, Random.Range(0, 360f), 0));

        pickupItem.Item = item;
        NetworkServer.Spawn(pickupItem.gameObject);
    }
Esempio n. 15
0
    public void SellItem()
    {
        MainCharacterController.Instance.AddMoney(price);
        PickUpItem item = PickUpTypeList.Instance.GetPickUpItem(itemType);

        MainCharInventory.Instance.DecreaseItemCount(item, 1);
        UpdateCount(-1);
    }
Esempio n. 16
0
    public void DropLoot(Vector2 dropPoint, int whatItem)
    {
        GameObject lootItem = (GameObject)Instantiate(inventoryItemList.itemList[whatItem].itemModel, dropPoint, Quaternion.Euler(0, 0, 0));
        PickUpItem item     = lootItem.AddComponent <PickUpItem>();

        item.item = inventoryItemList.itemList[whatItem];
        lootItem.transform.localPosition = dropPoint;
    }
Esempio n. 17
0
    // Start is called before the first frame update
    void Start()
    {
        room.SetActive(false);
        pickUpScript = GetComponent <PickUpItem>();
        rend         = GetComponent <Renderer>();

        hideWithTag = GameObject.FindGameObjectsWithTag(roomTag);
    }
Esempio n. 18
0
    public void DeleteItem(PickUpItem item)
    {
        StoreRange  -= Spacing;
        item.OnSeen -= UpdateIDs;

        PreviousPositions.RemoveRange(0, Spacing);
        ItemsQueue.Remove(item);
    }
Esempio n. 19
0
    public static PickUpItem SpawnPickUpItem(Item item, Vector3 position)
    {
        Transform  transform  = Instantiate(GameAssets.i.pfPickupItem, position, Quaternion.identity);
        PickUpItem pickUpItem = transform.GetComponent <PickUpItem>();

        pickUpItem.SetItem(item);
        return(pickUpItem);
    }
Esempio n. 20
0
    private void OnTriggerEnter(Collider other)
    {
        PickUpItem item = other.GetComponent <PickUpItem>();

        if (item != null)
        {
            Validate(item);
        }
    }
Esempio n. 21
0
    private void OnTriggerExit(Collider other)
    {
        PickUpItem pickUpItem = other.GetComponent <PickUpItem>();

        if (pickUpItem != null)
        {
            pickupObjects.Remove(other.gameObject);
        }
    }
Esempio n. 22
0
    public void DropWeapon()
    {
        GetComponent <HandIKControl>().Clear();

        PickUpItem weapon = GetComponentInChildren <PickUpItem>();

        weapon.Drop(ammoLeft: leftoverAmmo);
        weapon.transform.parent = null;
    }
    // ---- PICK UP OBJECTS ---- //

    // Assign Pick up item to player for pick up
    public void RecievePickupItemReferences(PickUpItem _pickup, LootBoxPanel _lootPanel)
    {
        currentPickupItem = _pickup;

        if (currentPickupItem.isLootBox)
        {
            currentLootBoxPanel = _lootPanel;
        }
    }
Esempio n. 24
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.CompareTag("ValueItem"))
     {
         bar = collision.gameObject.GetComponent <PickUpItem>();
         collision.gameObject.GetComponent <PickUpItem>().TurnTextOn();
         inCollider   = true;
         pickedUpItem = collision.gameObject;
     }
 }
Esempio n. 25
0
        private bool CheckIfPlayerPickUpItem(PickUpItem pickUpItem, Rectangle targetRectangel, bool allItemIsCollected)
        {
            ItemIsPickedUp(pickUpItem, targetRectangel);

            if (pickUpItem.Sprite.Alive)
            {
                allItemIsCollected = false;
            }
            return(allItemIsCollected);
        }
Esempio n. 26
0
    void DropLoot()
    {
        Item item = dropTable.GetDrop();

        if (item != null)
        {
            PickUpItem instance = Instantiate(pickUpItem, transform.position, Quaternion.identity);
            instance.ItemDrop = item;
        }
    }
Esempio n. 27
0
    public void DestroyItem()
    {
        if (currentItem == null)
        {
            return;
        }

        Destroy(currentItem.gameObject);
        currentItem = null;
    }
Esempio n. 28
0
    // Start is called before the first frame update
    void Start()
    {
        rend = meshGO.GetComponent <Renderer>();
        note = GameObject.Find("Reverse");

        hideWithTag1 = GameObject.FindGameObjectsWithTag(roomTag1);
        hideWithTag2 = GameObject.FindGameObjectsWithTag(roomTag2);
        hideWithTag3 = GameObject.FindGameObjectsWithTag(roomTag3);

        cardPickUp = card.GetComponent <PickUpItem>();
    }
Esempio n. 29
0
    public PickUpItem GetPickUpItem(string itemTypeStr)
    {
        if (itemTypeStr == null)
        {
            return(null);
        }

        PickUpItem.ItemTypes type = PickUpItem.GetItemType(itemTypeStr);

        return(GetPickUpItem(type));
    }
Esempio n. 30
0
    private void Validate(PickUpItem item)
    {
        item.transform.DOMove(transform.position, validationTime);
        item.transform.DOScale(0.01f, validationTime).OnComplete(() => DisableItem(item));
        currentValidatedItems++;
        if (currentValidatedItems >= nbItemNeeded)
        {
            GameManager.Instance.Win();
        }

        UpdateUi();
    }
Esempio n. 31
0
    private void Update()
    {
        _mesh = new Mesh();

        _points      = new Vector3[rayNumber + 1];
        _tris        = new int[(rayNumber - 1) * 3];
        _indexPoints = 0;
        _indexTris   = 0;

        _points[0] = transform.parent.InverseTransformPoint(new Vector3(transform.parent.position.x, transform.parent.position.y + 0.1f, transform.parent.position.z));
        _indexPoints++;

        if (rayNumber - 1 != 0)
        {
            _angleStep = coneAngle / (rayNumber - 1);
        }
        else
        {
            _angleStep = coneAngle;
        }


        for (int i = 0; i < rayNumber; i++)
        {
            Vector3 rayPoint = new Vector3(transform.position.x + raycastDistance * Mathf.Cos((-coneAngle / 2 + (_angleStep * i) + 90 - transform.eulerAngles.y) * Mathf.Deg2Rad), transform.position.y, transform.position.z + raycastDistance * Mathf.Sin((-coneAngle / 2 + (_angleStep * i) + 90 - transform.eulerAngles.y) * Mathf.Deg2Rad));
            Ray     ray      = new Ray(transform.parent.position, rayPoint - transform.parent.position);
            //Debug.DrawRay(ray.origin, ray.direction * raycastDistance, Color.cyan);
            if (Physics.Raycast(ray, out _hit, raycastDistance, ~IgnoreLayer))
            {
                PickUpItem item = _hit.collider.GetComponent <PickUpItem>();
                if (item != null)
                {
                    item.SeenByGuard();
                }
                rayPoint = _hit.point;
            }
            _points[_indexPoints] = transform.parent.InverseTransformPoint(new Vector3(rayPoint.x, transform.parent.position.y + 0.1f, rayPoint.z));
            _indexPoints++;

            if (i > 0)
            {
                _tris[_indexTris]     = 0;
                _tris[_indexTris + 1] = i + 1;
                _tris[_indexTris + 2] = i;
                _indexTris           += 3;
            }
        }

        _mesh.vertices  = _points;
        _mesh.triangles = _tris;
        _meshFilter.transform.position = transform.parent.position;
        _meshFilter.mesh = _mesh;
    }
Esempio n. 32
0
    public void createPickUps()
    {
        int randomNumberPickUps = Random.Range(0, maxNumberPickUps);
        Tile[] tiles = boardManagerScript.tiles.ToArray();

        for (int i = 0; i < randomNumberPickUps; i++)
        {
            int randomTilePlacement = Random.Range(2, boardManagerScript.tiles.Count);
            Tile placementTile = tiles[randomTilePlacement];

            GameObject currPickUpItem = (GameObject)Instantiate(pickUp, placementTile.position, placementTile.tile.transform.rotation);
            currPickUpItem.collider.isTrigger = true;
            currPickUpItem.transform.localScale = new Vector3(.3f, .3f, .3f);
            currPickUpItem.renderer.material.color = Color.cyan;

            totalPickUps++;

            PickUpItem currItem = new PickUpItem(currPickUpItem, placementTile, totalPickUps);
            pickUpList.Add(currItem);
        }
    }
Esempio n. 33
0
 public static void AddItem(PickUpItem item)
 {
     instance.items.Add (item);
     instance.UpdateItemSlot(instance.items.Count - 1);
     instance.HideObj (item.gameObject);
 }