Exemplo n.º 1
0
        private void LoadExistingDirt()
        {
            // find the dirts data that matches its x and y.
            data = SectionData.Current.DirtDatas.Find(dirt => X == dirt.x && Y == dirt.y);

            PlantableData plantData = SectionData.Current.PlantDatas.Find(plant => plant.Id == data.Id);

            // if there is a matching plant data
            if (plantData != null)
            {
                // we must create a plant game object
                var prefab = Resources.Load(PLANTABLE_PREFAB_FOLDER + plantData.PrefabName) as GameObject;

                if (prefab == null)
                {
                    Debug.LogError("There is no planteable prefab at path: " + PLANTABLE_PREFAB_FOLDER + plantData.PrefabName);
                }

                var gameObject = Instantiate(prefab);
                gameObject.transform.position = transform.position;

                // assign the plant data
                plant      = gameObject.GetComponent <Plantable>();
                plant.Data = plantData;
            }
        }
Exemplo n.º 2
0
        public void Load()
        {
            bool noDirt = SectionData.Current.DirtDatas == null || SectionData.Current.DirtDatas.Count <= 0;

            if (noDirt)
            {
                // if there is no dirt data that was loaded then create a new one.
                data = new DirtData(UniqueIdGenerator.IdFromDate(), X, Y, false, false, 0);
            }
            else
            {
                LoadExistingDirt();
            }
        }