public void SpawnDefaultBatteries(GameObject constructedObject, List <InteractiveChildObjectIdentifier> childIdentifiers) { Optional <EnergyMixin> opEnergy = Optional.OfNullable(constructedObject.GetComponent <EnergyMixin>()); if (opEnergy.HasValue) { EnergyMixin mixin = opEnergy.Value; mixin.ReflectionSet("allowedToPlaySounds", false); mixin.SetBattery(mixin.defaultBattery, 1); mixin.ReflectionSet("allowedToPlaySounds", true); } foreach (InteractiveChildObjectIdentifier identifier in childIdentifiers) { Optional <GameObject> opChildGameObject = NitroxEntity.GetObjectFrom(identifier.Id); if (opChildGameObject.HasValue) { Optional <EnergyMixin> opEnergyMixin = Optional.OfNullable(opChildGameObject.Value.GetComponent <EnergyMixin>()); if (opEnergyMixin.HasValue) { EnergyMixin mixin = opEnergyMixin.Value; mixin.ReflectionSet("allowedToPlaySounds", false); mixin.SetBattery(mixin.defaultBattery, 1); mixin.ReflectionSet("allowedToPlaySounds", true); } } } }
// As the normal spawn is suppressed, spawn default batteries afterwards private void SpawnDefaultBatteries(GameObject constructedObject, List <InteractiveChildObjectIdentifier> childIdentifiers) { Optional <EnergyMixin> opEnergy = Optional <EnergyMixin> .OfNullable(constructedObject.GetComponent <EnergyMixin>()); if (opEnergy.IsPresent()) { EnergyMixin mixin = opEnergy.Get(); mixin.ReflectionSet("allowedToPlaySounds", false); mixin.SetBattery(mixin.defaultBattery, 1); mixin.ReflectionSet("allowedToPlaySounds", true); } foreach (InteractiveChildObjectIdentifier identifier in childIdentifiers) { Optional <GameObject> opChildGameObject = GuidHelper.GetObjectFrom(identifier.Guid); if (opChildGameObject.IsPresent()) { opChildGameObject.Get().AddComponent <NitroxEntity>(); Optional <EnergyMixin> opEnergyMixin = Optional <EnergyMixin> .OfNullable(opChildGameObject.Get().GetComponent <EnergyMixin>()); if (opEnergyMixin.IsPresent()) { EnergyMixin mixin = opEnergyMixin.Get(); mixin.ReflectionSet("allowedToPlaySounds", false); mixin.SetBattery(mixin.defaultBattery, 1); mixin.ReflectionSet("allowedToPlaySounds", true); } } } }