Esempio n. 1
0
    public static PlantDataStruct GetPlantData(int objId)
    {
        PlantDataStruct temp = new PlantDataStruct();

        temp.SpeciesId     = PlayerPrefs.GetInt("Plant_SpeciesId_" + objId, -1);
        temp.state         = (PlantState)PlayerPrefs.GetInt("Plant_State_" + objId, (int)PlantState.NONE);
        temp.RemainingTime = PlayerPrefs.GetInt("Plant_RemainingTime_" + objId, 0);
        temp.ReferenceTime = ulong.Parse(PlayerPrefs.GetString("Plant_ReferenceTime_" + objId, (0).ToString()));
        temp.MaxTime       = PlayerPrefs.GetInt("Plant_MaxTime_" + objId, 0);
        return(temp);
    }
Esempio n. 2
0
        public static void LoadPlantItems(MapDataSo map, MapType mapType)
        {
            Debug.Log("Loading Map ITEMS to ECS: " + map.id);

            //-- Update References
            if (!PlantItemReferences.IsCreated)
            {
                PlantItemReferences = new NativeHashMap <byte, PlantDataStruct>(
                    map.plantRefList.list.Length, Allocator.Persistent);

                for (int i = 0; i < map.plantRefList.list.Length; i++)
                {
                    PlantItemReferences[(byte)i] = PlantDataStruct.FromSo(map.plantRefList.list[i].data);
                }
            }



            if (mapType == MapType.current)
            {
                mapType = MapType.main;
            }


            var items = new NativeHashMap <int, PlantItem>(
                map.plantItems.Count, Allocator.Persistent);

            PlantItem       p;
            PlantDataStruct pds;
            int             index;

            for (int i = 0; i < map.plantItems.Count; i++)
            {
                p   = map.plantItems[i];
                pds = PlantItemReferences[p.TypeId];

                index        = map.GetGridIndex(p.Pos);
                items[index] = p;
            }

            if (mapType == MapType.main)
            {
                if (MainMapPlantItems.IsCreated)
                {
                    MainMapPlantItems.Dispose();
                }
                MainMapPlantItems = items;
            }
            else if (mapType == MapType.secondary)
            {
                if (SecondaryMapPlantIems.IsCreated)
                {
                    SecondaryMapPlantIems.Dispose();
                }
                SecondaryMapPlantIems = items;
            }
            else
            {
                Debug.LogWarning("Map type not recongnized: " + mapType);
            }


            //Update Mono Manager
            PlantManager.Instance.LoadPlants(map, mapType);
        }