// Return color based on current weather type private Material getParticleTexture(WeatherManager.WeatherType t) { Material m = null; switch (t) { case WeatherManager.WeatherType.sun: { m = dandyMat; break; } case WeatherManager.WeatherType.rain: { m = rainMan; break; } case WeatherManager.WeatherType.snow: { m = snowMat; break; } } return(m); }
// Update is called once per frame void LateUpdate() { // Check if the global weather has changed and change the variable accordingly type = type != WeatherManager.Instance.type ? WeatherManager.Instance.type : type; globalParticleList.Clear(); instanceParticleList.Clear(); InitializeIfNeeded(ref globalParticleSystem, ref globalParticles); InitializeIfNeeded(ref instanceParticleSystem, ref instanceParticles); int globalNumParticles = globalParticleSystem.GetParticles(globalParticles); int instanceNumParticles = instanceParticleSystem.GetParticles(instanceParticles); globalParticleSystem.GetComponent <Renderer>().material = getParticleTexture(type); instanceParticleSystem.GetComponent <Renderer>().material = getParticleTexture(instType); for (int i = 0; i < globalNumParticles; i++) { checkParticle(ref globalParticles[i]); } for (int i = 0; i < instanceNumParticles; i++) { checkParticle(ref instanceParticles[i]); } globalParticleSystem.SetParticles(globalParticleList.ToArray(), globalParticleList.Count); instanceParticleSystem.SetParticles(instanceParticleList.ToArray(), instanceParticleList.Count); }
public static int getWeatherLayer(WeatherManager.WeatherType type) { int rVal; switch (type) { case WeatherManager.WeatherType.sun: rVal = 1 << LayerMask.NameToLayer("Sun"); break; case WeatherManager.WeatherType.rain: rVal = 1 << LayerMask.NameToLayer("Rain"); break; case WeatherManager.WeatherType.snow: rVal = 1 << LayerMask.NameToLayer("Snow"); break; default: rVal = 0; break; } return(rVal); }
private void Awake() { WeatherManager.Instance.weatherTileList.Add(this); type = WeatherManager.Instance.type; WeatherChange(type); if (type == WeatherManager.WeatherType.rain) { prevFrame = frames[0]; } else if (type == WeatherManager.WeatherType.snow) { prevFrame = frames[1]; } else { prevFrame = frames[(int)type]; } if (frames.Count == 0) { Debug.LogError(String.Format("TileAnimation on '{0}' has no frames.", this.name)); } else if (frames.Count < 2) { Debug.LogError(String.Format("TileAnimation on '{0}' has insufficient frames.", this.name)); } }
// Called from the WeatherManager to set the scale of the instance weather public void setInstanceZone(Rect _r, bool isRunning, int typeNum) { //x = _x; //width = _width; r = _r; instanceIsRunning = isRunning; instType = (WeatherManager.WeatherType)typeNum; }
void LateUpdate() { currentType = WeatherManager.Instance.type; if (type != currentType) { WeatherChange(currentType); type = currentType; } }
// Use this for initialization void Start() { edgeCount = Mathf.RoundToInt(width) * 5; nodeCount = edgeCount + 1; edgesPerTextureTile = (int)(textureWidth * 5); SpawnWater(); WeatherManager.Instance.lakeList.Add(this); prevType = (WeatherManager.WeatherType)(-1); StartCoroutine(WaitForInstanceCast()); //StartCoroutine(scrollTexture()); }
public void LoadLevel(LevelInfo level, WeatherManager.WeatherType weather) { Debug.Log("Loading Level: " + level.name + " Weather: " + weather.ToString()); // Unload current level LevelInfo curr = FindObjectOfType <LevelInfo>(); if (curr != null) { Destroy(curr.gameObject); } // Load new level Instantiate(level.gameObject); //WeatherScript.Instance.type = weather; StartCoroutine(SetWeather(weather)); }
// Update is called once per frame void Update() { instType = instType != (WeatherManager.WeatherType)WeatherManager.Instance.instanceTypeNum ? (WeatherManager.WeatherType)WeatherManager.Instance.instanceTypeNum : instType; switch (instType) { case WeatherManager.WeatherType.sun: animator.SetTrigger(sunTrigger); break; case WeatherManager.WeatherType.rain: animator.SetTrigger(rainTrigger); break; case WeatherManager.WeatherType.snow: animator.SetTrigger(snowTrigger); break; } }
// Russell Brabers - 05/28 // Modified from coroutine to method for global weather public void WeatherChange(WeatherManager.WeatherType _type) { Frame frame; if (_type == WeatherManager.WeatherType.rain && prevFrame == this.frames[0]) { return; } else if (_type == WeatherManager.WeatherType.rain && prevFrame == this.frames[1]) { frame = this.frames[0]; } else if (_type == WeatherManager.WeatherType.snow) { frame = this.frames[1]; } else { frame = this.frames[0]; } if (prevFrame == null) { prevFrame = frame; } // Make the frame 'visible' by making negative 'z' vertex positions positive ModifyVertices(-frame.Vertex_z); // Check if the current frame is different from the previous frame and // make the previous frame 'invisible' again. Make matching positive 'z' values negative if (frame != prevFrame) { ModifyVertices(prevFrame.Vertex_z); } prevFrame = frame; }
void Update() { bool isInView = false; foreach (Transform t in transform) { if (t.name == "Water Mesh(Clone)") { if (t.GetComponent <MeshRenderer>().isVisible) { isInView = true; break; } } } if (isInView) { // Check Player's position compared to the water to determine render order if (gameObject.transform.position.y - 0.5f < player.transform.position.y) { foreach (Transform t in transform) { if (t.name == "Water Mesh(Clone)") { t.GetComponent <MeshRenderer>().sortingLayerName = "Ice"; } } } else { foreach (Transform t in transform) { if (t.name == "Water Mesh(Clone)") { t.GetComponent <MeshRenderer>().sortingLayerName = "Foreground"; } } } // dampening factor for (int i = 0; i < xPositions.Length; i++) { float force = springConstant * (yPositions[i] - transform.position.y) + velocities[i] * damping; accelerations[i] = -force; yPositions[i] += velocities[i]; yEdgePositions[i] += velocities[i]; velocities[i] += accelerations[i]; } // wave propagation for (int i = 0; i < 8; i++) { for (int j = 0; j < xPositions.Length; j++) { // Water is frozen if (type == WeatherManager.WeatherType.snow && !instanceRunning) { velocities[j] = 0; accelerations[j] = 0; yPositions[j] = transform.position.y; yEdgePositions[j] = transform.position.y - perspectiveDepth; } else { if (j > 0) { leftDeltas[j] = spread * (yPositions[j] - yPositions[j - 1]); velocities[j - 1] += leftDeltas[j]; } if (j < xPositions.Length - 1) { rightDeltas[j] = spread * (yPositions[j] - yPositions[j + 1]); velocities[j + 1] += rightDeltas[j]; } // Prevent the first and end points from moving if (j == 0) { velocities[j] = 0; } for (int k = 1; k <= 5; k++) { velocities[xPositions.Length - k] = 0; } } } } for (int i = 0; i < xPositions.Length; i++) { if (i > 0) { yPositions[i - 1] += leftDeltas[i]; yEdgePositions[i - 1] += leftDeltas[i]; } if (i < xPositions.Length - 1) { yPositions[i + 1] += rightDeltas[i]; yEdgePositions[i + 1] += rightDeltas[i]; } } } type = WeatherManager.Instance.type; #region Weather Change Effect if (type != prevType) { if (type == WeatherManager.WeatherType.sun) { for (int i = 0; i < edgeCount; i++) { colliders[i].GetComponent <BoxCollider2D>().isTrigger = true; } if (prevType == WeatherManager.WeatherType.snow) { foreach (GameObject g in meshObjects) { g.GetComponent <MeshRenderer>().material = waterMat; } } prevType = type; } else if (type == WeatherManager.WeatherType.rain) { for (int i = 0; i < edgeCount; i++) { colliders[i].GetComponent <BoxCollider2D>().isTrigger = true; } if (prevType == WeatherManager.WeatherType.snow) { foreach (GameObject g in meshObjects) { g.GetComponent <MeshRenderer>().material = waterMat; } } prevType = type; } else if (type == WeatherManager.WeatherType.snow) { foreach (GameObject g in meshObjects) { g.GetComponent <MeshRenderer>().material = iceMat; } for (int i = 0; i < edgeCount; i++) { colliders[i].GetComponent <BoxCollider2D>().isTrigger = false; } prevType = type; } } #endregion if (instanceRunning && currentInstType == WeatherManager.WeatherType.sun && type == WeatherManager.WeatherType.snow) { foreach (GameObject go in colliders) { if (WeatherManager.Instance.withinInstanceWeather(go)) { go.GetComponent <BoxCollider2D>().isTrigger = true; } } foreach (GameObject go in meshObjects) { if (WeatherManager.Instance.withinInstanceWeather(go.GetComponent <MeshFilter>().sharedMesh.vertices[0].x)) { go.GetComponent <MeshRenderer>().material = waterMat; } } // Stop frozen water outside sun weather zone from waving for (int i = 0; i < xPositions.Length - 1; i++) { if (!WeatherManager.Instance.withinInstanceWeather(xPositions[i])) { velocities[i] = 0; } } } else if (!instanceRunning && type == WeatherManager.WeatherType.snow) { foreach (GameObject go in colliders) { go.GetComponent <BoxCollider2D>().isTrigger = false; } foreach (GameObject go in meshObjects) { go.GetComponent <MeshRenderer>().material = iceMat; } } UpdateMeshes(); //scrollTexture(); }
public void castInstance(bool instance, WeatherManager.WeatherType instType) { instanceRunning = instance; currentInstType = instType; }
// Check if a particle is inside any collider on a weather layer that's currently in affect private void handleForces(WeatherManager.WeatherType t, ref ParticleSystem.Particle p, out bool inForceAccector, out bool inGravityAffector) { inForceAccector = false; inGravityAffector = false; Force externalForce = new Force(); externalForce.priority = -1; Collider2D[] col = Physics2D.OverlapPointAll(p.position, WeatherManager.getWeatherLayer(t)); foreach (Collider2D c in col) { ForceAffector foa = c.GetComponent <ForceAffector>(); if (foa != null) { inForceAccector = true; if (externalForce.priority == foa.priority) { externalForce.force += foa.force; p.velocity = externalForce.force; } else if (foa.priority > externalForce.priority) { externalForce.priority = foa.priority; externalForce.force = foa.force; } } GravityAffector ga = c.GetComponent <GravityAffector>(); if (ga != null) { inGravityAffector = true; jumpHeight = ga.jumpHeight; timeToJumpApex = ga.timeToApex; } else { jumpHeight = pal.jumpHeightDefault; timeToJumpApex = pal.timeToApexDefault; } } if (jumpHeight == 0 && timeToJumpApex == 0) { jumpHeight = pal.jumpHeightDefault; timeToJumpApex = pal.timeToApexDefault; } float gravityMod = 1; switch (t) { case WeatherManager.WeatherType.sun: gravityMod = dandyFall; break; case WeatherManager.WeatherType.rain: gravityMod = rainFall; break; case WeatherManager.WeatherType.snow: gravityMod = snowFall; break; } Vector3 velocity = p.velocity; gravity = -(2 * jumpHeight) / Mathf.Pow(timeToJumpApex, 2) * gravityMod; velocity.x = externalForce.force.x; // Reduce or increase gravity depending on the magnitude and direction of the external force float forceDiff = gravity + externalForce.force.y; float m = 0.05f; float forceMod = forceDiff > 0 ? Mathf.Pow(2, m * -forceDiff) : -Mathf.Pow(2, m * forceDiff) + 2; velocity.y = gravity * forceMod; p.velocity = velocity; }
public IEnumerator SetWeather(WeatherManager.WeatherType weather) { yield return(new WaitForEndOfFrame()); WeatherManager.Instance.type = weather; }
public void LoadWeatherLevel(LevelInfo level, WeatherManager.WeatherType weather) { LoadLevel(level, weather); }
public void LoadWeatherLevel(string levelName, WeatherManager.WeatherType weather) { LevelInfo level = Resources.Load <LevelInfo>("Levels/" + levelName); LoadLevel(level, weather); }