Ejemplo n.º 1
0
    public PlaygroundParticlesC particles;      // Set the Particle Playground System through Inspector

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            particles.Emit(!particles.emit);
        }
    }
    IEnumerator Emit()
    {
        float emissionRate = 0;
        int   emitted      = 0;

        while (emitted < particles.particleCount)
        {
            emissionRate += (particles.particleCount / seconds) * (Time.deltaTime);
            int r = Mathf.RoundToInt(emissionRate);
            if (r > 0)
            {
                if (emitted + r >= particles.particleCount)
                {
                    r = (particles.particleCount - emitted);
                }
                particles.Emit(
                    r,
                    position,
                    minVelocity,
                    maxVelocity,
                    color
                    );
                emitted     += r;
                emissionRate = 0;
            }
            yield return(null);
        }
    }
        public IEnumerator StartDelayedEmission()
        {
            particles.particleSystemGameObject.SetActive(false);
            yield return(new WaitForSeconds(startTime));

            particles.Emit(true);
        }
Ejemplo n.º 4
0
 protected override void DoStart()
 {
     core.onDamaged += (float value) => {
         var minVelocity = damageParticle.initialLocalVelocityMin;
         var maxVelocity = damageParticle.initialLocalVelocityMax;
         damageParticle.Emit(emitParticlesPerDamaged, transform.position, minVelocity, maxVelocity, Color.white);
     };
 }
Ejemplo n.º 5
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown("space"))
     {
         Debug.Log("space");
         m_particles.Emit(true);
     }
 }
Ejemplo n.º 6
0
 void Update()
 {
     // As an example, emit when pressing left mouse-button.
     // This version of Emit () processes random velocities within range set by you. Initial Velocity Shape will apply when available.
     if (Input.GetMouseButtonDown(0))
     {
         particles.Emit(amount, position, minimumVelocity, maximumVelocity, color);
     }
 }
Ejemplo n.º 7
0
    void Update()
    {
        // Ensure particle system is ready before we use it
        if (!particles.IsReady())
        {
            return;
        }

        // Emit
        _emitTimer += Time.deltaTime / emitTime;
        if (_emitTimer >= 1f)
        {
            // Emit onto the initial position of the spline
            Vector3 emitPos = spline.GetPoint(0);
            particles.Emit(emitPos, Vector3.zero, color);
            _emitTimer = 0;
        }

        // Ensure correct length of scatter positions (upon changing particle count)
        if (applyPositionScatter && particles.particleCount != _scatterPosition.Length)
        {
            GenerateScatter();
        }

        // Position
        for (int i = 0; i < particles.particleCount; i++)
        {
            // If Playground Cache is resized while in here we need to exit the loop
            if (applyPositionScatter && particles.playgroundCache.simulate.Length != _scatterPosition.Length)
            {
                break;
            }

            // Check if the particle is simulating
            if (particles.playgroundCache.simulate[i])
            {
                // Normalize the time for the particle
                float t = Mathf.Min(particles.playgroundCache.life[i] / (particles.lifetime - particles.playgroundCache.lifetimeSubtraction[i]), .99f);

                // Create a position on the spline along with the generated scattering
                Vector3 pos = spline.GetPoint(t);
                if (applyPositionScatter)
                {
                    pos += applyScatterLifetimeMultiplier? _scatterPosition[i] * positionScatterLifetimeMultiplier.Evaluate(t) : _scatterPosition[i];
                }

                // Set the position of the particle
                particles.ParticlePosition(i, pos);
            }
        }
    }
Ejemplo n.º 8
0
    void ShootParabola()
    {
        for (int i = 0; i < particles.particleCount; i++)
        {
            float   movePercentage = (i * 1f) / (particles.particleCount * 1f);
            Vector3 currentPos     = Vector3.Lerp(startPosition, endPosition, movePercentage);

            currentPos.x += bending.x * Mathf.Sin(Mathf.Clamp01(movePercentage) * Mathf.PI);
            currentPos.y += bending.y * Mathf.Sin(Mathf.Clamp01(movePercentage) * Mathf.PI);
            currentPos.z += bending.z * Mathf.Sin(Mathf.Clamp01(movePercentage) * Mathf.PI);

            particles.Emit(currentPos, Vector3.zero, Color.white);
        }
    }
Ejemplo n.º 9
0
 // Update is called once per frame
 void Update()
 {
     for (int y = 0; y < Height; y++)
     {
         for (int x = 0; x < Width; x++)
         {
             if (WebCamManager.checkActivePixel(x, y))
             {
                 Vector3 pos = new Vector3((x - Width / 2), (y - Height / 2), 0) + transform.position;
                 Particle.Emit(pos);
             }
         }
     }
 }
    IEnumerator Pop()
    {
        /* A manipulator using events will contain a list of all its particles in form of List<ManipulatorParticle>
         * where each item has a particle system id and a particle id.
         * When using manipulator.GetParticles() the list will be converted into List<PlaygroundEventParticle> and
         * contain detailed information about each particle currently inside its shape.
         */

        // Get the list of particles inside the manipulator
        List <PlaygroundEventParticle> manipulatorParticles = manipulator.GetParticles();

        // Work through the list and emit popParticles and popTurbulenceParticles
        foreach (PlaygroundEventParticle particle in manipulatorParticles)
        {
            popParticles.Emit(particle.position, particle.velocity, particle.color);
            for (int i = 0; i < 5; i++)
            {
                popTurbulenceParticles.Emit(particle.position, particle.velocity + RandomV3(), particle.color);
            }
        }

        // Kill all tracked particles within the Manipulator
        manipulator.KillAllParticles();

        // This part is just for the gui text
        if (manipulatorParticles.Count > 0)
        {
            if (manipulatorParticles.Count > highestPop)
            {
                popTextColor.a = 1f;
                popText.color  = popTextColor;
                highestPop     = manipulatorParticles.Count;
                popText.text   = highestPop.ToString();
                Vector2 pixelOffset = mainCamera.WorldToScreenPoint(manipulatorTransform.position);
                pixelOffset.y      += 50;
                popText.pixelOffset = pixelOffset;

                int highestNow = highestPop;
                while (popTextColor.a > 0 && highestNow == highestPop)
                {
                    popTextColor.a -= .5f * Time.deltaTime;
                    popText.color   = popTextColor;
                    yield return(null);
                }
            }
        }
    }
Ejemplo n.º 11
0
 void Update()
 {
     // Emit on left-click
     if (Input.GetMouseButtonDown(0))
     {
         Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit, 1000f))
         {
             particles.Emit(
                 hit.point,
                 velocity,
                 color
                 );
         }
     }
 }
Ejemplo n.º 12
0
    IEnumerator Start()
    {
        PlaygroundParticlesC particles = GetComponent <PlaygroundParticlesC>();

        while (!particles.IsReady())
        {
            yield return(null);
        }

        Vector3 position = particles.particleSystemTransform.position;

        for (int i = 0; i < particles.particleCount; i++)
        {
            float   iCircle   = 360f * ((i * 1f) / (particles.particleCount * 1f));
            Vector3 direction = new Vector3(Mathf.Cos(Mathf.Deg2Rad * iCircle) * width, Mathf.Sin(Mathf.Deg2Rad * iCircle) * height, 0);
            particles.Emit(position, direction * velocity, color);
        }
    }
    IEnumerator EmitOverAllVertices()
    {
        while (true)
        {
            yield return(new WaitForSeconds(emitRepeatTime));

            swo.BoneUpdate();
            swo.UpdateOnNewThread();
            while (!swo.isDoneThread)
            {
                yield return(null);
            }
            for (int i = 0; i < swo.vertexPositions.Length; i += vertexStep)
            {
                particles.Emit(swo.vertexPositions[i], particleVelocity, particleColor);
            }
        }
    }
Ejemplo n.º 14
0
    void Update()
    {
        if (Time.time > lastTimeUpdated + emissionRate)
        {
            // Iterate through each transform
            foreach (Transform t in transforms)
            {
                particles.Emit(
                    emissionAmount,
                    t.position + randomPositionMin,
                    t.position + randomPositionMax,
                    randomVelocityMin,
                    randomVelocityMax,
                    color
                    );
            }

            lastTimeUpdated = Time.time;
        }
    }
    public void Game_Event(string event_name)
    {
        switch (event_name)
        {
        case "hover start":
            StartCoroutine(Text_Wait());
            break;

        case "hover play":
            m_text_hover.Play();
            m_text_hover.GetComponent <AudioSource>().Play();
            m_text_onetimer.Play();
            break;

        case "hover stop":
            m_text_hover.Stop();
            m_text_hover.GetComponent <AudioSource>().Stop();
            break;

        case "onetimer":
            m_text_onetimer.Play();
            break;

        case "onetimer small":
            m_text_onetimer_small.Play();
            break;

        case "goal":
            m_goal.Emit(true);
            break;

        case "summary record":
            //include particles
            break;

        case "summary record stop":
            //stop particles
            break;
        }
    }
Ejemplo n.º 16
0
 /// <summary>
 /// Emit when particle system is moving.
 /// </summary>
 void EmissionMoveCheck()
 {
     if (movingTransform.position != previousPosition)
     {
         float emissionStepper = 0;
         float deltaDistance   = Vector3.Distance(previousPosition, movingTransform.position);
         if (deltaDistance < minSpace)
         {
             return;
         }
         Vector3 delta    = previousPosition;
         Vector3 velocity = Vector3.zero;
         Color   color    = Color.white;
         while (emissionStepper < deltaDistance)
         {
             delta = Vector3.Lerp(previousPosition, movingTransform.position, emissionStepper / deltaDistance);
             particles.Emit(delta, velocity, color);
             emissionStepper += minSpace;
         }
     }
     previousPosition = movingTransform.position;
 }
Ejemplo n.º 17
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButton(0))
     {
         Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit, 1000f))
         {
             particles.Emit(
                 Mathf.RoundToInt(4000 * Time.deltaTime),
                 hit.point - new Vector3(.2f, .2f, .2f),
                 hit.point + new Vector3(.2f, .2f, .2f),
                 new Vector3(-1f, -1f, -1f),
                 new Vector3(1f, 1f, 1f),
                 Color.white
                 );
             if (controlTransform != null)
             {
                 controlTransform.position = hit.point;
             }
         }
     }
 }
    void Update()
    {
        if (!_ready || !particles.IsReady() || particles.particleCount < 2)
        {
            return;
        }

        // Generate new interpolation positions if needed
        if (_spiralInterpolations.Length != particles.particleCount ||
            _startPos != start.position ||
            _endPos != end.position ||
            !Mathf.Approximately(_i, swirlIterations) ||
            !Mathf.Approximately(_r, radius))
        {
            GenerateSpiralInterpolations();
        }

        for (int i = 0; i < particles.particleCount; i++)
        {
            // If particles cache is resized in the middle of execution we need to exit the loop
            if (_spiralInterpolations.Length != particles.playgroundCache.simulate.Length)
            {
                break;
            }

            // Emit or position particles to the calculated spiral position
            if (!particles.playgroundCache.simulate[i])
            {
                particles.Emit(_spiralInterpolations[i]);
            }
            else
            {
                particles.ParticlePosition(i, _spiralInterpolations[i]);
            }
        }
    }
	// Set emission on/off
	public static void Emit (PlaygroundParticlesC playgroundParticles, bool setEmission) {
		playgroundParticles.Emit(setEmission);
	}
	// Emit next particle while setting scriptedEmission data - using the particle system as a pool. Returns emitted particle number.
	public static int Emit (PlaygroundParticlesC playgroundParticles, Vector3 position, Vector3 normal, Color color, Transform parent) {
		return playgroundParticles.Emit(position,normal,color,parent);
	}
Ejemplo n.º 21
0
    /// <summary>
    /// Load next effect while transitioning.
    /// </summary>
    IEnumerator NextEffect(int increment)
    {
        if (!canLoadNext)
        {
            yield break;
        }
        isSimulating = true;
        inTransition = true;
        canLoadNext  = false;

        pressSpaceText.SetActive(false);

        // Internally used variables
        bool  canContinue = looping || !looping && currentIndex < particleFx.Count - 1;
        float startTime;

        // Store current particle system's values before we change them
        int  previousIndex = currentIndex;
        bool previousOnlySourcePositioning   = previousIndex >= 0?particleFx[previousIndex].particles.onlySourcePositioning:false;
        bool previousOnlyLifetimePositioning = previousIndex >= 0?particleFx[previousIndex].particles.onlyLifetimePositioning:false;
        bool previousTransitionBackToSource  = previousIndex >= 0?particleFx[previousIndex].particles.transitionBackToSource:false;

        // Make Lifetime Positioning unable to set new positions (this makes particles behave like a target manipulator has affected them)
        if (previousOnlyLifetimePositioning)
        {
            for (int p = 0; p < particleFx[previousIndex].particles.particleCount; p++)
            {
                particleFx[previousIndex].particles.playgroundCache.changedByPropertyTarget[p] = true;
            }
        }

        // Prepare current (previous) particle system for transition
        if (previousIndex >= 0)
        {
            particleFx[previousIndex].particles.emit = false;
            particleFx[previousIndex].particles.onlySourcePositioning   = false;
            particleFx[previousIndex].particles.onlyLifetimePositioning = false;
            particleFx[previousIndex].particles.transitionBackToSource  = false;
            particleFx[previousIndex].particles.particleMaskTime        = transitionTime * .75f;
            particleFx[previousIndex].particles.particleMask            = particleFx[previousIndex].particles.particleCount;
            particleFx[previousIndex].particles.applyParticleMask       = true;
        }

        if (canContinue)
        {
            if (!isSelfRunning)
            {
                particleBlastSound.clip  = particleBlastClips[UnityEngine.Random.Range(0, particleBlastClips.Length)];
                particleBlastSound.pitch = UnityEngine.Random.Range(.9f, 1.1f);
                particleBlastSound.Play();
            }
            currentIndex = (currentIndex + increment) % particleFx.Count;
            if (currentIndex < 0)
            {
                currentIndex = particleFx.Count - 1;
            }

            // Scene transition fx
            StartCoroutine(NextSkyboxColor());
            nextParticleFx.Emit(true);
            nextParticleSmokeFx.Emit(true);
            repellentManipulator.enabled = true;

            // Camera push back
            yield return(new WaitForSeconds(.05f));

            startTime = Time.time;
            while (Time.time < startTime + (transitionTime / 2f))
            {
                cameraPushBack = Mathf.Lerp(cameraPushBack, cameraPushBackForce, (Time.time - startTime) / (transitionTime / 2f));
                yield return(null);
            }

            // Prepare new (next) particle system for transition
            particleFx[currentIndex].particles.particleMaskTime  = 0;
            particleFx[currentIndex].particles.particleMask      = particleFx[currentIndex].particles.particleCount;
            particleFx[currentIndex].particles.applyParticleMask = true;
            yield return(null);

            repellentManipulator.enabled = false;
            if (particleFx[currentIndex].moveInOut)
            {
                particleFx[currentIndex].particles.particleSystemTransform.position = new Vector3(0, -20f, 0);
            }
            particleFx[currentIndex].particles.Emit(true);
            while (!particleFx[currentIndex].particles.IsReady())
            {
                yield return(null);
            }
            for (int p = 0; p < particleFx[currentIndex].particles.particleCount; p++)
            {
                particleFx[currentIndex].particles.playgroundCache.maskAlpha[p] = 0f;
                particleFx[currentIndex].particles.playgroundCache.isMasked[p]  = true;
            }
            yield return(null);

            particleFx[currentIndex].particles.particleMaskTime = transitionTime / 2f;
            particleFx[currentIndex].particles.particleMask     = 0;

            nextParticleFx.Emit(false);
            nextParticleSmokeFx.Emit(false);

            inTransition = false;

            // Move particle system in if needed
            if (particleFx[currentIndex].moveInOut)
            {
                startTime = Time.time;
                while (Time.time < startTime + (transitionTime / 2f))
                {
                    particleFx[currentIndex].particles.particleSystemTransform.position =
                        new Vector3(
                            0,
                            Mathf.Lerp(-20f, 0, Easing(2, (Time.time - startTime) / (transitionTime / 2f))),
                            0
                            );
                    yield return(null);
                }
                particleFx[currentIndex].particles.particleSystemTransform.position = Vector3.zero;
            }
        }

        // Wait around till all fx is ready, move previous particle system if needed
        startTime = Time.time;
        while (Time.time < startTime + transitionTime + .5f)
        {
            if (previousIndex >= 0 && particleFx[previousIndex].moveInOut)
            {
                particleFx[previousIndex].particles.particleSystemTransform.position =
                    new Vector3(
                        0,
                        Mathf.Lerp(0, 20f, Easing(1, (Time.time - startTime) / (transitionTime / 2f))),
                        0
                        );
            }
            yield return(null);
        }

        // Restore previous particle system (for when it returns in the fx cycle)
        if (previousIndex >= 0 && canContinue)
        {
            yield return(null);

            particleFx[previousIndex].particles.onlySourcePositioning   = previousOnlySourcePositioning;
            particleFx[previousIndex].particles.onlyLifetimePositioning = previousOnlyLifetimePositioning;
            particleFx[previousIndex].particles.transitionBackToSource  = previousTransitionBackToSource;
            particleFx[previousIndex].particles.particleSystemGameObject.SetActive(false);
        }

        if (canContinue)
        {
            canLoadNext = true;
        }
        else
        {
            StartCoroutine(FadeOut());
        }
    }
    void OnTrailPoint(PlaygroundEventTrailPoint trailPoint)
    {
        Vector3 position = trailPoint.position;

        particles.Emit(position, velocity, color);
    }
Ejemplo n.º 23
0
    IEnumerator Shoot()
    {
        // Set variables
        float rotationSpeed = 360f / numberOfParticles;
        float timeDone;

        // Set particle count to match the amount needed
        particles.particleCount = numberOfParticles * cycles;

        // Wait before emission starts (if applicable)
        if (yieldBeforeEmission > 0)
        {
            timeDone = PlaygroundC.globalTime + yieldBeforeEmission;
            while (PlaygroundC.globalTime < timeDone)
            {
                yield return(null);
            }
        }

        // Loop through every cycle (c) and particle (p)
        for (int c = 0; c < cycles; c++)
        {
            for (int p = 0; p < numberOfParticles; p++)
            {
                // Emit a particle in rotated direction
                particles.Emit(thisTransform.position, thisTransform.right * force, color);

                // Rotate towards direction
                thisTransform.Rotate(rotationNormal * rotationSpeed);

                // Wait for next emission (if applicable)
                if (yieldBetweenShots > 0)
                {
                    timeDone = PlaygroundC.globalTime + yieldBetweenShots;
                    while (PlaygroundC.globalTime < timeDone)
                    {
                        yield return(null);
                    }
                }
            }

            // Wait for next cycle (if applicable)
            if (yieldBetweenCycles > 0)
            {
                timeDone = PlaygroundC.globalTime + yieldBetweenCycles;
                while (PlaygroundC.globalTime < timeDone)
                {
                    yield return(null);
                }
            }
        }

        // Return if not in Play Mode in Editor
                #if UNITY_EDITOR
        if (!UnityEditor.EditorApplication.isPlaying)
        {
            yield break;
        }
                #endif

        // Wait for action when last particle's lifetime is over
        switch (whenDone)
        {
        case WhenDoneCircleShot.Inactivate:
            yield return(new WaitForSeconds(particles.lifetime));

            gameObject.SetActive(false);
            break;

        case WhenDoneCircleShot.Destroy:
            yield return(new WaitForSeconds(particles.lifetime));

            Destroy(gameObject);
            break;
        }
    }
	// Emit next particle - using the particle system as a pool (note that you need to set scriptedEmission-variables on beforehand). Returns emitted particle number.
	public static int Emit (PlaygroundParticlesC playgroundParticles) {
		return playgroundParticles.Emit(playgroundParticles.scriptedEmissionPosition,playgroundParticles.scriptedEmissionVelocity,playgroundParticles.scriptedEmissionColor,playgroundParticles.scriptedEmissionParent);
	}