public IEnumerator <WaitForEndOfFrame> ModifySection(ISentenceData data) { var musicData = data as IMusicData; MusicTrack[] tracks = musicData.MusicTracks(); AudioSource[] sources = musicAudioSources.GetComponentsInChildren <AudioSource>(); // Keep runing till replaced by new enumerator while (true) { for (int i = 0; i < sources.Length; i++) { // TODO: Using tracks length in such a fasion assumes that the number of 'a' tracks is the same number // of 'b' tracks and the same number of 'percussion' tracks etc. If we want a different size array for each // type of track this code needs to be changed accordingly. int trackIndex = i / tracks.Length; float vol = 0; int innerIndex = i % tracks.Length; if (innerIndex == tracks[trackIndex].track) { // Debug.Log("I: " + i.ToString() + " track index: " + trackIndex.ToString() + " Inner index: " + innerIndex.ToString()); vol = tracks[trackIndex].vol; } var newVolume = Mathf.Lerp(originalVolumes[sources[i].name], vol, changeSpeed * (Time.time - startTime)); sources[i].volume = newVolume; } yield return(Globals.EndOfFrame); } }
public IEnumerator <WaitForEndOfFrame> ModifySection(ISentenceData data) { var groundData = data as IGroundData; var groundColors = groundData.GroundColors(); // Keep runing till replaced by new enumerator while (true) { // Change each layer color for (int i = 0; i < MaxLayers; i++) { var currColor = Color.Lerp(orgLayerColors[i], Helpers.FromText(groundColors[i]), Globals.speedChange * (Time.time - startTime)); textureData.layers[i].tint = currColor; } // Apply color changes textureData.ApplyToMaterial(groundMaterial); // Change glossiness and metallic groundMaterial.SetFloat(Glossiness, Mathf.Lerp(orgGlosiness, groundData.Smoothness(), Globals.speedChange * (Time.time - startTime))); groundMaterial.SetFloat(Glossiness, Mathf.Lerp(orgMetallic, groundData.Metallic(), Globals.speedChange * (Time.time - startTime))); yield return(Globals.EndOfFrame); } }
public IEnumerator <WaitForEndOfFrame> ModifySection(ISentenceData data) { System.Random random = new System.Random(); var animalData = data as IAnimalsData; float actualPosX, actualPosZ; int[] maxes = new int[] { 1, 1 }; foreach (var animal in animalData.Animals()) { // Origin center of section actualPosX = origin.x + (animal.pos_x_percent * sectionData.SectionLength() * Globals.animalSeperateMul); actualPosZ = origin.z + (animal.pos_z_percent * sectionData.SectionLength() * Globals.animalSeperateMul); // FOR DEBUG (choose one of the available animal subsub types) int subSubType = random.Next(1, maxes[animal.subtypeIndex - 1]); var animalName = "Animals_" + animal.subtypeIndex + "_" + subSubType; //var newAnimal = GameObject.Instantiate(originalModels.transform.Find(animalName)); GameObject newAnimal; if (poolsDict[animalName].TryGetNextObject(new Vector3(), Quaternion.Euler(0, animal.angle * 360, 0), out newAnimal)) { // Set org scale newAnimal.GetComponent <ItemComponent>().SetOrgLocalScale(newAnimal.transform.localScale); // Uniform scale newAnimal.transform.localScale *= animal.scale_mul; // Rotation around Y axis //newAnimal.rotation = Quaternion.Euler(0, animal.angle * 360, 0); // Set chunk parent var chunk = Helpers.FindClosestTerrain(terrainChunksParent, new Vector2(actualPosX, actualPosZ)); chunk.AddItem(newAnimal.GetComponent <ItemComponent>()); if (newAnimal.GetComponent <GroundItemComponent>() != null) { // Save original actual pos newAnimal.GetComponent <GroundItemComponent>().ActualOriginalPos = new Vector2(actualPosX, actualPosZ); // Set inital pos! chunk.PositionSingleGroundItem(newAnimal.GetComponent <GroundItemComponent>()); } else if (newAnimal.GetComponent <AirborneItemComponent>() != null) { // Set current item position newAnimal.GetComponent <ItemComponent>().UpdatePosition(new Vector3(actualPosX, animal.height, actualPosZ)); } } yield return(Globals.EndOfFrame); } }
public IEnumerator <WaitForEndOfFrame> ModifySection(ISentenceData data) { var skyData = data as ISkyData; // Keep runing till replaced by new enumerator while (true) { // Interpolate colors! // Interpolate Environment settings & directional lights as well var newSkyColor = Color.Lerp(orgSkyColor, Helpers.FromText(skyData.ColorSky()), Globals.speedChange * (Time.time - startTime)); skyMaterial.SetColor(SkyColorId, newSkyColor); RenderSettings.ambientSkyColor = newSkyColor; // Darken color float h, s, v; Color.RGBToHSV(newSkyColor, out h, out s, out v); v = Mathf.Clamp01(v * FogDarknessFactor); RenderSettings.fogColor = Color.HSVToRGB(h, s, v); // TODO Color a bit darker than the actual sky color! foreach (var light in lights.GetComponentsInChildren <Light>()) { // Just a touch of the new light color light.color = Color.Lerp(Color.white, newSkyColor, 0.1f); } // Change horizon to new horizon color if (skyData.IsSkyGradient()) { var newHorizonColor = Color.Lerp(orgHorizonColor, Helpers.FromText(skyData.ColorHorizon()), Globals.speedChange * (Time.time - startTime)); RenderSettings.ambientEquatorColor = newHorizonColor; skyMaterial.SetColor(HorizonColorId, newHorizonColor); } else { var newHorizonColor = Color.Lerp(orgHorizonColor, Helpers.FromText(skyData.ColorSky()), Globals.speedChange * (Time.time - startTime)); // Change horizon to sky color RenderSettings.ambientEquatorColor = newHorizonColor; skyMaterial.SetColor(HorizonColorId, newHorizonColor); } // Change ground color to match horizon RenderSettings.ambientGroundColor = RenderSettings.ambientEquatorColor; yield return(Globals.EndOfFrame); } }
public IEnumerator <WaitForEndOfFrame> ModifySection(ISentenceData data) { var pathData = data as IPathData; // Keep runing till replaced by new enumerator while (true) { BloomModel.Settings effectSettings = myProfile.bloom.settings; // Lerp changes effectSettings.bloom.intensity = Mathf.Lerp(orgIntensity, pathData.BloomIntensity(), Globals.speedChange * (Time.time - startTime)); effectSettings.bloom.threshold = Mathf.Lerp(orgThreshold, pathData.BloomThreshold(), Globals.speedChange * (Time.time - startTime)); myProfile.bloom.settings = effectSettings; yield return(Globals.EndOfFrame); } }
public IEnumerator <WaitForEndOfFrame> ModifySection(ISentenceData data) { System.Random random = new System.Random(); var rocksData = data as IRocksData; float actualPosX, actualPosZ; int[] maxes = new int[] { 6 }; foreach (var rock in rocksData.Rocks()) { // Origin center of section actualPosX = origin.x + (rock.pos_x_percent * sectionData.SectionLength() * Globals.groundSeperateMul); actualPosZ = origin.z + (rock.pos_z_percent * sectionData.SectionLength() * Globals.groundSeperateMul); // FOR DEBUG int subSubType = random.Next(1, maxes[rock.subtypeIndex - 1]); var rockName = "Rocks_" + rock.subtypeIndex + "_" + subSubType; //var newRock = GameObject.Instantiate(originalModels.transform.Find(rockName)); GameObject newRock; if (poolsDict[rockName].TryGetNextObject(new Vector3(), Globals.defaultRotation, out newRock)) { newRock.GetComponent <ItemComponent>().SetOrgLocalScale(newRock.transform.localScale); // Uniform scale newRock.transform.localScale *= rock.scale_mul; // Set chunk parent var chunk = Helpers.FindClosestTerrain(terrainChunksParent, new Vector2(actualPosX, actualPosZ)); chunk.AddItem(newRock.GetComponent <ItemComponent>()); // Save original actual pos newRock.GetComponent <GroundItemComponent>().ActualOriginalPos = new Vector2(actualPosX, actualPosZ); // Set inital pos! chunk.PositionSingleGroundItem(newRock.GetComponent <GroundItemComponent>()); } yield return(Globals.EndOfFrame); } }
public IEnumerator <WaitForEndOfFrame> ModifySection(ISentenceData data) { var weatherData = data as IWeatherData; // Cancel any active weather effects if (!weatherData.IsWeatherActive()) { // If no more particles & active - turn inactive if (hail.isPlaying) { hail.Stop(true, ParticleSystemStopBehavior.StopEmitting); } } while (weatherData.IsWeatherActive()) { // Enable correct system once if (!hail.isPlaying && (weatherData.WeatherType() == WeatherTypes.Hail)) { // If type and active mismatch but weather should be active, set active/inactive according to type hail.Play(true); } // Enable/disable wind once if (wind.gameObject.activeSelf != weatherData.IsWindActive()) { wind.gameObject.SetActive(weatherData.IsWindActive()); } // TODO make change to weather more versetile main.gravityModifier = new ParticleSystem.MinMaxCurve(Mathf.Lerp(main.gravityModifier.constant, weatherData.GravityModifier(), Globals.speedChange * Time.deltaTime)); wind.windMain = Mathf.Lerp(wind.windMain, weatherData.WindMain(), Globals.speedChange * Time.deltaTime); wind.windTurbulence = Mathf.Lerp(wind.windTurbulence, weatherData.WindTurbulence(), Globals.speedChange * Time.deltaTime); wind.windPulseMagnitude = Mathf.Lerp(wind.windPulseMagnitude, weatherData.WindPulseMag(), Globals.speedChange * Time.deltaTime); wind.windPulseFrequency = Mathf.Lerp(wind.windPulseFrequency, weatherData.WindPulseFreq(), Globals.speedChange * Time.deltaTime); yield return(Globals.EndOfFrame); } }
public IEnumerator <WaitForEndOfFrame> ModifySection(ISentenceData data) { System.Random random = new System.Random(); var cloudData = data as ICloudsData; float actualPosX, actualPosZ; int[] maxes = new int[] { 3, 9 }; foreach (var cloud in cloudData.Clouds()) { // Origin center of section actualPosX = origin.x + (cloud.pos_x_percent * sectionData.SectionLength() * Globals.cloudSeperateMul); actualPosZ = origin.z + (cloud.pos_z_percent * sectionData.SectionLength() * Globals.cloudSeperateMul); // FOR DEBUG int subSubType = random.Next(1, maxes[cloud.subtypeIndex - 1]); var cloudName = "Clouds_" + cloud.subtypeIndex + "_" + subSubType; //GameObject newCloud = GameObject.Instantiate(originalModels.transform.Find(plantName)); GameObject newCloud; if (poolsDict[cloudName].TryGetNextObject(new Vector3(), Globals.defaultRotation, out newCloud)) { newCloud.GetComponent <ItemComponent>().SetOrgLocalScale(newCloud.transform.localScale); // Uniform scale newCloud.transform.localScale *= cloud.scale_mul; // Set chunk parent var chunk = Helpers.FindClosestTerrain(terrainChunksParent, new Vector2(actualPosX, actualPosZ)); chunk.AddItem(newCloud.GetComponent <ItemComponent>()); // Set current item position to X, Y = cloud height, Z newCloud.GetComponent <ItemComponent>().UpdatePosition(new Vector3(actualPosX, cloud.height, actualPosZ)); } yield return(Globals.EndOfFrame); } }
public IEnumerator <WaitForEndOfFrame> ModifySection(ISentenceData data) { var sectionData = data as ISectionData; // Get data angles = sectionData.SectionAngles(); Array.Sort(angles, new SectionAngleComp()); points = new Vector2[angles.Length + 1]; for (int i = 0; i < angles.Length; i++) { points[i] = new Vector2(initialPosition.x + angles[i].pos_x * sectionData.SectionLength(), initialPosition.z + angles[i].pos_z * sectionData.SectionLength()); } points[angles.Length] = new Vector2(sectionData.SectionLength(), 0); // Move Character! Currently not working well... // If not done with curr sub path //if (Vector2.Distance(points[currSubPath], new Vector2(player.position.x, player.position.z)) < distThreshold) { // currSubPath++; //} //if (currSubPath < points.Length) //{ // movement = new Vector2(Mathf.Clamp(points[currSubPath].x - player.position.x, 0, 1), // Mathf.Clamp(points[currSubPath].y - player.position.z, 0, 1)); //} //else //{ // movement = new Vector2(); //} yield return(null); }