Пример #1
0
                // ...

                void OnGUI()
                {
                    // Get windows.

                    particlePlayback.updateEditorCameraWindowReferences();

                    // Looks nicer.

                    EditorGUILayout.Separator();

                    // Twister settings.

                    EditorGUILayout.LabelField("- Twister Settings:", EditorStyles.boldLabel);
                    EditorGUILayout.Separator();

                    EditorGUI.BeginChangeCheck();
                    {
                        guiContentLabel = new GUIContent("Scale", "Time scale: higher values == more curves / twists.");
                        particleTwisterEditorValues.scale = EditorGUILayout.Slider(guiContentLabel, particleTwisterEditorValues.scale, 1.0f, 100.0f);

                        guiContentLabel = new GUIContent("Velocity", "Velocity scale: higher values == faster particles.");
                        particleTwisterEditorValues.velocity = EditorGUILayout.Slider(guiContentLabel, particleTwisterEditorValues.velocity, 0.25f, 1000.0f);

                        guiContentLabel = new GUIContent("Resolution", "Keyframes used per axis. Higher values == smoother curves. 64 is a decent maximum.");
                        particleTwisterEditorValues.resolution = EditorGUILayout.IntSlider(guiContentLabel, particleTwisterEditorValues.resolution, 8, 1024);
                    }

                    // If any previous GUI elements were modified and set to auto-update, apply twister to all.

                    if (EditorGUI.EndChangeCheck())
                    {
                        if (particleTwisterEditorValues.autoUpdate)
                        {
                            applyTwisterToAll();
                        }
                    }

                    EditorGUILayout.Separator();

                    // Extension options.

                    EditorGUILayout.LabelField("- Twister Options:", EditorStyles.boldLabel);
                    EditorGUILayout.Separator();

                    guiContentLabel = new GUIContent("Auto-Update", "Update particles on setting changes.");
                    particleTwisterEditorValues.autoUpdate = EditorGUILayout.Toggle(guiContentLabel, particleTwisterEditorValues.autoUpdate);

                    guiContentLabel = new GUIContent("Auto Fast-Forward", "Simulate particles forward on updates.");
                    particleTwisterEditorValues.fastForwardOnApply = EditorGUILayout.Toggle(guiContentLabel, particleTwisterEditorValues.fastForwardOnApply);

                    EditorGUILayout.Separator();

                    guiContentLabel = new GUIContent("Fast-Forward Time (s)", "Time to simulate particles forward (in seconds).");
                    particleTwisterEditorValues.fastForwardTime = EditorGUILayout.Slider(guiContentLabel, particleTwisterEditorValues.fastForwardTime, 0.5f, 1024.0f);

                    EditorGUILayout.Separator();

                    guiContentLabel = new GUIContent("Invert", "Invert scale factor (reverse direction).");
                    particleTwisterEditorValues.invert = EditorGUILayout.Toggle(guiContentLabel, particleTwisterEditorValues.invert);

                    guiContentLabel = new GUIContent("Spiral", "Spiral velocity curve (else, circular).");
                    particleTwisterEditorValues.spiral = EditorGUILayout.Toggle(guiContentLabel, particleTwisterEditorValues.spiral);

                    EditorGUILayout.Separator();

                    // Buttons to apply.

                    EditorGUILayout.BeginHorizontal();
                    {
                        guiContentLabel = new GUIContent("Apply Twister",
                                                         "Apply twister settings to all ParticleSystem components in select GameObjects (copy values).");

                        if (GUILayout.Button(guiContentLabel, GUILayout.Height(applyTwisterButtonHeight)))
                        {
                            applyTwisterToAll();
                        }

                        guiContentLabel = new GUIContent("Fast-Forward",
                                                         "Simulate particles forward in time.");

                        if (GUILayout.Button(guiContentLabel, GUILayout.Height(applyTwisterButtonHeight)))
                        {
                            for (int i = 0; i < particleSystems.Count; i++)
                            {
                                simulateAndPlay(particleSystems[i]);
                            }
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    // Button for creating a new system.

                    guiContentLabel = new GUIContent("Create New",
                                                     "Create a new default ParticleSystem as a twister.");

                    if (GUILayout.Button(guiContentLabel, GUILayout.Height(applyTwisterButtonHeight)))
                    {
                        GameObject     gameObject     = new GameObject("Twister", typeof(ParticleSystem));
                        ParticleSystem particleSystem = gameObject.GetComponent <ParticleSystem>();

                        particleSystem.setNewParticleTwisterValues();

                        // particleSystem.applyTwister();

                        particleSystem.applyTwister(

                            particleTwisterEditorValues.spiral,
                            particleTwisterEditorValues.scale,
                            particleTwisterEditorValues.velocity,
                            particleTwisterEditorValues.resolution);

                        //simulateAndPlay(particleSystem);
                    }

                    // Button for resetting editor values.

                    guiContentLabel = new GUIContent("Reset Editor",
                                                     "Resets editor values to their original defaults.");

                    if (GUILayout.Button(guiContentLabel, GUILayout.Height(applyTwisterButtonHeight)))
                    {
                        particleTwisterEditorValues.reset();
                    }

                    EditorGUILayout.Separator();

                    // Playback settings.

                    particlePlayback.GUIPlaybackSettings(particleSystems);
                    EditorGUILayout.Separator();

                    // Selected objects.

                    particlePlayback.GUIParticleSelection(selectedGameObjectsWithParticleSystems);
                }
Пример #2
0
            // ...

            void OnGUI()
            {
                // Twister settings.

                EditorGUILayout.Separator();

                EditorGUILayout.LabelField("- Twister Settings:", EditorStyles.boldLabel);
                EditorGUILayout.Separator();

                content = new GUIContent("Scale", "Time scale: higher values == more curves / twists.");
                particleTwisterEditorValues.scale = EditorGUILayout.Slider(content, particleTwisterEditorValues.scale, 1.0f, 100.0f);

                content = new GUIContent("Velocity", "Velocity scale: higher values == faster particles.");
                particleTwisterEditorValues.velocity = EditorGUILayout.Slider(content, particleTwisterEditorValues.velocity, 0.25f, 1000.0f);

                content = new GUIContent("Resolution", "Keyframes used per axis. Higher values == smoother curves. 64 is a decent maximum.");
                particleTwisterEditorValues.resolution = EditorGUILayout.IntSlider(content, particleTwisterEditorValues.resolution, 8, 1024);

                EditorGUILayout.Separator();

                // If any previous GUI elements were modified and set to auto-update, apply twister to all.

                if (particleTwisterEditorValues.autoUpdate)
                {
                    if (GUI.changed)
                    {
                        applyTwisterToAll();
                    }
                }

                // Extension options.

                EditorGUILayout.LabelField("- Options:", EditorStyles.boldLabel);
                EditorGUILayout.Separator();

                content = new GUIContent("Auto-Update", "Update particles on setting changes.");
                particleTwisterEditorValues.autoUpdate = EditorGUILayout.Toggle(content, particleTwisterEditorValues.autoUpdate);

                content = new GUIContent("Auto Fast-Forward", "Simulate particles forward on updates.");
                particleTwisterEditorValues.fastForwardOnApply = EditorGUILayout.Toggle(content, particleTwisterEditorValues.fastForwardOnApply);

                EditorGUILayout.Separator();

                content = new GUIContent("Fast-Forward Time (s)", "Time to simulate particles forward (in seconds).");
                particleTwisterEditorValues.fastForwardTime = EditorGUILayout.Slider(content, particleTwisterEditorValues.fastForwardTime, 0.5f, 1024.0f);

                EditorGUILayout.Separator();

                content = new GUIContent("Invert", "Invert scale factor (reverse direction).");
                particleTwisterEditorValues.invert = EditorGUILayout.Toggle(content, particleTwisterEditorValues.invert);

                EditorGUILayout.Separator();

                // Buttons to apply.

                EditorGUILayout.BeginHorizontal();
                {
                    content = new GUIContent("Apply Twister",
                                             "Apply twister settings to all ParticleSystem components in select GameObjects (copy values).");

                    if (GUILayout.Button(content))
                    {
                        applyTwisterToAll();
                    }

                    content = new GUIContent("Fast-Forward",
                                             "Simulate particles forward in time.");

                    if (GUILayout.Button(content))
                    {
                        for (int i = 0; i < particleSystems.Count; i++)
                        {
                            simulateAndPlay(particleSystems[i]);
                        }
                    }
                } EditorGUILayout.EndHorizontal();

                // Button for creating a new system.

                content = new GUIContent("Create New",
                                         "Create a new default ParticleSystem as a twister.");

                if (GUILayout.Button(content))
                {
                    GameObject     gameObject     = new GameObject("Twister", typeof(ParticleSystem));
                    ParticleSystem particleSystem = gameObject.GetComponent <ParticleSystem>();

                    particleSystem.setNewParticleTwisterValues();

                    // particleSystem.applyTwister();

                    particleSystem.applyTwister(

                        particleTwisterEditorValues.scale,
                        particleTwisterEditorValues.velocity,
                        particleTwisterEditorValues.resolution);

                    //simulateAndPlay(particleSystem);
                }

                // Button for resetting editor values.

                content = new GUIContent("Reset Editor",
                                         "Resets editor values to their original defaults.");

                if (GUILayout.Button(content))
                {
                    particleTwisterEditorValues.reset();
                }

                EditorGUILayout.Separator();

                // Selected objects.

                content = new GUIContent("- Selected:",
                                         "Selected GameObjects must be active and contain at least one active ParticleSystem component in their hierarchy.");

                EditorGUILayout.LabelField(content, EditorStyles.boldLabel);
                EditorGUILayout.Separator();

                scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
                {
                    if (selectedGameObjects.Count == 0)
                    {
                        EditorGUILayout.LabelField("Please select GameObjects with at least one ParticleSystem component.", EditorStyles.miniBoldLabel);
                    }
                    else
                    {
                        for (int i = 0; i < selectedGameObjects.Count; i++)
                        {
                            EditorGUILayout.BeginHorizontal();
                            {
                                EditorGUILayout.LabelField(">   " + selectedGameObjects[i].name, EditorStyles.miniBoldLabel);
                            }

                            EditorGUILayout.EndHorizontal();
                        }
                    }
                }

                EditorGUILayout.EndScrollView();
            }