void CreateGrid() { float x_offset = 0; float y_offset = 0; if (centered) { x_offset = -width / 2f; y_offset = -height / 2f; } int numSegmentsPerRow = (int)(width / maxVertexDistance) + (width % maxVertexDistance > 0 ? 1 : 0); int numPointsPerRow = numSegmentsPerRow + 1; for (int r = 0; r < rows; r++) { GameObject lineObj = new GameObject(); LineHandler lineHandler = lineObj.AddComponent <LineHandler>(); lineHandler.name = "Row " + r; float y = height / (rows - 1) * r; Vector3[] points = new Vector3[numPointsPerRow]; for (int i = 0; i < numPointsPerRow; i++) { float x = i * width / numSegmentsPerRow; points[i] = new Vector3(x + x_offset, y + y_offset, 0); } lineHandler.SetPoints(points); ColorSplitter splitter = lineHandler.gameObject.AddComponent <ColorSplitter>(); splitter.Split(); } int numSegmentsPerCol = (int)(height / maxVertexDistance) + (height % maxVertexDistance > 0 ? 1: 0); int numPointsPerCol = numSegmentsPerCol + 1; for (int c = 0; c < cols; c++) { GameObject lineObj = new GameObject(); LineHandler lineHandler = lineObj.AddComponent <LineHandler>(); lineHandler.name = "Col " + c; float x = width / (cols - 1) * c; Vector3[] points = new Vector3[numPointsPerCol]; for (int i = 0; i < numPointsPerCol; i++) { float y = i * height / numSegmentsPerCol; points[i] = new Vector3(x + x_offset, y + y_offset, 0); } lineHandler.SetPoints(points); ColorSplitter splitter = lineHandler.gameObject.AddComponent <ColorSplitter>(); splitter.Split(); } }
GameObject CreateFragment(Color color, int layer, string name) { GameObject fragment = GameObject.Instantiate(this.gameObject); Renderer rend = fragment.GetComponent <Renderer>(); if (rend != null) { rend.material.color = color; } fragment.name = fragment.name + " " + name; fragment.layer = layer; ColorSplitter splitter = fragment.GetComponent <ColorSplitter>(); splitter.enabled = false; return(fragment); }
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(); }