Esempio n. 1
0
    void LoadInventoryAndFactories()
    {
        string filePath = Application.persistentDataPath + "/" + saveFileName;

        if (System.IO.File.Exists(filePath))
        {
            InventoryData data = DataManager.XMLUnmarshalling <InventoryData>(filePath);
            LoadInventory(data);
        }
        else
        {
            //Bear toy: P02 + P01 + P04 + P03
            List <Piece> bearPieces = new List <Piece>();

            bearPieces.Add(Recipes.Instance.recipes["P02"]);
            bearPieces.Add(Recipes.Instance.recipes["P01"]);
            bearPieces.Add(Recipes.Instance.recipes["P04"]);
            bearPieces.Add(Recipes.Instance.recipes["P03"]);

            for (int i = 0; i < 10; i++)
            {
                Toy.ToyData bear = new Toy.ToyData()
                {
                    pieces = bearPieces.ToArray()
                };

                toys.Add(bear);
                MiniGameManager.Instance.GenerateToy(bear);
            }

            IItem piece = Recipes.Instance.recipes["P02"].ToInventory();
            piece.Quantity = 12;
            pieces.Add(piece.Code, piece);

            piece          = Recipes.Instance.recipes["P01"].ToInventory();
            piece.Quantity = 12;
            pieces.Add(piece.Code, piece);

            piece          = Recipes.Instance.recipes["P04"].ToInventory();
            piece.Quantity = 12;
            pieces.Add(piece.Code, piece);

            piece          = Recipes.Instance.recipes["P03"].ToInventory();
            piece.Quantity = 12;
            pieces.Add(piece.Code, piece);
        }

        ensambler.TryLoad();
        factory.TryLoad();

        Shop.Instance.UpdateGUI();
        UpdateGUI(Type.Worker);
        Recipes.Instance.UpdateGUI();
    }
Esempio n. 2
0
    void CreateToy(Piece[] pieces, int totalQuantity)
    {
        foreach (Piece p in pieces)
        {
            Inventory.Instance.Remove(p.id, totalQuantity, Inventory.Type.Piece);
        }

        Toy.ToyData data = new Toy.ToyData()
        {
            pieces = pieces
        };

        Inventory.Instance.Add(data);

        MiniGameManager.Instance.GenerateToy(data);
    }
Esempio n. 3
0
    void LoadInventory(InventoryData data)
    {
        Money = data.Money;

        for (int i = 0; i < data.items.Length; i++)
        {
            switch (data.items[i].type)
            {
            case Type.Material:
                IItem material = Shop.Instance.materials[data.items[i].id].InventoryItem;
                material.Quantity = data.items[i].quantity;
                materials.Add(material.Code, material);
                break;

            case Type.Piece:
                IItem piece = Recipes.Instance.recipes[data.items[i].id].ToInventory();
                piece.Quantity = data.items[i].quantity;
                pieces.Add(piece.Code, piece);
                break;

            case Type.Worker:
                IItem worker = Shop.Instance.workers[data.items[i].id].InventoryItem;
                worker.Quantity = data.items[i].quantity;
                workers.Add(worker.Code, worker);
                Shop.Instance.workers.Remove(worker.Code);
                break;
            }
        }

        for (int i = 0; i < data.toys.Length; i++)
        {
            Toy.ToyData toy = new Toy.ToyData();
            toy.pieces = new Piece[data.toys[i].idPieces.Length];

            for (int j = 0; j < data.toys[i].idPieces.Length; j++)
            {
                toy.pieces[j] = Recipes.Instance.recipes[data.toys[i].idPieces[j]];
            }

            toys.Add(toy);
            MiniGameManager.Instance.GenerateToy(toy);
        }

        UIManager.Instance.UpdateMoney();
    }
Esempio n. 4
0
    public void GenerateToy(Toy.ToyData data)
    {
        double deltaSeconds = (DateTime.Now.TimeOfDay - lastTimeToyCreated).TotalSeconds;

        if (deltaSeconds < creatingToyDelay)
        {
            StartCoroutine(ToyStack(data, (float)(creatingToyDelay + .1f - deltaSeconds)));
            return;
        }

        //Code to generate a Toy
        GameObject prefab     = UIManager.Instance.generateToy.basePrefab;
        Transform  parent     = UIManager.Instance.generateToy.parent;
        Transform  startPoint = UIManager.Instance.generateToy.generationPoint;

        SpriteRenderer sr = prefab.GetComponent <SpriteRenderer>();

        sr.sprite = data.pieces[0].sprite;
        sr.color  = data.pieces[0].color;

        GameObject toy = ObjectPool.Instantiate(prefab, startPoint.position, prefab.transform.rotation, parent);

        toy.GetComponent <Toy>().item = data.pieces[0];
        toy.GetComponent <Toy>().data = data;

        GameObject piecePrefab = UIManager.Instance.generateToy.piecePrefab;

        for (int i = 1; i < data.pieces.Length; i++)
        {
            SpriteRenderer psr = piecePrefab.GetComponent <SpriteRenderer>();
            psr.sprite = data.pieces[i].sprite;
            psr.color  = data.pieces[i].color;

            GameObject piece = ObjectPool.Instantiate(piecePrefab, toy.transform.position, piecePrefab.transform.rotation, toy.transform);

            piece.GetComponent <MiniGamePiece>().item = data.pieces[i];

            //Add the Joint to make them together;
            //toy.AddComponent<FixedJoint2D>().connectedBody = piece.GetComponent<Rigidbody2D>();
        }

        lastTimeToyCreated = DateTime.Now.TimeOfDay;
    }
Esempio n. 5
0
 public void Remove(Toy.ToyData toy)
 {
     toys.Remove(toy);
 }
Esempio n. 6
0
 public void Add(Toy.ToyData toy)
 {
     toys.Add(toy);
 }
Esempio n. 7
0
    IEnumerator ToyStack(Toy.ToyData data, float waitTime)
    {
        yield return(new WaitForSeconds(waitTime));

        GenerateToy(data);
    }