Ejemplo n.º 1
0
        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;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            NeutrinoRenderer renderer = (NeutrinoRenderer)target;

            Neutrino.Effect effect = renderer.neutrinoEffect();

            if (effect == null)
            {
                return;
            }

            GUILayout.BeginHorizontal();

            if (GUILayout.Button("Restart"))
            {
                renderer.reset();
            }

            bool paused = renderer.paused();

            if (GUILayout.Button(paused ? "Unpause" : "Pause"))
            {
                Undo.RecordObject(renderer, paused ? "Unpause particle effect" : "Pause particles effect");

                if (paused)
                {
                    renderer.unpause();
                }
                else
                {
                    renderer.pause();
                }
            }

            bool generatorsPaused = renderer.generatorsPaused();

            if (GUILayout.Button(generatorsPaused ? "Unpause generation" : "Pause generation"))
            {
                Undo.RecordObject(renderer, generatorsPaused ? "Unpause generation in particle effect" : "Pause generation in particles effect");

                if (generatorsPaused)
                {
                    renderer.unpauseGenerators();
                }
                else
                {
                    renderer.pauseGenerators();
                }
            }

            GUILayout.EndHorizontal();

            for (int emitterIndex = 0; emitterIndex < effect.numEmitters(); ++emitterIndex)
            {
                Neutrino.Emitter emitter = effect.emitter(emitterIndex);

                if (emitter.model().numProperties() == 0)
                {
                    continue;
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField(emitter.model().name());
                EditorGUI.indentLevel++;

                for (int propIndex = 0; propIndex < emitter.model().numProperties(); ++propIndex)
                {
                    string name = emitter.model().propertyName(propIndex);

                    switch (emitter.model().propertyType(propIndex))
                    {
                    case Neutrino.EmitterModel.PropertyType.FLOAT:
                    {
                        float valueBefore = (float)emitter.propertyValue(propIndex);
                        float valueAfter  = EditorGUILayout.FloatField(name, valueBefore);
                        emitter.setPropertyValue(propIndex, valueAfter);
                    }
                    break;

                    case Neutrino.EmitterModel.PropertyType.VEC2:
                    {
                        _math.vec2          valueBefore = (_math.vec2)emitter.propertyValue(propIndex);
                        UnityEngine.Vector2 valueAfter  = EditorGUILayout.Vector2Field(name,
                                                                                       new UnityEngine.Vector2(valueBefore.x, valueBefore.y));
                        emitter.setPropertyValue(propIndex, _math.vec2_(valueAfter.x, valueAfter.y));
                    }
                    break;

                    case Neutrino.EmitterModel.PropertyType.VEC3:
                    {
                        _math.vec3          valueBefore = (_math.vec3)emitter.propertyValue(propIndex);
                        UnityEngine.Vector3 valueAfter  = EditorGUILayout.Vector3Field(name,
                                                                                       new UnityEngine.Vector3(valueBefore.x, valueBefore.y, valueBefore.z));
                        emitter.setPropertyValue(propIndex, _math.vec3_(valueAfter.x, valueAfter.y, valueAfter.z));
                    }
                    break;

                    case Neutrino.EmitterModel.PropertyType.QUAT:
                        break;
                    }
                }

                EditorGUI.indentLevel--;
            }
        }
Ejemplo n.º 4
0
        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;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            NeutrinoRenderer renderer = (NeutrinoRenderer)target;

            Neutrino.Effect effect = renderer.neutrinoEffect();

            for (int emitterIndex = 0; emitterIndex < effect.numEmitters(); ++emitterIndex)
            {
                Neutrino.Emitter emitter = effect.emitter(emitterIndex);

                if (emitter.model().numProperties() == 0)
                {
                    continue;
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField(emitter.model().name());
                EditorGUI.indentLevel++;

                for (int propIndex = 0; propIndex < emitter.model().numProperties(); ++propIndex)
                {
                    string name = emitter.model().propertyName(propIndex);

                    switch (emitter.model().propertyType(propIndex))
                    {
                    case Neutrino.EmitterModel.PropertyType.FLOAT:
                    {
                        float valueBefore = (float)emitter.propertyValue(propIndex);
                        float valueAfter  = EditorGUILayout.FloatField(name, valueBefore);
                        emitter.setPropertyValue(propIndex, valueAfter);
                    }
                    break;

                    case Neutrino.EmitterModel.PropertyType.VEC2:
                    {
                        _math.vec2          valueBefore = (_math.vec2)emitter.propertyValue(propIndex);
                        UnityEngine.Vector2 valueAfter  = EditorGUILayout.Vector2Field(name,
                                                                                       new UnityEngine.Vector2(valueBefore.x, valueBefore.y));
                        emitter.setPropertyValue(propIndex, _math.vec2_(valueAfter.x, valueAfter.y));
                    }
                    break;

                    case Neutrino.EmitterModel.PropertyType.VEC3:
                    {
                        _math.vec3          valueBefore = (_math.vec3)emitter.propertyValue(propIndex);
                        UnityEngine.Vector3 valueAfter  = EditorGUILayout.Vector3Field(name,
                                                                                       new UnityEngine.Vector3(valueBefore.x, valueBefore.y, valueBefore.z));
                        emitter.setPropertyValue(propIndex, _math.vec3_(valueAfter.x, valueAfter.y, valueAfter.z));
                    }
                    break;

                    case Neutrino.EmitterModel.PropertyType.QUAT:
                        break;
                    }
                }

                EditorGUI.indentLevel--;
            }
        }