public void OnBeforeSerialize() { Neutrino.Effect effect = neutrinoEffect_; if (effect == null) { return; } serializableEffect_.emitters_.Clear(); for (int emitterIndex = 0; emitterIndex < effect.numEmitters(); ++emitterIndex) { Neutrino.Emitter emitter = effect.emitter(emitterIndex); var serialEmitter = new SerializableEmitter(); serialEmitter.name_ = emitter.model().name(); serialEmitter.paused_ = emitter.paused(); serialEmitter.generatorsPaused_ = emitter.generatorsPaused(); serializableEffect_.emitters_.Add(serialEmitter); for (int propIndex = 0; propIndex < emitter.model().numProperties(); ++propIndex) { var serialProp = new SerializableProperty(); serialProp.name_ = emitter.model().propertyName(propIndex); serialEmitter.properties_.Add(serialProp); switch (emitter.model().propertyType(propIndex)) { case Neutrino.EmitterModel.PropertyType.FLOAT: { float value = (float)emitter.propertyValue(propIndex); serialProp.value_.Add(value); } break; case Neutrino.EmitterModel.PropertyType.VEC2: { _math.vec2 value = (_math.vec2)emitter.propertyValue(propIndex); serialProp.value_.Add(value.x); serialProp.value_.Add(value.y); } break; case Neutrino.EmitterModel.PropertyType.VEC3: { _math.vec3 value = (_math.vec3)emitter.propertyValue(propIndex); serialProp.value_.Add(value.x); serialProp.value_.Add(value.y); serialProp.value_.Add(value.z); } break; case Neutrino.EmitterModel.PropertyType.QUAT: // none until inspector is ready for quaternions break; } } } }
public bool generatorsPaused() { if (neutrinoEffect_ == null || neutrinoEffectModel_ == null) { return(false); } for (int emitterIndex = 0; emitterIndex < neutrinoEffect_.numEmitters(); ++emitterIndex) { Neutrino.Emitter emitter = neutrinoEffect_.emitter(emitterIndex); if (!emitter.generatorsPaused()) { return(false); } } return(true); }
private void deserializeToEffect() { if (serializableEffect_ == null) { return; } Neutrino.Effect effect = neutrinoEffect_; for (int emitterIndex = 0; emitterIndex < serializableEffect_.emitters_.Count; ++emitterIndex) { var serialEmitter = serializableEffect_.emitters_[emitterIndex]; Neutrino.Emitter emitter = effect.emitter(serialEmitter.name_); if (emitter == null) { continue; } if (emitter.paused() != serialEmitter.paused_) { if (serialEmitter.paused_) { emitter.pause(); } else { emitter.unpause(); } } if (emitter.generatorsPaused() != serialEmitter.generatorsPaused_) { if (serialEmitter.generatorsPaused_) { emitter.pauseGenerators(); } else { emitter.unpauseGenerators(); } } for (int propIndex = 0; propIndex < serialEmitter.properties_.Count; ++propIndex) { var serialProp = serialEmitter.properties_[propIndex]; var propType = emitter.model().propertyType(serialProp.name_); if (propType == null) { continue; } switch (propType.Value) { case Neutrino.EmitterModel.PropertyType.FLOAT: { if (serialProp.value_.Count == 1) { emitter.setPropertyValue(serialProp.name_, serialProp.value_[0]); } } break; case Neutrino.EmitterModel.PropertyType.VEC2: { if (serialProp.value_.Count == 2) { emitter.setPropertyValue(serialProp.name_, _math.vec2_(serialProp.value_[0], serialProp.value_[1])); } } break; case Neutrino.EmitterModel.PropertyType.VEC3: { if (serialProp.value_.Count == 3) { emitter.setPropertyValue(serialProp.name_, _math.vec3_(serialProp.value_[0], serialProp.value_[1], serialProp.value_[2])); } } break; case Neutrino.EmitterModel.PropertyType.QUAT: // none until inspector is ready for quaternions break; } } } }