Exemple #1
0
    public void InitialzeInventories()
    {
        InventoryObjects = new List <GameObject>();
        List <ObjectInfo> inventories = loader.GetSavedObjFromChunkPos(new Vector2(chunkPos.x, chunkPos.y), SavedObjType.Inventory);

        for (int i = 0; i < inventories.Count; i++)
        {
            ObjectInfo data = inventories[i];
            if (data.Prefab == "")
            {
                continue;
            }

            Vector3 pos = new Vector3(
                (float)data.LocalPos[0] + transform.position.x,
                0.0f,
                (float)data.LocalPos[1] + transform.position.z
                );

            Quaternion rotation = Quaternion.Euler((float)data.Rotation[0], (float)data.Rotation[1], (float)data.Rotation[2]);

            GameObject inventoryObj = Instantiate(Resources.Load <GameObject>(data.Prefab), pos, rotation, transform);
            inventoryObj.name = data.ObjectName;
            InventoryObjects.Add(inventoryObj);

            Inventory invClass = inventoryObj.GetComponentInChildren <Inventory>();
            if (invClass == null)
            {
                Help.print("Inventory at", pos, "does not have an inventory.");
                continue;
            }

            if (InventorySaver.MostRecentInventorySave.ContainsKey(data.ObjectName))
            {
                invClass.Load(InventorySaver.MostRecentInventorySave[data.ObjectName]);
            }
            else
            {
                invClass.Load(new List <ItemSave>(data.Inventory));
            }
        }
    }