public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { var produce = new ProduceComponent { time = Time.realtimeSinceStartup, Production = new ResourceComponent // What the building is going to produce { gold = gold, wood = wood, steel = steel }, Storage = new ResourceComponent // What has been produced { gold = 0, wood = 0, steel = 0 } }; dstManager.AddComponentData(entity, produce); #if UNITY_EDITOR dstManager.SetName(entity, string.Format("Prefab #" + entity.Index + ":" + name, entity.Index)); #endif }
public void ProduceGrown(EntityUid uid, ProduceComponent produce) { if (!TryGetSeed(produce, out var seed)) { return; } if (TryComp(uid, out SpriteComponent? sprite)) { sprite.LayerSetRSI(0, seed.PlantRsi); sprite.LayerSetState(0, seed.PlantIconState); } var solutionContainer = _solutionContainerSystem.EnsureSolution(uid, produce.SolutionName); solutionContainer.RemoveAllSolution(); foreach (var(chem, quantity) in seed.Chemicals) { var amount = FixedPoint2.New(quantity.Min); if (quantity.PotencyDivisor > 0 && seed.Potency > 0) { amount += FixedPoint2.New(seed.Potency / quantity.PotencyDivisor); } amount = FixedPoint2.New((int)MathHelper.Clamp(amount.Float(), quantity.Min, quantity.Max)); solutionContainer.MaxVolume += amount; solutionContainer.AddReagent(chem, amount); } }
//Runs on the MainThread protected override JobHandle OnUpdate(JobHandle inputDependencies) { EntityManager entityManager = World.Active.EntityManager; NativeArray <Entity> entities = group.ToEntityArray(Allocator.TempJob); float gold = 0; float wood = 0; float steel = 0; foreach (Entity entity in entities) { ProduceComponent production = entityManager.GetComponentData <ProduceComponent>(entity); gold += production.Storage.gold; wood += production.Storage.wood; steel += production.Storage.steel; entityManager.SetComponentData(entity, new ProduceComponent { time = production.time, Production = production.Production, Storage = new ResourceComponent // What has been produced { gold = 0, wood = 0, steel = 0 } }); } entities.Dispose(); //array = new NativeArray<ProduceComponent>(); var job = new PayoutJob { gold = gold, wood = wood, steel = steel //array = array, //production = GetComponentDataFromEntity<ProduceComponent>(true), }; // return(job.Schedule(this, inputDependencies)); }
public bool TryGetSeed(ProduceComponent comp, [NotNullWhen(true)] out SeedData?seed) { if (comp.Seed != null) { seed = comp.Seed; return(true); } if (comp.SeedId != null && _prototypeManager.TryIndex(comp.SeedId, out SeedPrototype? protoSeed)) { seed = protoSeed; return(true); } seed = null; return(false); }