Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyUp(KeyCode.I))
        {
            if (showInventory)
            {
                showInventory      = false;
                GameState.TheState = GameState.State.playing;
            }
            else
            {
                showInventory      = true;
                GameState.TheState = GameState.State.paused;
            }
        }

        // Auto-craft
        string[] raftArr       = { "Log", "Rope" };
        string[] torchArr      = { "Rag", "Fuel", "Stick" };
        string[] flashlightArr = { "Flashlight", "Battery" };

        if (checkPreconditions(raftArr))
        {
            for (uint i = 0; i < raftArr.Length; i++)
            {
                UseItem(getPosOf(raftArr[i]));
            }
            // Add raft
            var obj        = Instantiate(RaftPrefab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
            var item       = obj.GetComponent <LootItem>();
            var iconSprite = item.iconSprite;
            var icon       = new Texture2D((int)iconSprite.rect.width, (int)iconSprite.rect.height);

            var pixels = iconSprite.texture.GetPixels((int)iconSprite.textureRect.x,
                                                      (int)iconSprite.textureRect.y,
                                                      (int)iconSprite.textureRect.width,
                                                      (int)iconSprite.textureRect.height);

            icon.SetPixels(pixels);
            icon.Apply();

            ItemCreatorClass itc = new ItemCreatorClass(item.name, icon, item.description);
            InventoryContent[getFirstEmpty()] = itc;
            Destroy(obj);
        }
        if (checkPreconditions(torchArr))
        {
            for (uint i = 0; i < torchArr.Length; i++)
            {
                UseItem(getPosOf(torchArr[i]));
            }
            // Add raft
            var obj              = Instantiate(TorchPrefab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
            var item             = obj.GetComponent <LootItem>();
            ItemCreatorClass itc = new ItemCreatorClass(item.name, item.iconSprite.texture, item.description);
            InventoryContent[getFirstEmpty()] = itc;
            Destroy(obj);
        }
    }
Ejemplo n.º 2
0
    void Start()
    {
        var icon = new Texture2D((int)iconSprite.rect.width, (int)iconSprite.rect.height);

        var pixels = iconSprite.texture.GetPixels((int)iconSprite.textureRect.x,
                                                  (int)iconSprite.textureRect.y,
                                                  (int)iconSprite.textureRect.width,
                                                  (int)iconSprite.textureRect.height);

        icon.SetPixels(pixels);
        icon.Apply();

        inventoryGUI  = GameObject.FindGameObjectWithTag("Player");
        icc           = new ItemCreatorClass(itemname, icon, description);
        inventoryList = inventoryGUI.GetComponent <InventoryGUI>().InventoryContent;
    }
Ejemplo n.º 3
0
    void Start()
    {
        var icon = new Texture2D((int)iconSprite.rect.width, (int)iconSprite.rect.height);

        var pixels = iconSprite.texture.GetPixels((int)iconSprite.textureRect.x,
        (int)iconSprite.textureRect.y,
        (int)iconSprite.textureRect.width,
        (int)iconSprite.textureRect.height);

        icon.SetPixels(pixels);
        icon.Apply();

        inventoryGUI = GameObject.FindGameObjectWithTag("Player");
        icc = new ItemCreatorClass(itemname, icon, description);
        inventoryList = inventoryGUI.GetComponent<InventoryGUI>().InventoryContent;
    }
Ejemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        if(Input.GetKeyUp(KeyCode.I))
        {
            if(showInventory)
            {
                showInventory = false;
                GameState.TheState = GameState.State.playing;
            }
            else
            {
                showInventory = true;
                GameState.TheState = GameState.State.paused;
            }
        }

        // Auto-craft
        string[] raftArr = {"Log", "Rope"};
        string[] torchArr = {"Rag", "Fuel", "Stick"};
        string[] flashlightArr = {"Flashlight", "Battery"};

        if (checkPreconditions (raftArr)) {
            for(uint i = 0; i < raftArr.Length; i++)
                UseItem(getPosOf(raftArr[i]));
            // Add raft
            var obj = Instantiate(RaftPrefab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
            var item = obj.GetComponent<LootItem>();
            var iconSprite = item.iconSprite;
            var icon = new Texture2D((int)iconSprite.rect.width, (int)iconSprite.rect.height);

            var pixels = iconSprite.texture.GetPixels((int)iconSprite.textureRect.x,
                                                      (int)iconSprite.textureRect.y,
                                                      (int)iconSprite.textureRect.width,
                                                      (int)iconSprite.textureRect.height);

            icon.SetPixels(pixels);
            icon.Apply();

            ItemCreatorClass itc = new ItemCreatorClass(item.name, icon, item.description);
            InventoryContent[getFirstEmpty()] = itc;
            Destroy(obj);
        }
        if (checkPreconditions (torchArr)) {
            for(uint i = 0; i < torchArr.Length; i++)
                UseItem(getPosOf(torchArr[i]));
            // Add raft
            var obj = Instantiate(TorchPrefab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
            var item = obj.GetComponent<LootItem>();
            ItemCreatorClass itc = new ItemCreatorClass(item.name, item.iconSprite.texture, item.description);
            InventoryContent[getFirstEmpty()] = itc;
            Destroy(obj);
        }
    }