コード例 #1
0
    public void SetupSelf(GameManager gm, GameObject myGameObject, GameItem data) // Called from GameManager on Load
    {
        GM         = gm;
        myGameItem = data;
        mainSprite = transform.Find("node_pot_base").GetComponent <SpriteRenderer>();
        topSprite  = transform.Find("node_flower_base").GetComponent <SpriteRenderer>();

        // Set Object name
        transform.name = myGameItem.itemProperties.displayedName;
        if (transform.name == "")
        {
            transform.name = "World Item";
        }

        // Set position
        this.transform.position = new Vector3(myGameItem.placedPointX, myGameItem.placedPointY, myGameItem.placedPointZ);

        // Get Sprites from GM Sprite Dictionary
        SetUpSprites();

        // If Pot with Plant, create the GameItem for the Pot
        if (myGameItem.itemProperties.itemType == ItemProperties.itemTypes.potWithPlant)
        {
            ItemProperties cloneOfPotScrObj = MagicTools.DeepCopy <ItemProperties>(GM.GetPotOriginal(myGameItem.basePotID));
            GameItem       potGI            = new GameItem();
            potGI.itemProperties = cloneOfPotScrObj;

            secondaryGameItem = potGI;
        }


        // Finally, tick bool
        myGameItem.inWorld = true;
    }
コード例 #2
0
    /// <summary>
    /// Runs on Game Startup. Not the same as displaying the items in the window. Try UpdateItemsForSale in MenuManager
    /// </summary>
    /// <param name="itemsLoaded"></param>
    public void LoadItemsForSale(List <GameItem> itemsLoaded) // Called From GM (TODO)
    {
        GM = FindObjectOfType <GameManager>();

        foreach (GameItem loadedGI in itemsLoaded)
        {
            ShopItem newShopItem = new ShopItem();
            newShopItem.mainGameItem = loadedGI;

            // If pot with plant, add the pot as secondary GameItem
            if (loadedGI.itemProperties.itemType == ItemProperties.itemTypes.potWithPlant)
            {
                ItemProperties originalPot      = GM.GetPotOriginal(loadedGI.basePotID);
                ItemProperties cloneOfPotScrObj = MagicTools.DeepCopy <ItemProperties>(originalPot);
                GameItem       potGI            = new GameItem();
                potGI.itemProperties = cloneOfPotScrObj;

                newShopItem.secondaryGameItem = potGI;
            }

            // Add the created ShopItem to the list of items for sale
            itemsForSale.Add(newShopItem);
        }

        Debug.Log(itemsForSale.Count + " Items loaded to Items For Sale");
    }
コード例 #3
0
    /// <summary>
    /// Overrides this item with a new Plant Game Item, keeping the pot sprite
    /// </summary>
    /// <param name="incomingPlantItem"></param>
    public void AddPlantToWorldPotItem(GameItem incomingPlantScriptable) // Called from GM
    {
        GameItem cloneOfIncomingPlantItem = MagicTools.DeepCopy <GameItem>(incomingPlantScriptable);

        cloneOfIncomingPlantItem.placedPointName = myGameItem.placedPointName;
        cloneOfIncomingPlantItem.placedPointX    = myGameItem.placedPointX;
        cloneOfIncomingPlantItem.placedPointY    = myGameItem.placedPointY;
        cloneOfIncomingPlantItem.placedPointZ    = myGameItem.placedPointZ;
        cloneOfIncomingPlantItem.basePotID       = myGameItem.itemProperties.itemID; // IMPORTANT. Allows loading of Pot Sprite on Game Re-Open

        secondaryGameItem = myGameItem;
        myGameItem        = cloneOfIncomingPlantItem;

        myGameItem.itemProperties.itemType = ItemProperties.itemTypes.potWithPlant;
        myGameItem.inWorld     = true;
        myGameItem.ageTimeMins = 0;

        // New Sprite Set for Plants
        spriteSet = GM.GetSpriteSet(myGameItem.itemProperties.itemID);

        StagePlanted();
    }