private void DoImportGrasses() { if (!ImportGrassInstancesOnly) { GGrassPrototypeGroup grassesGroup = DesData.Foliage.Grasses; if (grassesGroup == null || grassesGroup == GRuntimeSettings.Instance.foliageDefault.grasses) { CreateNewGrassPrototypesGroup = true; } if (CreateNewGrassPrototypesGroup) { grassesGroup = ScriptableObject.CreateInstance <GGrassPrototypeGroup>(); #if UNITY_EDITOR if (!Application.isPlaying) { string path = AssetDatabase.GetAssetPath(DesData); string directory = Path.GetDirectoryName(path); string filePath = Path.Combine(directory, string.Format("Grasses_{0}_{1}.asset", DesData.Id, System.DateTime.Now.Ticks)); AssetDatabase.CreateAsset(grassesGroup, filePath); } #endif DesData.Foliage.Grasses = grassesGroup; } grassesGroup.Prototypes.Clear(); DetailPrototype[] detailPrototypes = SrcData.detailPrototypes; for (int i = 0; i < detailPrototypes.Length; ++i) { GGrassPrototype proto = (GGrassPrototype)detailPrototypes[i]; grassesGroup.Prototypes.Add(proto); } GCommon.SetDirty(grassesGroup); } List <GGrassInstance> grasses = new List <GGrassInstance>(); int detailResolution = SrcData.detailResolution; int detailLayerCount = SrcData.detailPrototypes.Length; for (int layer = 0; layer < detailLayerCount; ++layer) { int[,] density = SrcData.GetDetailLayer(0, 0, detailResolution, detailResolution, layer); DoImportDetailLayer(layer, density, grasses); } DesData.Foliage.ClearGrassInstances(); DesData.Foliage.AddGrassInstances(grasses); if (DesTerrain != null) { DesData.Foliage.SetGrassRegionDirty(GCommon.UnitRect); DesTerrain.UpdateGrassPatches(-1, true); DesData.Foliage.ClearGrassDirtyRegions(); } DesData.SetDirty(GTerrainData.DirtyFlags.Foliage); //GC.Collect(); }
private void DoImportGeometry() { if (UseUnityTerrainSize) { DesData.Geometry.Width = SrcData.size.x; DesData.Geometry.Height = SrcData.size.y; DesData.Geometry.Length = SrcData.size.z; } int hmResolution = SrcData.heightmapResolution - 1; DesData.Geometry.HeightMapResolution = hmResolution; float[,] heightSample = SrcData.GetHeights(0, 0, DesData.Geometry.HeightMapResolution, DesData.Geometry.HeightMapResolution); Color[] heightMapColor = new Color[DesData.Geometry.HeightMapResolution * DesData.Geometry.HeightMapResolution]; float h = 0; Vector2 enc; int length = heightSample.GetLength(0); int width = heightSample.GetLength(1); for (int z = 0; z < length; ++z) { for (int x = 0; x < width; ++x) { h = Mathf.Clamp(heightSample[z, x], 0f, 0.99999f); enc = GCommon.EncodeTerrainHeight(h); heightMapColor[GUtilities.To1DIndex(x, z, width)] = new Color(enc.x, enc.y, 0, 0); } } DesData.Geometry.HeightMap.SetPixels(heightMapColor); DesData.Geometry.HeightMap.Apply(); DesData.Geometry.SetRegionDirty(GCommon.UnitRect); DesData.SetDirty(GTerrainData.DirtyFlags.GeometryTimeSliced); if (!SkipFoliageSnap) { if (DesTerrain != null) { DesData.Foliage.SetTreeRegionDirty(GCommon.UnitRect); DesData.Foliage.SetGrassRegionDirty(GCommon.UnitRect); DesTerrain.UpdateTreesPosition(); DesTerrain.UpdateGrassPatches(); DesData.Foliage.ClearTreeDirtyRegions(); DesData.Foliage.ClearGrassDirtyRegions(); } } //GC.Collect(); }
private static void InventoryAndWaterParkSetup() { // Setting a name for the Rockgrub LanguageHandler.SetTechTypeName(TechType.Rockgrub, "Rockgrub"); // Setting a Tooltip for the Rockgrub LanguageHandler.SetTechTypeTooltip(TechType.Rockgrub, "A small, luminescent scavenger"); // Setting a Sprite for the Rockgrub Sprite rockgrub = ImageUtils.LoadSpriteFromFile(Path.Combine(AssetsFolder, "RockGrub.png")); if (rockgrub != null) { SpriteHandler.RegisterSprite(TechType.Rockgrub, rockgrub); } // Setting Rockgrub's size in the Inventory CraftDataHandler.SetItemSize(TechType.Rockgrub, new Vector2int(1, 1)); // Setting WPC Parameters for Rockgrub so it can grow and breed normaly WaterParkCreature.waterParkCreatureParameters[TechType.Rockgrub] = new WaterParkCreatureParameters(0.03f, 0.7f, 1f, 1f); // Setting Fuel value for the Rockgrub BioReactorHandler.SetBioReactorCharge(TechType.Rockgrub, 350f); // Totally origina.. *cough* taken from MrPurple's CYS code #region BiomeData stuff Dictionary <TechType, List <BiomeData> > rockgrubBiomeData = new Dictionary <TechType, List <BiomeData> >() { { TechType.Rockgrub, new List <BiomeData>() { new BiomeData() { biome = BiomeType.SafeShallows_CaveSpecial, count = 3, probability = 1f }, new BiomeData() { biome = BiomeType.GrassyPlateaus_CaveCeiling, count = 3, probability = 1f }, new BiomeData() { biome = BiomeType.MushroomForest_CaveRecess, count = 5, probability = 1f }, new BiomeData() { biome = BiomeType.MushroomForest_CaveSpecial, count = 3, probability = 1f }, new BiomeData() { biome = BiomeType.MushroomForest_GiantTreeInteriorRecess, count = 3, probability = 1f }, new BiomeData() { biome = BiomeType.MushroomForest_GiantTreeInteriorSpecial, count = 3, probability = 1f }, new BiomeData() { biome = BiomeType.KooshZone_CaveWall, count = 3, probability = 1f }, new BiomeData() { biome = BiomeType.SparseReef_DeepWall, count = 4, probability = 1f }, new BiomeData() { biome = BiomeType.GrassyPlateaus_CaveCeiling, count = 3, probability = 1f }, new BiomeData() { biome = BiomeType.Dunes_Rock, count = 4, probability = 1f }, new BiomeData() { biome = BiomeType.Dunes_SandPlateau, count = 4, probability = 1f }, new BiomeData() { biome = BiomeType.Dunes_CaveCeiling, count = 4, probability = 1f }, new BiomeData() { biome = BiomeType.Dunes_CaveWall, count = 4, probability = 1f }, new BiomeData() { biome = BiomeType.Mountains_CaveWall, count = 4, probability = 1f }, new BiomeData() { biome = BiomeType.GrassyPlateaus_CaveFloor, count = 4, probability = 1f }, } } }; foreach (KeyValuePair <TechType, List <BiomeData> > pair in rockgrubBiomeData) { string classId = CraftData.GetClassIdForTechType(pair.Key) ?? pair.Key.AsString(); if (PrefabDatabase.TryGetPrefabFilename(classId, out string prefabpath)) { if (!WorldEntityDatabase.TryGetInfo(classId, out WorldEntityInfo info)) { info = new WorldEntityInfo() { cellLevel = LargeWorldEntity.CellLevel.Medium, classId = classId, localScale = UnityEngine.Vector3.one, prefabZUp = false, slotType = EntitySlot.Type.Medium, techType = pair.Key }; } WorldEntityDatabaseHandler.AddCustomInfo(classId, info); } SrcData data = new SrcData() { prefabPath = prefabpath, distribution = pair.Value }; LootDistributionHandler.AddLootDistributionData(classId, data); } #endregion }