void Start() { int maxBuoys = 5; //max limit available bool tooCloseToOthers = SoundBuoyScript.CloseToOthers(gameObject, 100.0f); if (!tooCloseToOthers) { tooCloseToOthers = BlackHoleScript.CloseToOthers(gameObject, 100.0f); } if (WorldBuoysList.Count >= maxBuoys || tooCloseToOthers) { DestroyImmediate(gameObject); return; } buoyAnimations[0] = "appear"; buoyAnimations[1] = "moving"; buoyAnimations[2] = "drop"; buoyAnimations[3] = "ringing"; buoyAnimations[4] = "ding"; buoyAnimations[5] = "sink"; buoyAnimations[6] = "underwater"; sprite.animationCompleteDelegate += AnimationComplete; WorldBuoysList.Add(this); fluidField = GameObject.FindGameObjectWithTag("fluidField").GetComponent <FluidFieldGenerator>(); audio.clip = ringingSounds[WorldBuoysList.IndexOf(this)]; audio.loop = true; audio.volume = 0.0f; audio.Play(); }
void FixedUpdate() { if(fluidField == null) { fluidField = GameObject.Find("fluid field").GetComponent<FluidFieldGenerator>(); } else { if(shrinkAndDissapear) { Vector3 curScale = transform.localScale * 0.9f; float curmag = Mathf.Sqrt((curScale.x*curScale.x)+(curScale.y*curScale.y)); if(curmag < 0.1f) Network.Destroy(gameObject); else transform.localScale = curScale; } else { fluidField.UpdateBasedOnBlackHole(this); RotationSpeed = Mathf.Min(1000, RotationSpeed); this.transform.Rotate(Vector3.forward, Time.deltaTime * Mathf.Max(50, RotationSpeed)); if(RotationSpeed < 0.0f) shrinkAndDissapear = true; } spewRotation = RotationSpeed * Time.deltaTime * 5.0f; spewingDirection = Quaternion.AngleAxis(spewRotation, Vector3.forward) * spewingDirection; } }
public FluidUpdateWorker(FluidFieldGenerator f, float visc, float dt, int chnkX, int chnkY, int idxx, int idxy, int NCOUNT) { fluid = f; viscoscity = visc; frame_dt = dt; chunkX = chnkX; chunkY = chnkY; startIdxX = idxx; startIdxY = idxy; NCount = NCOUNT; System.Threading.Interlocked.Increment(ref numberOfWorkers); }
void Start() { fluidField = GameObject.FindGameObjectWithTag("fluidField").GetComponent <FluidFieldGenerator>(); isPlayer1 = gameObject.tag == "PLAYER1"; if (Network.isClient && isPlayer1) { isLocalPlayer = false; } else if (Network.isServer && !isPlayer1) { isLocalPlayer = false; } if (!isLocalPlayer) { touchAnimations[0] = "fingerprintBeginAnim"; touchAnimations[1] = "fingerprintLoopAnim"; touchAnimations[2] = "fingerprintEndAnim"; //set custom scale for the fingahprint touchAnim.scale = new Vector3(150, 150, 150); } else { touchAnimations[0] = "touchBeginAnim"; touchAnimations[1] = "touchLoopAnim"; touchAnimations[2] = "touchEndAnim"; //set scale for the regular glowball touchAnim.scale = new Vector3(200, 200, 200); } touchAnim.animationCompleteDelegate += AnimationComplete; DontDestroyOnLoad(this); }
void FixedUpdate() { if (fluidField == null) { fluidField = GameObject.Find("fluid field").GetComponent <FluidFieldGenerator>(); } else { if (shrinkAndDissapear) { Vector3 curScale = transform.localScale * 0.9f; float curmag = Mathf.Sqrt((curScale.x * curScale.x) + (curScale.y * curScale.y)); if (curmag < 0.1f) { Network.Destroy(gameObject); } else { transform.localScale = curScale; } } else { fluidField.UpdateBasedOnBlackHole(this); RotationSpeed = Mathf.Min(1000, RotationSpeed); this.transform.Rotate(Vector3.forward, Time.deltaTime * Mathf.Max(50, RotationSpeed)); if (RotationSpeed < 0.0f) { shrinkAndDissapear = true; } } spewRotation = RotationSpeed * Time.deltaTime * 5.0f; spewingDirection = Quaternion.AngleAxis(spewRotation, Vector3.forward) * spewingDirection; } }
void Start() { fluidField = GameObject.FindGameObjectWithTag("fluidField").GetComponent<FluidFieldGenerator>(); isPlayer1 = gameObject.tag == "PLAYER1"; if(Network.isClient && isPlayer1) isLocalPlayer = false; else if(Network.isServer && !isPlayer1) isLocalPlayer = false; if(!isLocalPlayer) { touchAnimations[0] = "fingerprintBeginAnim"; touchAnimations[1] = "fingerprintLoopAnim"; touchAnimations[2] = "fingerprintEndAnim"; //set custom scale for the fingahprint touchAnim.scale = new Vector3(150, 150, 150); } else { touchAnimations[0] = "touchBeginAnim"; touchAnimations[1] = "touchLoopAnim"; touchAnimations[2] = "touchEndAnim"; //set scale for the regular glowball touchAnim.scale = new Vector3(200, 200, 200); } touchAnim.animationCompleteDelegate += AnimationComplete; DontDestroyOnLoad(this); }
void Start() { int maxBuoys = 5; //max limit available bool tooCloseToOthers = SoundBuoyScript.CloseToOthers(gameObject, 100.0f); if(!tooCloseToOthers) tooCloseToOthers = BlackHoleScript.CloseToOthers(gameObject, 100.0f); if(WorldBuoysList.Count >= maxBuoys || tooCloseToOthers) { DestroyImmediate(gameObject); return; } buoyAnimations[0] = "appear"; buoyAnimations[1] = "moving"; buoyAnimations[2] = "drop"; buoyAnimations[3] = "ringing"; buoyAnimations[4] = "ding"; buoyAnimations[5] = "sink"; buoyAnimations[6] = "underwater"; sprite.animationCompleteDelegate += AnimationComplete; WorldBuoysList.Add(this); fluidField = GameObject.FindGameObjectWithTag("fluidField").GetComponent<FluidFieldGenerator>(); audio.clip = ringingSounds[WorldBuoysList.IndexOf(this)]; audio.loop = true; audio.volume = 0.0f; audio.Play(); }
public void BuildFieldVisualizerVertices(FluidFieldGenerator fluidField, int gridSize, int n, int bXIdx, int bYIdx, Vector2 gridAspectScale) { N = n; width = height = gridSize; arraySize = height*width; beginXIdx = bXIdx; beginYIdx = bYIdx; gameObject.transform.parent = fluidField.transform; gameObject.AddComponent(typeof(MeshFilter)); gameObject.AddComponent("MeshRenderer"); renderer.material = fluidField.material; Mesh mesh = GetComponent<MeshFilter>().mesh; vertPositions = new Vector3[arraySize]; vertColors = new Color32[arraySize]; uvs = new Vector2[arraySize]; float screenWidth = fluidField.camcam.GetScreenWidth()-1; float screenHeight = fluidField.camcam.GetScreenHeight()-1; float screenWidthPerBlockX = screenWidth * gridAspectScale.x; float screenWidthPerBlockY = screenHeight * gridAspectScale.y; float initialXPosition = (beginXIdx / (float)(N) / gridAspectScale.x) * screenWidthPerBlockX; float initialYPosition = (beginYIdx / (float)(N) / gridAspectScale.y) * screenWidthPerBlockY; initialXPosition -= screenWidth * 0.5f; initialYPosition -= screenHeight * 0.5f; float cellWidth = screenWidthPerBlockX / (float)(width-1); float cellHeight = screenWidthPerBlockY / (float)(height-1); System.Random rand = new System.Random(); for (int y=0;y<height;y++) { for (int x=0;x<width;x++) { float xpos = initialXPosition + (x*cellWidth); float ypos = initialYPosition + (y*cellHeight); Vector3 vertPos = new Vector3(xpos, ypos, 0); int idx = y*width+x; vertPositions[idx] = vertPos; uvs[idx] = new Vector2 ( (float)x/(float)width, (float)y / (float)height); vertColors[idx] = new Color32(255, 255, 255, 255); //float randomX = (float)rand.NextDouble() * particleGridOffsets; //float randomY = (float)rand.NextDouble() * particleGridOffsets; //particles[idx].position = new Vector3(vertPositions[idx].x+randomX, vertPositions[idx].y+randomY, vertPositions[idx].z-10); //particles[idx].color = new Color32(173, 194, 72, 32); //particles[idx].lifetime = 10000.0f; //particles[idx].startLifetime = 0.0f; } } mesh.vertices = vertPositions; mesh.colors32 = vertColors; mesh.uv = uvs; //indices int[] triangles = new int[(height - 1) * (width - 1) * 6]; int index = 0; for (int y = 0; y < height-1; ++y) { for (int x = 0; x < width-1; ++x) { // For each grid cell output two triangles triangles[index++] = (y * width) + x; triangles[index++] = ((y+1) * width) + x; triangles[index++] = (y * width) + x + 1; triangles[index++] = ((y+1) * width) + x; triangles[index++] = ((y+1) * width) + x + 1; triangles[index++] = (y * width) + x + 1; } } mesh.triangles = triangles; //mesh.RecalculateNormals(); mesh.Optimize(); }
public void UpdateLookBasedOnFluid(FluidFieldGenerator fluidField, float N, float vertDivsX, float vertDivsY, Color fluidColor, Color inkColor) { if(fluidTexture == null || (int)N != fluidTexture.width) { fluidTexture = new Texture2D((int)N, (int)N, TextureFormat.ARGB32, false); this.renderer.material.mainTexture = fluidTexture; } float sw = width-1; float sh = height-1; float sadColorRating = fluidField.amountOfSadness*0.5f; float happyColorRating = fluidField.amountOfHappiness*0.5f; float angryColorRating = fluidField.amountOfAngriness*0.5f; for (int y = 0; y < height; ++y) { float yperc = (float)y / sh; float fycord = beginYIdx + ((yperc * N) / vertDivsY); int colorIdx = y*width; for (int x = 0; x < width; ++x) { float xperc = (float)x / sw; float fxcord = beginXIdx + ((xperc * N) / vertDivsX); float vval = Math.Abs (fluidField.SampleField(fluidField.u, fxcord, fycord)); vval += Math.Abs(fluidField.SampleField(fluidField.v, fxcord, fycord)); vval *= 512.0f; float dval = fluidField.SampleField(fluidField.densityField, fxcord, fycord) * 5; float fr = vval * fluidColor.r; float fg = vval * fluidColor.g; float fb = vval * fluidColor.b; float ir = dval * inkColor.r; float ig = dval * inkColor.g; float ib = dval * inkColor.b; byte vertColorR = (byte)Math.Min(255, (fr+ir)); byte vertColorG = (byte)Math.Min(255, (fg+ig)); byte vertColorB = (byte)Math.Min(255, (fb+ib)); int vidx = colorIdx + x; vertColors[vidx].r = vertColorR; vertColors[vidx].g = vertColorG; vertColors[vidx].b = vertColorB; vertColors[vidx].a = 255; //vertPositions[vidx].z = vertColorR; } } Mesh mesh = GetComponent<MeshFilter>().mesh; mesh.colors32 = vertColors; fluidTexture.filterMode = FilterMode.Trilinear; fluidTexture.mipMapBias = -0.5f; fluidTexture.SetPixels32(vertColors); fluidTexture.Apply(false); //mesh.vertices = vertPositions; //mesh.RecalculateNormals(); }
public void UpdateLookBasedOnFluid(FluidFieldGenerator fluidField, float N, float vertDivsX, float vertDivsY, Color fluidColor, Color inkColor) { if (fluidTexture == null || (int)N != fluidTexture.width) { fluidTexture = new Texture2D((int)N, (int)N, TextureFormat.ARGB32, false); this.renderer.material.mainTexture = fluidTexture; } float sw = width - 1; float sh = height - 1; float sadColorRating = fluidField.amountOfSadness * 0.5f; float happyColorRating = fluidField.amountOfHappiness * 0.5f; float angryColorRating = fluidField.amountOfAngriness * 0.5f; for (int y = 0; y < height; ++y) { float yperc = (float)y / sh; float fycord = beginYIdx + ((yperc * N) / vertDivsY); int colorIdx = y * width; for (int x = 0; x < width; ++x) { float xperc = (float)x / sw; float fxcord = beginXIdx + ((xperc * N) / vertDivsX); float vval = Math.Abs(fluidField.SampleField(fluidField.u, fxcord, fycord)); vval += Math.Abs(fluidField.SampleField(fluidField.v, fxcord, fycord)); vval *= 512.0f; float dval = fluidField.SampleField(fluidField.densityField, fxcord, fycord) * 5; float fr = vval * fluidColor.r; float fg = vval * fluidColor.g; float fb = vval * fluidColor.b; float ir = dval * inkColor.r; float ig = dval * inkColor.g; float ib = dval * inkColor.b; byte vertColorR = (byte)Math.Min(255, (fr + ir)); byte vertColorG = (byte)Math.Min(255, (fg + ig)); byte vertColorB = (byte)Math.Min(255, (fb + ib)); int vidx = colorIdx + x; vertColors[vidx].r = vertColorR; vertColors[vidx].g = vertColorG; vertColors[vidx].b = vertColorB; vertColors[vidx].a = 255; //vertPositions[vidx].z = vertColorR; } } Mesh mesh = GetComponent <MeshFilter>().mesh; mesh.colors32 = vertColors; fluidTexture.filterMode = FilterMode.Trilinear; fluidTexture.mipMapBias = -0.5f; fluidTexture.SetPixels32(vertColors); fluidTexture.Apply(false); //mesh.vertices = vertPositions; //mesh.RecalculateNormals(); }
public void BuildFieldVisualizerVertices(FluidFieldGenerator fluidField, int gridSize, int n, int bXIdx, int bYIdx, Vector2 gridAspectScale) { N = n; width = height = gridSize; arraySize = height * width; beginXIdx = bXIdx; beginYIdx = bYIdx; gameObject.transform.parent = fluidField.transform; gameObject.AddComponent(typeof(MeshFilter)); gameObject.AddComponent("MeshRenderer"); renderer.material = fluidField.material; Mesh mesh = GetComponent <MeshFilter>().mesh; vertPositions = new Vector3[arraySize]; vertColors = new Color32[arraySize]; uvs = new Vector2[arraySize]; float screenWidth = fluidField.camcam.GetScreenWidth() - 1; float screenHeight = fluidField.camcam.GetScreenHeight() - 1; float screenWidthPerBlockX = screenWidth * gridAspectScale.x; float screenWidthPerBlockY = screenHeight * gridAspectScale.y; float initialXPosition = (beginXIdx / (float)(N) / gridAspectScale.x) * screenWidthPerBlockX; float initialYPosition = (beginYIdx / (float)(N) / gridAspectScale.y) * screenWidthPerBlockY; initialXPosition -= screenWidth * 0.5f; initialYPosition -= screenHeight * 0.5f; float cellWidth = screenWidthPerBlockX / (float)(width - 1); float cellHeight = screenWidthPerBlockY / (float)(height - 1); System.Random rand = new System.Random(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float xpos = initialXPosition + (x * cellWidth); float ypos = initialYPosition + (y * cellHeight); Vector3 vertPos = new Vector3(xpos, ypos, 0); int idx = y * width + x; vertPositions[idx] = vertPos; uvs[idx] = new Vector2((float)x / (float)width, (float)y / (float)height); vertColors[idx] = new Color32(255, 255, 255, 255); //float randomX = (float)rand.NextDouble() * particleGridOffsets; //float randomY = (float)rand.NextDouble() * particleGridOffsets; //particles[idx].position = new Vector3(vertPositions[idx].x+randomX, vertPositions[idx].y+randomY, vertPositions[idx].z-10); //particles[idx].color = new Color32(173, 194, 72, 32); //particles[idx].lifetime = 10000.0f; //particles[idx].startLifetime = 0.0f; } } mesh.vertices = vertPositions; mesh.colors32 = vertColors; mesh.uv = uvs; //indices int[] triangles = new int[(height - 1) * (width - 1) * 6]; int index = 0; for (int y = 0; y < height - 1; ++y) { for (int x = 0; x < width - 1; ++x) { // For each grid cell output two triangles triangles[index++] = (y * width) + x; triangles[index++] = ((y + 1) * width) + x; triangles[index++] = (y * width) + x + 1; triangles[index++] = ((y + 1) * width) + x; triangles[index++] = ((y + 1) * width) + x + 1; triangles[index++] = (y * width) + x + 1; } } mesh.triangles = triangles; //mesh.RecalculateNormals(); mesh.Optimize(); }