Example #1
0
    public void Update()
    {
        if (Pause.current && Pause.current.IsPaused)
        {
            return;
        }

        m_LineRenderer.SetColors(colorToEmit, colorToEmit);
        m_Particles.lifetimeColor = GetGradient(colorToEmit);

        // Find the screen limits to the emitter's movement.
        m_Min = Camera.main.ViewportToWorldPoint(new Vector2(0, 0));
        m_Max = Camera.main.ViewportToWorldPoint(new Vector2(1, 1));
        // Get the emitter's current position.
        m_Pos = transform.position;
        // Direction of the ray.
        Vector2 dir = Vector2.zero;
        Vector3 rot = Vector3.zero;

        // Update the location according to its orientation.
        switch (orient)
        {
        case Orientation.Horizontal:
            // Set 'Y' location when the screen changes its horizontal size.
            switch (locate)
            {
            case Location.Negative: m_Pos.y = m_Min.y + offset; dir = Vector2.up; rot = new Vector3(0, 0, 0); break;

            case Location.Positive: m_Pos.y = m_Max.y - offset; dir = Vector2.down; rot = new Vector3(0, 0, 180); break;
            }
            // Set 'X' location if is outside of the screen.
            if (m_Pos.x < m_Min.x)
            {
                m_Pos.x = m_Min.x + offset;
            }
            if (m_Pos.x > m_Max.x)
            {
                m_Pos.x = m_Max.x - offset;
            }
            break;

        case Orientation.Vertical:
            // Set 'X' location when the screen changes its vertical size.
            switch (locate)
            {
            case Location.Negative: m_Pos.x = m_Min.x + offset; dir = Vector2.right; rot = new Vector3(0, 0, -90); break;

            case Location.Positive: m_Pos.x = m_Max.x - offset; dir = Vector2.left; rot = new Vector3(0, 0, 90); break;
            }
            // Set 'Y' location if is outside of the screen.
            if (m_Pos.y < m_Min.y)
            {
                m_Pos.y = m_Min.y + offset;
            }
            if (m_Pos.y > m_Max.y)
            {
                m_Pos.y = m_Max.y - offset;
            }
            break;
        }
        // Update the emitter's position.
        transform.position = Vector3.Lerp(transform.position, m_Pos, 0.5f);
        m_Particles.transform.eulerAngles    = rot;
        m_LineRenderer.transform.eulerAngles = rot;

        // Ray
        RaycastHit2D hit = Physics2D.Raycast(transform.position, dir, laserDistance, WhatIsReceiver);

        if (hit)
        {
//			if (amount)
//				m_Particles.particleCount = Mathf.FloorToInt(Vector3.Distance(transform.position, hit.point) * m_Multiplier);
//			else
            // Set overflow offset y to hit distance (divide by particle count which by default is 1000)
            m_Particles.overflowOffset.y = Vector3.Distance(transform.position, hit.point) / m_Particles.particleCount;
//			m_Particles.lifetime = ((Vector3.Distance(transform.position, hit.point) / m_Particles.particleCount) * 60) * 0.5f;

            m_LineRenderer.SetPosition(1, new Vector3(0, hit.distance, 0));

            if (hit.collider.tag == "Receiver")
            {
                Receiver cacheReceiver = hit.collider.GetComponent <Receiver>();
                cacheReceiver.AddColor(colorToEmit);

                UpdateManipulator(cacheReceiver.transform.position, cacheReceiver.currentColor);
                EnableManipulator(true);
            }
            else if (hit.collider.tag == "Obstacle")
            {
                Transform cacheObstacle = hit.collider.transform;
                UpdateManipulator(cacheObstacle.position, colorToEmit);
                EnableManipulator(true);
            }
            else if (hit.collider.tag == "Pipeline")
            {
                PipeHead cachePipeHead = hit.collider.GetComponent <PipeHead>();
                cachePipeHead.Entry       = true;
                cachePipeHead.colorToEmit = colorToEmit;

                UpdateManipulator(cachePipeHead.transform.position, colorToEmit);
                EnableManipulator(true);
            }
        }
        else
        {
//			if (amount)
//				m_Particles.particleCount = Mathf.FloorToInt(laserDistance * m_Multiplier);
//			else
            // Render laser to laserMaxDistance on clear sight
            m_Particles.overflowOffset.y = laserDistance / m_Particles.particleCount;
//			m_Particles.lifetime = ((laserDistance / m_Particles.particleCount) * 60) * 0.5f;

            m_LineRenderer.SetPosition(1, new Vector3(0, laserDistance, 0));
            EnableManipulator(false);
        }
        Debug.DrawRay(transform.position, dir);
    }
Example #2
0
    private void TriggerRay(Vector3 pos, Vector2 dir, PlaygroundParticlesC particles, bool left, Color color)
    {
        RaycastHit2D hit = Physics2D.Raycast(pos, dir, laserDistance, WhatIsReceiver);

        if (hit)
        {
            particles.overflowOffset.y = Vector3.Distance(transform.position, hit.point) / particles.particleCount;

            if (left)
            {
                m_LineRendererLeft.SetPosition(1, new Vector3(0, hit.distance, 0));
            }
            else
            {
                m_LineRendererRight.SetPosition(1, new Vector3(0, hit.distance, 0));
            }

            if (receivedColors.Length > 1)
            {
                if (hit.collider.tag == "Receiver")
                {
                    Receiver cacheReceiver = hit.collider.GetComponent <Receiver>();
                    cacheReceiver.AddColor(color);

                    if (left)
                    {
                        UpdateManipulatorLeft(cacheReceiver.transform.position, cacheReceiver.currentColor);
                        EnableManipulatorLeft(true);
                    }
                    else
                    {
                        UpdateManipulatorRight(cacheReceiver.transform.position, cacheReceiver.currentColor);
                        EnableManipulatorRight(true);
                    }
                }
                else if (hit.collider.tag == "Obstacle")
                {
                    Transform cacheObstacle = hit.collider.transform;

                    if (left)
                    {
                        UpdateManipulatorLeft(cacheObstacle.position, color);
                        EnableManipulatorLeft(true);
                    }
                    else
                    {
                        UpdateManipulatorRight(cacheObstacle.position, color);
                        EnableManipulatorRight(true);
                    }
                }
                else if (hit.collider.tag == "Pipeline")
                {
                    PipeHead cachePipeHead = hit.collider.GetComponent <PipeHead>();
                    cachePipeHead.colorToEmit = color;
                    cachePipeHead.Entry       = true;

                    if (left)
                    {
                        UpdateManipulatorLeft(cachePipeHead.transform.position, color);
                        EnableManipulatorLeft(true);
                    }
                    else
                    {
                        UpdateManipulatorRight(cachePipeHead.transform.position, color);
                        EnableManipulatorRight(true);
                    }
                }
            }
        }
        else
        {
            particles.overflowOffset.y = laserDistance / particles.particleCount;

            if (left)
            {
                m_LineRendererLeft.SetPosition(1, new Vector3(0, hit.distance, 0));
                EnableManipulatorLeft(false);
            }
            else
            {
                m_LineRendererRight.SetPosition(1, new Vector3(0, hit.distance, 0));
                EnableManipulatorRight(false);
            }
        }
        Debug.DrawRay(pos, dir);
    }
Example #3
0
    public void ExitBehaviour()
    {
        m_Particles.lifetimeColor = GetGradientExit(colorToEmit);

        if (otherPipeHead.onActivated)
        {
            theSprite.color = Color.Lerp(theSprite.color, Color.white, 0.5f);

            m_LineRenderer.SetColors(colorToEmit, colorToEmit);
            m_Particles.emit = true;
        }
        else
        {
            Color nothing = new Color(0, 0, 0, 0);
//			theSprite.color = Color.Lerp(theSprite.color, nothing, 0.5f);

            m_LineRenderer.SetColors(nothing, nothing);
            m_Particles.emit = false;
        }

        // target - origin
        Vector2      dir = m_Raycast.position - transform.position;
        RaycastHit2D hit = Physics2D.Raycast(m_Raycast.position, dir, laserDistance, WhatIsReceiver);

        if (hit)
        {
//			if (amount)
//				m_Particles.particleCount = Mathf.FloorToInt(Vector3.Distance(transform.position, hit.point) * m_Multiplier);
//			else
            // Set overflow offset y to hit distance (divide by particle count which by default is 1000)
            m_Particles.overflowOffset.y = Vector3.Distance(transform.position, hit.point) / m_Particles.particleCount;
            m_LineRenderer.SetPosition(1, new Vector3(0, hit.distance, 0));

            if (otherPipeHead.onActivated /* && emit*/)
            {
                if (hit.collider.tag == "Receiver")
                {
                    Receiver cacheReceiver = hit.collider.GetComponent <Receiver>();
                    cacheReceiver.AddColor(colorToEmit);

                    UpdateManipulator(cacheReceiver.transform.position, cacheReceiver.currentColor);
                    EnableManipulator(true);
                }
                else if (hit.collider.tag == "Obstacle")
                {
                    Transform cacheObstacle = hit.collider.transform;
                    UpdateManipulator(cacheObstacle.position, colorToEmit);
                    EnableManipulator(true);
                }
                else if (hit.collider.tag == "Pipeline")
                {
                    PipeHead cachePipeHead = hit.collider.GetComponent <PipeHead>();
                    cachePipeHead.colorToEmit = colorToEmit;
                    cachePipeHead.Entry       = true;

                    UpdateManipulator(cachePipeHead.transform.position, colorToEmit);
                    EnableManipulator(true);
                }
            }
        }
        else
        {
//			if (amount)
//				m_Particles.particleCount = Mathf.FloorToInt(laserDistance * m_Multiplier);
//			else
            // Render laser to laserMaxDistance on clear sight
            m_Particles.overflowOffset.y = laserDistance / m_Particles.particleCount;
            m_LineRenderer.SetPosition(1, new Vector3(0, laserDistance, 0));
            EnableManipulator(false);
        }
        Debug.DrawRay(m_Raycast.position, dir, Color.magenta);

        otherPipeHead.Entry = false;
    }
Example #4
0
    public virtual void Update()
    {
        if (Pause.current && Pause.current.IsPaused)
        {
            return;
        }

        // Rotate
        if (m_bMouseOver)
        {
            if (Input.GetKey(KeyCode.Mouse0))
            {
                Rotate(Vector3.forward * speed);
            }
            else if (Input.GetKey(KeyCode.Mouse1))
            {
                Rotate(Vector3.forward * -speed);
            }
        }

        receivedColors = GetColors();
        currentColor   = CombineColors(receivedColors);

        m_PigmentCircle.color = Color.Lerp(m_PigmentCircle.color, currentColor, 0.5f * speedInking * Time.deltaTime);

        if (Compare(currentColor, colorToReceive))
        {
            m_Output.color      = Color.Lerp(m_Output.color, currentColor, 0.5f * speedInking * Time.deltaTime);
            m_PigmentRing.color = Color.Lerp(m_PigmentRing.color, currentColor, 0.5f * speedInking * Time.deltaTime);

            Color ccr = m_CromaticRing.color;
            ccr.a = 0f;
            m_CromaticRing.color = Color.Lerp(m_CromaticRing.color, ccr, 0.5f * speedInking * Time.deltaTime);

            ready = true;
        }
        else
        {
            if (!HintScript.showHint)
            {
                m_Output.color = Color.Lerp(m_Output.color, Color.white, 0.5f * speedInking * Time.deltaTime);

                Color cpr = m_PigmentRing.color;
                cpr.a = 0f;
                m_PigmentRing.color = Color.Lerp(m_PigmentRing.color, cpr, 0.5f * speedInking * Time.deltaTime);

                Color ccr = m_CromaticRing.color;
                ccr.a = 1f;
                m_CromaticRing.color = Color.Lerp(m_CromaticRing.color, ccr, 0.5f * speedInking * Time.deltaTime);
            }

            ready = false;
        }

        if (HintScript.showHint)
        {
            m_Output.color      = Color.Lerp(m_Output.color, colorToReceive, 0.5f * speedInking * Time.deltaTime);
            m_PigmentRing.color = Color.Lerp(m_PigmentRing.color, colorToReceive, 0.5f * speedInking * Time.deltaTime);

            Color ccr = m_CromaticRing.color;
            ccr.a = 0f;
            m_CromaticRing.color = Color.Lerp(m_CromaticRing.color, ccr, 0.5f * speedInking * Time.deltaTime);
        }

        // Ray
        Vector3 pos = m_Raycast.position;
        Vector2 dir = m_Raycast.position - transform.position;        //m_Raycast.position + rot * pos;

        RaycastHit2D hit = Physics2D.Raycast(pos, dir, laserDistance, WhatIsReceiver);

        if (hit)
        {
//			if (amount)
//				m_Particles.particleCount = Mathf.FloorToInt(Vector3.Distance(transform.position, hit.point) * m_Multiplier);
//			else
            // Set overflow offset y to hit distance (divide by particle count which by default is 1000)
            m_Particles.overflowOffset.y = Vector3.Distance(transform.position, hit.point) / m_Particles.particleCount;
            m_LineRenderer.SetPosition(1, new Vector3(0, hit.distance, 0));

            if (currentColor != new Color(0, 0, 0, 0))
            {
                if (hit.collider.tag == "Receiver")
                {
                    Receiver cacheReceiver = hit.collider.GetComponent <Receiver>();
                    cacheReceiver.AddColor(currentColor);

                    UpdateManipulator(cacheReceiver.transform.position, cacheReceiver.currentColor);
                    EnableManipulator(true);
                }
                else if (hit.collider.tag == "Obstacle")
                {
                    Transform cacheObstacle = hit.collider.transform;
                    UpdateManipulator(cacheObstacle.position, currentColor);
                    EnableManipulator(true);
                }
                else if (hit.collider.tag == "Pipeline")
                {
                    PipeHead cachePipeHead = hit.collider.GetComponent <PipeHead>();
                    cachePipeHead.colorToEmit = currentColor;
                    cachePipeHead.Entry       = true;

                    UpdateManipulator(cachePipeHead.transform.position, currentColor);
                    EnableManipulator(true);
                }
                else if (hit.collider.tag == "Prism")
                {
                    ColorSplitter cacheSplitter = hit.collider.GetComponent <ColorSplitter>();
                    if (receivedColors.Length > 1)
                    {
                        cacheSplitter.AddColors(receivedColors);
                    }

                    UpdateManipulator(cacheSplitter.transform.position, currentColor);
                    EnableManipulator(true);
                }
            }
        }
        else
        {
//			if (amount)
//				m_Particles.particleCount = Mathf.FloorToInt(laserDistance * m_Multiplier);
//			else
            // Render laser to laserMaxDistance on clear sight
            m_Particles.overflowOffset.y = laserDistance / m_Particles.particleCount;
            m_LineRenderer.SetPosition(1, new Vector3(0, laserDistance, 0));
            EnableManipulator(false);
        }
        Debug.DrawRay(pos, dir);

        m_LineRenderer.SetColors(currentColor, currentColor);
        m_Particles.lifetimeColor = GetGradient(currentColor);

        if (currentColor == new Color(0, 0, 0, 0))
        {
            m_Particles.emit = false;
        }
        else
        {
            m_Particles.emit = true;
        }

        // Sparkle
        if (m_ColorStack.Count > m_count && !m_ParticleRing.isPlaying)
        {
//			m_ParticleRing.emit = true;
            m_ParticleRing.Play();
            m_SoundSource.Play();
        }

//		if (m_ColorStack.Count == m_count)
//			m_ParticleRing.emit = false;

        m_count = receivedColors.Length;

        RotateParticles();
    }