public static FloatingChunk SpawnChunk(Biome.ChunkConfiguration chunkType, Vector3 location, Node worldNode, PackedScene chunkScene, CompoundCloudSystem cloudSystem, Random random) { var chunk = (FloatingChunk)chunkScene.Instance(); // Settings need to be applied before adding it to the scene chunk.GraphicsScene = chunkType.Meshes[random.Next(chunkType.Meshes.Count)]. LoadedScene; // Pass on the chunk data chunk.Init(chunkType, cloudSystem); worldNode.AddChild(chunk); // Chunk is spawned with random rotation chunk.Transform = new Transform(new Quat( new Vector3(0, 1, 1).Normalized(), 2 * Mathf.Pi * (float)random.NextDouble()), location); chunk.Scale = new Vector3(chunkType.ChunkScale, chunkType.ChunkScale, chunkType.ChunkScale); chunk.AddToGroup(Constants.FLUID_EFFECT_GROUP); chunk.AddToGroup(Constants.AI_TAG_CHUNK); return(chunk); }
/// <summary> /// Grabs data from the type to initialize this /// </summary> /// <remarks> /// <para> /// Doesn't initialize the graphics scene which needs to be set separately /// </para> /// </remarks> public void Init(Biome.ChunkConfiguration chunkType, CompoundCloudSystem compoundClouds, string modelPath = null) { this.compoundClouds = compoundClouds; // Grab data VentPerSecond = chunkType.VentAmount; Dissolves = chunkType.Dissolves; Size = chunkType.Size; Damages = chunkType.Damages; DeleteOnTouch = chunkType.DeleteOnTouch; Mass = chunkType.Mass; ModelNodePath = modelPath; // Apply physics shape var shape = GetNode <CollisionShape>("CollisionShape"); // This only works as long as the sphere shape type is not changed in the editor ((SphereShape)shape.Shape).Radius = chunkType.Radius; // Copy compounds to vent if (chunkType.Compounds != null && chunkType.Compounds.Count > 0) { // Capacity is set to 0 so that no compounds can be added // the normal way to the chunk ContainedCompounds = new CompoundBag(0); foreach (var entry in chunkType.Compounds) { ContainedCompounds.Compounds.Add(entry.Key, entry.Value.Amount); } } // Needs physics callback when this is engulfable or damaging if (Damages > 0 || DeleteOnTouch || Size > 0) { ContactsReported = Constants.DEFAULT_STORE_CONTACTS_COUNT; Connect("body_shape_entered", this, "OnContactBegin"); Connect("body_shape_exited", this, "OnContactEnd"); } }
public ChunkSpawner(Biome.ChunkConfiguration chunkType, CompoundCloudSystem cloudSystem) { this.chunkType = chunkType; this.cloudSystem = cloudSystem; chunkScene = SpawnHelpers.LoadChunkScene(); }
public static ChunkSpawner MakeChunkSpawner(Biome.ChunkConfiguration chunkType, CompoundCloudSystem cloudSystem) { return(new ChunkSpawner(chunkType, cloudSystem)); }