コード例 #1
0
    public LootInstance Clone()
    {
        LootInstance tempLoot = new LootInstance();

        tempLoot.ItemKey  = this.ItemKey;
        tempLoot.MinStack = this.MinStack;
        tempLoot.MaxStack = this.MaxStack;

        return(tempLoot);
    }
コード例 #2
0
    public static GameObject SpawnLoot(int lootNum, int amount, Transform spawnPos)     //instanciates loot game objcts and assigns their needed values, returns game object for forgotten reasons
    {
        GameObject lootObj = Instantiate(Resources.Load <GameObject>(Loot.prefabPath)); //instanciates a defalut loot

        lootObj.transform.position = spawnPos.position;                                 //give it the given position
        LootInstance newLoot = lootObj.GetComponent <LootInstance>();                   //acces the loot instance script

        newLoot.lootNum = lootNum;                                                      //give values that can create the loot instance
        newLoot.amount  = amount;
        newLoot.DefineMe();                                                             //give the loot it's apperance and instanciate loot
        return(lootObj);
    }
コード例 #3
0
        public void InitInventoryPanel()
        {
            GameObject owner            = null;
            Sprite     associatedSprite = null;
            int        nbSlot           = 0;

            if (instance != null && instance.GetComponent <PawnInstance>() != null)
            {
                PawnInstance pawnInstance = instance.GetComponent <PawnInstance>();
                associatedSprite = pawnInstance.Data.AssociatedSprite;
                name             = pawnInstance.Data.PawnName;
                owner            = pawnInstance.gameObject;
                nbSlot           = data.NbSlot;
            }
            else if (GetComponent <LootInstance>() != null)
            {
                LootInstance lootInstance = GetComponent <LootInstance>();

                associatedSprite = GameManager.Instance.SpriteUtils.spriteLoot;
                inventoryPanel.transform.GetChild(1).gameObject.SetActive(false);
                owner  = lootInstance.gameObject;
                nbSlot = data.NbSlot;
            }
            else
            {
                return;
            }

            inventoryPanel.transform.GetChild(1).GetChild(0).GetComponent <Image>().sprite = associatedSprite;
            inventoryPanel.transform.GetChild(0).GetComponent <InventoryOwner>().Owner     = owner;

            for (int i = 0; i < nbSlot; i++)
            {
                //Create Slots
                GameObject currentgoSlotPanel = Instantiate(GameManager.Instance.PrefabUIUtils.PrefabSlotUI, Vector3.zero, Quaternion.identity) as GameObject;
                currentgoSlotPanel.transform.SetParent(inventoryPanel.transform.GetChild(0).transform);

                currentgoSlotPanel.transform.localPosition = Vector3.zero;
                currentgoSlotPanel.transform.localScale    = Vector3.one;
                currentgoSlotPanel.name = "Slot" + i;
            }
        }
コード例 #4
0
        public void UpdateInventoryPanel()
        {
            GameObject owner            = null;
            Sprite     associatedSprite = null;
            string     name             = "";

            if (instance != null && instance.GetComponent <PawnInstance>() != null)
            {
                PawnInstance pawnInstance = instance.GetComponent <PawnInstance>();
                associatedSprite = pawnInstance.Data.AssociatedSprite;
                name             = pawnInstance.Data.PawnName;
                owner            = pawnInstance.gameObject;
            }
            else if (GetComponent <LootInstance>() != null)
            {
                LootInstance lootInstance = GetComponent <LootInstance>();

                associatedSprite = GameManager.Instance.SpriteUtils.spriteLoot;
                owner            = lootInstance.gameObject;
                name             = "Loot";
            }
            else
            {
                return;
            }

            for (int i = 0; i < items.Length; i++)
            {
                GameObject currentSlot = inventoryPanel.transform.GetChild(0).GetChild(i).gameObject;
                if (currentSlot.GetComponentInChildren <ItemInstance>() != null)
                {
                    Destroy(currentSlot.GetComponentInChildren <ItemInstance>().gameObject);
                }
            }

            for (int i = 0; i < items.Length; i++)
            {
                if (items[i] != null && items[i].Item != null && items[i].Item.Id != null)
                {
                    GameObject currentSlot = inventoryPanel.transform.GetChild(0).GetChild(i).gameObject;
                    GameObject go          = Instantiate(GameManager.Instance.PrefabUIUtils.PrefabItemUI);
                    go.transform.SetParent(currentSlot.transform);
                    go.GetComponent <ItemInstance>().ItemContainer = items[i];
                    go.name = items[i].ToString();

                    go.GetComponent <Image>().sprite = items[i].Item.InventorySprite;
                    go.transform.localScale          = Vector3.one;

                    go.transform.position = currentSlot.transform.position;
                    go.transform.SetAsFirstSibling();

                    if (go.GetComponent <ItemInstance>().ItemContainer.Item.GetType() == typeof(Ressource))
                    {
                        go.transform.GetComponentInChildren <Text>().text = items[i].Quantity.ToString();
                    }
                    else
                    {
                        go.transform.GetComponentInChildren <Text>().text = "";
                    }
                }
            }
        }
コード例 #5
0
    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;
        if (timer > .1f)
        {
            loot  = false;
            enemy = false;
            menu  = false;
            timer = 0;
            if (Physics.Raycast(transform.position, transform.forward, out hit, 25, layerMask))
            {
                if (hit.transform.tag == "Loot")
                {
                    lootLookingAt = hit.transform.gameObject.GetComponent <LootInstance>();
                    loot          = true;
                }
                if (hit.transform.tag == "Enemy")
                {
                    enemyBehaviour = hit.transform.gameObject.GetComponent <EnemyBehaviour>();
                    enemy          = true;
                }
                if (hit.transform.CompareTag("Menu"))
                {
                    menuObj = hit.transform.gameObject.GetComponent <OpenMenu>();
                    menu    = true;
                }
            }
        }

        if (loot)
        {
            if (Input.GetKeyDown(KeyCode.E))
            {
                loot = false;
                lootLookingAt.AddToInventory(playerInv);
            }
            lootText.text = lootLookingAt.name + "\r\n" + lootLookingAt.amount + " x" + "\r\n" + "Press E";
        }
        else
        {
            lootText.text = "";
        }

        if (enemy && enemyBehaviour != null)
        {
            enemyText.text             = enemyBehaviour.name;
            enemyHp.text               = enemyBehaviour.Hp + "/" + enemyBehaviour.thisEnemy.hp;
            image.transform.localScale = new Vector3(enemyBehaviour.Hp / enemyBehaviour.thisEnemy.hp, 1);
            enemyCanvas.alpha          = 1;
        }
        else
        {
            enemyText.text    = "";
            enemyHp.text      = "";
            enemyCanvas.alpha = 0;
        }

        if (menu)
        {
            if (Input.GetKeyDown(KeyCode.E))
            {
                print("open");
                menuObj.Open(true);
            }
            lootText.text = menuObj.name + "\r\n" + "Press E";
        }
        else
        {
            lootText.text = "";
        }
    }