void Update()
    {
        // Send a Raycast from particle system's source transform forward
        RaycastHit hit;

        if (Physics.Raycast(particles.sourceTransform.position, particles.sourceTransform.forward, out hit, laserMaxDistance, collisionLayer))
        {
            // Set overflow offset z to hit distance (divide by particle count which by default is 1000)
            particles.overflowOffset.z = Vector3.Distance(particles.sourceTransform.position, hit.point) / (1 + particles.particleCount);
        }
        else
        {
            // Render laser to laserMaxDistance on clear sight
            particles.overflowOffset.z = laserMaxDistance / (1 + particles.particleCount);
        }

        // Update the amount of particles if particleCount changes
        if (particleCount != previousParticleCount)
        {
            PlaygroundC.SetParticleCount(particles, particleCount);
            previousParticleCount = particleCount;
        }

        // Update the lifetimeColor if laserColor changes
        if (laserColor != particles.lifetimeColor)
        {
            particles.lifetimeColor = laserColor;
        }
    }
Exemple #2
0
 // Use this for initialization
 void Start()
 {
     PlaygroundC.SetParticleCount(GetComponent <PlaygroundParticlesC> (), NumParticles);
 }
    public static void RenderPlaygroundSettings()
    {
        if (boxStyle == null)
        {
            boxStyle = GUI.skin.FindStyle("box");
        }
        EditorGUILayout.BeginVertical(boxStyle);

        playgroundFoldout = GUILayout.Toggle(playgroundFoldout, "Playground Manager", EditorStyles.foldout);
        if (playgroundFoldout)
        {
            EditorGUILayout.BeginVertical(boxStyle);
            if (playgroundScriptReference == null)
            {
                playgroundScriptReference = GameObject.FindObjectOfType <PlaygroundC>();
                if (playgroundScriptReference)
                {
                    Initialize(playgroundScriptReference);
                }
            }

            if (playgroundFoldout && playgroundScriptReference != null)
            {
                playground.Update();

                // Particle System List
                if (GUILayout.Button("Particle Systems (" + playgroundScriptReference.particleSystems.Count + ")", EditorStyles.toolbarDropDown))
                {
                    particleSystemsFoldout = !particleSystemsFoldout;
                }
                if (particleSystemsFoldout)
                {
                    EditorGUILayout.Separator();

                    if (playgroundScriptReference.particleSystems.Count > 0)
                    {
                        for (int ps = 0; ps < playgroundScriptReference.particleSystems.Count; ps++)
                        {
                            EditorGUILayout.BeginVertical(boxStyle, GUILayout.MinHeight(26));
                            EditorGUILayout.BeginHorizontal();

                            if (playgroundScriptReference.particleSystems[ps].particleSystemGameObject == Selection.activeGameObject)
                            {
                                GUILayout.BeginHorizontal(boxStyle);
                            }

                            GUILayout.Label(ps.ToString(), EditorStyles.miniLabel, new GUILayoutOption[] { GUILayout.Width(18) });
                            if (GUILayout.Button(playgroundScriptReference.particleSystems[ps].particleSystemGameObject.name, EditorStyles.label))
                            {
                                Selection.activeGameObject = playgroundScriptReference.particleSystems[ps].particleSystemGameObject;
                            }
                            EditorGUILayout.Separator();
                            GUI.enabled = (playgroundScriptReference.particleSystems.Count > 1);
                            if (GUILayout.Button("U", EditorStyles.toolbarButton, new GUILayoutOption[] { GUILayout.Width(18), GUILayout.Height(16) }))
                            {
                                particleSystems.MoveArrayElement(ps, ps == 0?playgroundScriptReference.particleSystems.Count - 1:ps - 1);
                            }
                            if (GUILayout.Button("D", EditorStyles.toolbarButton, new GUILayoutOption[] { GUILayout.Width(18), GUILayout.Height(16) }))
                            {
                                particleSystems.MoveArrayElement(ps, ps < playgroundScriptReference.particleSystems.Count - 1?ps + 1:0);
                            }
                            GUI.enabled = true;

                            // Clone
                            if (GUILayout.Button("+", EditorStyles.toolbarButton, new GUILayoutOption[] { GUILayout.Width(18), GUILayout.Height(16) }))
                            {
                                GameObject           ppsDuplicateGo = Instantiate(playgroundScriptReference.particleSystems[ps].particleSystemGameObject, playgroundScriptReference.particleSystems[ps].particleSystemTransform.position, playgroundScriptReference.particleSystems[ps].particleSystemTransform.rotation) as GameObject;
                                PlaygroundParticlesC ppsDuplicate   = ppsDuplicateGo.GetComponent <PlaygroundParticlesC>();

                                // Cache state data
                                for (int x = 0; x < ppsDuplicate.states.Count; x++)
                                {
                                    ppsDuplicate.states[x].Initialize();
                                }

                                // Set particle count to initiate all arrays
                                PlaygroundC.SetParticleCount(ppsDuplicate, ppsDuplicate.particleCount);

                                // Add this to Manager
                                if (PlaygroundC.reference != null)
                                {
                                    PlaygroundC.particlesQuantity++;
                                    PlaygroundC.reference.particleSystems.Add(ppsDuplicate);
                                    ppsDuplicate.particleSystemId = PlaygroundC.particlesQuantity;
                                    if (PlaygroundC.reference.autoGroup && ppsDuplicate.particleSystemTransform.parent == null)
                                    {
                                        ppsDuplicate.particleSystemTransform.parent = PlaygroundC.referenceTransform;
                                    }
                                }
                            }
                            if (GUILayout.Button("-", EditorStyles.toolbarButton, new GUILayoutOption[] { GUILayout.Width(18), GUILayout.Height(16) }))
                            {
                                if (EditorUtility.DisplayDialog(
                                        "Remove " + playgroundScriptReference.particleSystems[ps].particleSystemGameObject.name + "?",
                                        "Are you sure you want to remove this Particle Playground System?",
                                        "Yes", "No"))
                                {
                                    if (Selection.activeGameObject == playgroundScriptReference.particleSystems[ps].particleSystemGameObject)
                                    {
                                        Selection.activeGameObject = PlaygroundC.referenceTransform.gameObject;
                                    }
                                    PlaygroundC.Destroy(playgroundScriptReference.particleSystems[ps]);
                                    playground.ApplyModifiedProperties();
                                    return;
                                }
                            }

                            if (playgroundScriptReference.particleSystems[ps].particleSystemGameObject == Selection.activeGameObject)
                            {
                                GUILayout.EndHorizontal();
                            }
                            EditorGUILayout.EndHorizontal();
                            EditorGUILayout.EndVertical();
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("No particle systems created.", MessageType.Info);
                    }

                    if (GUILayout.Button("Create", EditorStyles.toolbarButton, GUILayout.Width(50)))
                    {
                        PlaygroundParticlesC createdParticles = PlaygroundC.Particle();
                        Selection.activeGameObject = createdParticles.particleSystemGameObject;
                    }

                    EditorGUILayout.Separator();
                }

                // Manipulators
                if (GUILayout.Button("Global Manipulators (" + playgroundScriptReference.manipulators.Count + ")", EditorStyles.toolbarDropDown))
                {
                    manipulatorsFoldout = !manipulatorsFoldout;
                }
                if (manipulatorsFoldout)
                {
                    EditorGUILayout.Separator();

                    if (manipulators.arraySize > 0)
                    {
                        for (int i = 0; i < manipulators.arraySize; i++)
                        {
                            string mName;
                            if (playgroundScriptReference.manipulators[i].transform)
                            {
                                mName = playgroundScriptReference.manipulators[i].transform.name;
                                if (mName.Length > 24)
                                {
                                    mName = mName.Substring(0, 24) + "...";
                                }
                            }
                            else
                            {
                                mName = "(Missing Transform!)";
                            }

                            EditorGUILayout.BeginVertical(boxStyle);

                            EditorGUILayout.BeginHorizontal();

                            GUILayout.Label(i.ToString(), EditorStyles.miniLabel, GUILayout.Width(18));
                            manipulatorListFoldout[i] = GUILayout.Toggle(manipulatorListFoldout[i], ManipulatorTypeName(playgroundScriptReference.manipulators[i].type), EditorStyles.foldout, GUILayout.Width(Screen.width / 4));
                            if (playgroundScriptReference.manipulators[i].transform)
                            {
                                if (GUILayout.Button(" (" + mName + ")", EditorStyles.label))
                                {
                                    Selection.activeGameObject = playgroundScriptReference.manipulators[i].transform.gameObject;
                                }
                            }
                            else
                            {
                                GUILayout.Button(ManipulatorTypeName(playgroundScriptReference.manipulators[i].type) + " (Missing Transform!)", EditorStyles.label);
                            }
                            EditorGUILayout.Separator();
                            GUI.enabled = (playgroundScriptReference.manipulators.Count > 1);
                            if (GUILayout.Button("U", EditorStyles.toolbarButton, new GUILayoutOption[] { GUILayout.Width(18), GUILayout.Height(16) }))
                            {
                                manipulators.MoveArrayElement(i, i == 0?playgroundScriptReference.manipulators.Count - 1:i - 1);
                            }
                            if (GUILayout.Button("D", EditorStyles.toolbarButton, new GUILayoutOption[] { GUILayout.Width(18), GUILayout.Height(16) }))
                            {
                                manipulators.MoveArrayElement(i, i < playgroundScriptReference.manipulators.Count - 1?i + 1:0);
                            }
                            GUI.enabled = true;
                            if (GUILayout.Button("+", EditorStyles.toolbarButton, new GUILayoutOption[] { GUILayout.Width(18), GUILayout.Height(16) }))
                            {
                                PlaygroundC.reference.manipulators.Add(playgroundScriptReference.manipulators[i].Clone());
                                manipulatorListFoldout.Add(manipulatorListFoldout[i]);
                            }
                            if (GUILayout.Button("-", EditorStyles.toolbarButton, new GUILayoutOption[] { GUILayout.Width(18), GUILayout.Height(16) }))
                            {
                                if (EditorUtility.DisplayDialog(
                                        "Remove " + ManipulatorTypeName(playgroundScriptReference.manipulators[i].type) + " Manipulator " + i + "?",
                                        "Are you sure you want to remove the Manipulator assigned to " + mName + "? (GameObject in Scene will remain intact)",
                                        "Yes", "No"))
                                {
                                    manipulators.DeleteArrayElementAtIndex(i);
                                    manipulatorListFoldout.RemoveAt(i);
                                    playground.ApplyModifiedProperties();
                                    return;
                                }
                            }

                            EditorGUILayout.EndHorizontal();

                            if (manipulatorListFoldout[i] && i < manipulators.arraySize)
                            {
                                RenderManipulatorSettings(playgroundScriptReference.manipulators[i], manipulators.GetArrayElementAtIndex(i), true);
                            }
                            GUI.enabled = true;
                            EditorGUILayout.Separator();
                            EditorGUILayout.EndVertical();
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("No manipulators created.", MessageType.Info);
                    }

                    if (GUILayout.Button("Create", EditorStyles.toolbarButton, GUILayout.Width(50)))
                    {
                        if (Selection.gameObjects.Length > 0 && Selection.activeGameObject.transform && Selection.activeTransform != null)
                        {
                            PlaygroundC.ManipulatorObject(Selection.activeGameObject.transform);
                        }
                        else
                        {
                            manipulators.InsertArrayElementAtIndex(manipulators.arraySize);
                        }
                        manipulatorListFoldout.Add(true);
                        SceneView.RepaintAll();
                    }


                    EditorGUILayout.Separator();
                }

                // Advanced Settings
                if (GUILayout.Button("Advanced", EditorStyles.toolbarDropDown))
                {
                    advancedSettingsFoldout = !advancedSettingsFoldout;
                }
                if (advancedSettingsFoldout)
                {
                    EditorGUILayout.Separator();
                    EditorGUILayout.PropertyField(calculate, new GUIContent("Calculate Particles", "Calculate forces on PlaygroundParticles objects. Disabling this overrides independently set values and halts all PlaygroundParticles objects."));
                    EditorGUILayout.PropertyField(garbageCollectOnResize, new GUIContent("Garbage Collection", "Issue a GC.Collect when resizing particle lists."));
                    EditorGUILayout.PropertyField(autoGroup, new GUIContent("Group Automatically", "Automatically parent a PlaygroundParticles object to Playground Manager if it has no parent."));
                    EditorGUILayout.PropertyField(buildZeroAlphaPixels, new GUIContent("Build Zero Alpha Pixels", "Turn this on if you want to build particles from 0 alpha pixels into states."));
                    EditorGUILayout.PropertyField(drawGizmos, new GUIContent("Scene Gizmos", "Show gizmos in Scene View for Playground objects."));
                    EditorGUILayout.PropertyField(paintToolbox, new GUIContent("Paint Toolbox", "Show Paint toolbox in Scene View when Source is set to Paint"));
                    EditorGUILayout.PropertyField(showShuriken, new GUIContent("Show Shuriken", "Show the Shuriken component in Inspector."));
                    EditorGUILayout.PropertyField(pixelFilterMode, new GUIContent("Pixel Filter Mode", "Color filtering mode when creating particles from pixels in an image."));
                    EditorGUILayout.Separator();

                    // Time reset
                    GUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel("Time Simulation");
                    if (GUILayout.Button("Reset", EditorStyles.toolbarButton, GUILayout.Width(50)))
                    {
                        PlaygroundC.TimeReset();
                        for (int p = 0; p < playgroundScriptReference.particleSystems.Count; p++)
                        {
                            playgroundScriptReference.particleSystems[p].Start();
                        }
                    }
                    GUILayout.EndHorizontal();

                    EditorGUILayout.Separator();

                    // Limits
                    EditorGUILayout.BeginVertical(boxStyle);
                    limitsFoldout = GUILayout.Toggle(limitsFoldout, "Editor Limits", EditorStyles.foldout);
                    if (limitsFoldout)
                    {
                        EditorGUILayout.Separator();
                        playgroundScriptReference.maximumAllowedTransitionTime = EditorGUILayout.FloatField("Transition Time", playgroundScriptReference.maximumAllowedTransitionTime);
                        EditorGUILayout.Separator();
                        playgroundScriptReference.maximumAllowedParticles     = EditorGUILayout.IntField("Particle Count", playgroundScriptReference.maximumAllowedParticles);
                        playgroundScriptReference.maximumAllowedLifetime      = EditorGUILayout.FloatField("Particle Lifetime", playgroundScriptReference.maximumAllowedLifetime);
                        playgroundScriptReference.maximumAllowedRotation      = EditorGUILayout.FloatField("Particle Rotation", playgroundScriptReference.maximumAllowedRotation);
                        playgroundScriptReference.maximumAllowedSize          = EditorGUILayout.FloatField("Particle Size", playgroundScriptReference.maximumAllowedSize);
                        playgroundScriptReference.maximumAllowedScale         = EditorGUILayout.FloatField("Particle Scale", playgroundScriptReference.maximumAllowedScale);
                        playgroundScriptReference.maximumAllowedSourceScatter = EditorGUILayout.FloatField("Source Scatter", playgroundScriptReference.maximumAllowedSourceScatter);
                        EditorGUILayout.Separator();
                        playgroundScriptReference.maximumAllowedDeltaMovementStrength = EditorGUILayout.FloatField("Delta Movement Strength", playgroundScriptReference.maximumAllowedDeltaMovementStrength);
                        playgroundScriptReference.maximumAllowedDamping         = EditorGUILayout.FloatField("Damping", playgroundScriptReference.maximumAllowedDamping);
                        playgroundScriptReference.maximumAllowedInitialVelocity = EditorGUILayout.FloatField("Initial Velocity", playgroundScriptReference.maximumAllowedInitialVelocity);
                        playgroundScriptReference.maximumAllowedVelocity        = EditorGUILayout.FloatField("Velocity", playgroundScriptReference.maximumAllowedVelocity);
                        EditorGUILayout.Separator();
                        playgroundScriptReference.maximumAllowedCollisionRadius = EditorGUILayout.FloatField("Collision Radius", playgroundScriptReference.maximumAllowedCollisionRadius);
                        playgroundScriptReference.maximumAllowedMass            = EditorGUILayout.FloatField("Mass", playgroundScriptReference.maximumAllowedMass);
                        playgroundScriptReference.maximumAllowedBounciness      = EditorGUILayout.FloatField("Bounciness", playgroundScriptReference.maximumAllowedBounciness);
                        EditorGUILayout.Separator();
                        playgroundScriptReference.minimumAllowedUpdateRate = EditorGUILayout.IntField("Update Rate", playgroundScriptReference.minimumAllowedUpdateRate);
                        playgroundScriptReference.maximumRenderSliders     = EditorGUILayout.FloatField("Render Sliders", playgroundScriptReference.maximumRenderSliders);
                        EditorGUILayout.Separator();
                        playgroundScriptReference.maximumAllowedPaintPositions = EditorGUILayout.IntField("Paint Positions", playgroundScriptReference.maximumAllowedPaintPositions);
                        playgroundScriptReference.minimumAllowedBrushScale     = EditorGUILayout.FloatField("Brush Size Min", playgroundScriptReference.minimumAllowedBrushScale);
                        playgroundScriptReference.maximumAllowedBrushScale     = EditorGUILayout.FloatField("Brush Size Max", playgroundScriptReference.maximumAllowedBrushScale);
                        playgroundScriptReference.minimumEraserRadius          = EditorGUILayout.FloatField("Eraser Size Min", playgroundScriptReference.minimumEraserRadius);
                        playgroundScriptReference.maximumEraserRadius          = EditorGUILayout.FloatField("Eraser Size Max", playgroundScriptReference.maximumEraserRadius);
                        playgroundScriptReference.maximumAllowedPaintSpacing   = EditorGUILayout.FloatField("Paint Spacing", playgroundScriptReference.maximumAllowedPaintSpacing);
                        EditorGUILayout.Separator();
                        playgroundScriptReference.maximumAllowedManipulatorSize         = EditorGUILayout.FloatField("Manipulator Size", playgroundScriptReference.maximumAllowedManipulatorSize);
                        playgroundScriptReference.maximumAllowedManipulatorStrength     = EditorGUILayout.FloatField("Manipulator Strength", playgroundScriptReference.maximumAllowedManipulatorStrength);
                        playgroundScriptReference.maximumAllowedManipulatorZeroVelocity = EditorGUILayout.FloatField("Zero Velocity Strength", playgroundScriptReference.maximumAllowedManipulatorZeroVelocity);
                        EditorGUILayout.Separator();
                    }
                    EditorGUILayout.EndVertical();
                }

                EditorGUI.indentLevel--;

                playground.ApplyModifiedProperties();
                EditorGUILayout.EndVertical();
            }
            else
            {
                EditorGUILayout.HelpBox("The Playground Manager runs all Particle Playground Systems in the scene, you need to create one in your scene to get started.", MessageType.Info);
                if (GUILayout.Button("Create", EditorStyles.toolbarButton, GUILayout.Width(50)))
                {
                    PlaygroundC.ResourceInstantiate("Playground Manager");
                }
                EditorGUILayout.EndVertical();
            }
        }
        EditorGUILayout.EndVertical();
    }