Beispiel #1
0
        public IEnumerator HarvestTest()
        {
            // load the test scene
            EditorSceneManager.LoadSceneInPlayMode
            (
                "Assets/Resources/Scenes/Test_Scene.unity",
                new LoadSceneParameters(LoadSceneMode.Single, LocalPhysicsMode.Physics2D)
            );

            yield return(TestUtilities.AssertSceneLoaded("Assets/Resources/Scenes/Test_Scene.unity"));

            Inventory    inventory    = Object.FindObjectOfType <Inventory>();
            NodeGrid     grid         = Object.FindObjectOfType <NodeGrid>();
            LoadingOrder loadingOrder = Object.FindObjectOfType <LoadingOrder>();
            ItemType     itemType     = Resources.Load("SO/Potato") as ItemType;

            // wait till grid is loaded
            while (!grid.LoadedSection)
            {
                yield return(null);
            }

            // wait till all data is loaded
            while (!loadingOrder.LoadedAll)
            {
                yield return(null);
            }

            if (itemType == null)
            {
                Debug.LogError("There is no ItemType scriptable object at path: SO/Potato");
            }

            // get the node we are going to plant on
            Node nodeToPlant = grid.GetNodeFromXY(0, 0);

            // plant the prefab
            bool succesfulPlanting = false;

            nodeToPlant.Interactable.OnInteract(ToolTypes.Hoe);
            nodeToPlant.Interactable.OnInteract(ToolTypes.Other, prefab, () => succesfulPlanting = true);
            Assert.IsTrue(succesfulPlanting);

            // get the single plant we made in this scene
            Plantable plant = Object.FindObjectOfType <Plantable>();

            // Harvest the plant
            plant.Grow(completeGrowth);
            plant.OnHarvest(ToolTypes.Sickle, null);

            // check if the items dropped
            WorldItem[] worldItems = Object.FindObjectsOfType <WorldItem>();
            Assert.IsTrue(worldItems.Length >= 2 && worldItems.Length <= 5);

            yield return(null);

            // plant object should be destroyed
            Assert.IsTrue(plant == null);
        }
Beispiel #2
0
 private void Harvest(ToolTypes toolType)
 {
     if (plant != null)
     {
         plant.OnHarvest(toolType, () => plant = null);
         INodeData node = nodeGrid.GetNodeFromXY(X, Y);
         node.Data.IsOccupied = false;
     }
 }
Beispiel #3
0
        private void RemoveSprinkler()
        {
            // drop the world item
            sprinklerItem.SpawnWorldItem(transform.position, 1);

            Node middleNode = nodeGrid.GetNodeFromXY(X, Y);

            // reassign to the previous interactable
            middleNode.Interactable = prevInteractable;

            // remove as a water source from neighbours
            ModifyAsWaterSource(false);
            SectionData.Current.TechDatas.Remove(Data);

            Destroy(gameObject);
        }