public void kill() { m_animator.SetTrigger(dieTrigger); Event <BossDieEvent> .Broadcast(new BossDieEvent()); var rand = new StaticRandomGenerator <DefaultRandomGenerator>(); var d = new UniformFloatDistribution(-m_explosionRadius, m_explosionRadius); for (float i = 0; i <= m_explosionTime; i += m_explosionDelta) { DOVirtual.DelayedCall(i, () => { var pos = transform.position + new Vector3(d.Next(rand), d.Next(rand), -0.5f); Instantiate(m_explosionPrefab, pos, Quaternion.identity); }); } DOVirtual.DelayedCall(m_explosionTime, () => { DOVirtual.DelayedCall(0.2f, () => gameObject.SetActive(false)); Event <PlaySoundEvent> .Broadcast(new PlaySoundEvent(m_bossExplosionClip)); for (int i = 0; i < m_explosionFinalCount; i++) { var pos = transform.position + new Vector3(d.Next(rand), d.Next(rand), -0.5f); Instantiate(m_explosionPrefab, pos, Quaternion.identity); } }); }
private void Awake() { var rand = new StaticRandomGenerator <DefaultRandomGenerator>(); var d = new UniformFloatDistribution(m_minModifierLevel, m_maxModifierLevel); modifier.life *= (int)((float)modifier.life * m_baseModifierValue + d.Next(rand) * GameInfos.level); modifier.speed *= (int)((float)modifier.speed * m_baseModifierValue + d.Next(rand) * GameInfos.level); modifier.fireRate *= (int)((float)modifier.fireRate * m_baseModifierValue + d.Next(rand) * GameInfos.level); modifier.power *= (int)((float)modifier.power * m_baseModifierValue + d.Next(rand) * GameInfos.level); }
public override void Update(float deltaTime, IRandomGenerator generator) { if (IsEnded()) { m_rotation = 0; return; } m_rotation = m_distribution.Next(generator); if (m_dampingPow > 0) { float diviser = Mathf.Pow(Mathf.Clamp01(1 - (m_time - m_duration)), m_dampingPow); m_rotation /= diviser; } m_time += deltaTime; }
public override void Update(float deltaTime, IRandomGenerator generator) { if (IsEnded()) { m_offset = Vector2.zero; return; } m_offset.x = m_horizontalDistribution.Next(generator); m_offset.y = m_verticalDistribution.Next(generator); if (m_dampingPow > 0) { float diviser = Mathf.Pow(Mathf.Clamp01(1 - (m_time - m_duration)), m_dampingPow); m_offset /= diviser; } m_time += deltaTime; }
static void makeStructures(PlanetData planet, IRandomGenerator gen) { planet.structuresPrefabs = new List <GameObject>(); planet.structures = new List <StructureInfo>(); int[] structStartIndex = new int[planet.biomes.Length]; for (int i = 0; i < planet.biomes.Length; i++) { structStartIndex[i] = planet.structuresPrefabs.Count; foreach (var s in planet.biomes[i].structures) { planet.structuresPrefabs.Add(s.prefab); } } var dAngle = new UniformFloatDistribution(0, 360.0f); for (int i = 0; i < planet.triangles.Length; i++) { int biomeId = PlanetEx.biomeIndexOfTriangle(planet, i); if (biomeId < 0) { continue; } if (planet.biomes[biomeId].structureDensity <= 0 || planet.biomes[biomeId].structures.Count == 0) { continue; } var t = planet.triangles[i]; float area = MathEx.triangleArea(planet.points[t.v1].point, planet.points[t.v2].point, planet.points[t.v3].point) * planet.biomes[biomeId].structureDensity; float v = area - (int)area; if (new BernoulliDistribution(v).Next(gen)) { area = (int)area + 1; } else { area = (int)area; } var p1 = planet.points[t.v1].point * (planet.points[t.v1].height + 1) * planet.scale; var p2 = planet.points[t.v2].point * (planet.points[t.v2].height + 1) * planet.scale; var p3 = planet.points[t.v3].point * (planet.points[t.v3].height + 1) * planet.scale; var d = new Uniform3DTriangleDistribution(p1, p2, p3); List <float> weights = new List <float>(); for (int j = 0; j < planet.biomes[biomeId].structures.Count; j++) { weights.Add(planet.biomes[biomeId].structures[j].weight); } var dStructs = new DiscreteDistribution(weights); for (int j = 0; j < area; j++) { var pos = d.Next(gen); planet.structures.Add(new StructureInfo(dStructs.Next(gen) + structStartIndex[biomeId], i, pos, dAngle.Next(gen))); } } }
static void makeFinalElevation(PlanetData planet, float minHeight, float maxHeight, float forcedOffsetElevation, float oceanLevel, float lakeSize, AnimationCurve elevationCurve, IRandomGenerator gen, float randomizeElevation) { var distrib = new UniformFloatDistribution(0, randomizeElevation); int oceanBiomeIndex = -1; int lakeBiomeIndex = -1; Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < planet.biomes.Length; i++) { if (planet.biomes[i].isLakeBiome) { lakeBiomeIndex = i; } if (planet.biomes[i].isOceanBiome) { oceanBiomeIndex = i; } } setWaterBiomes(planet, oceanLevel, oceanBiomeIndex, lakeBiomeIndex, lakeSize); UnityEngine.Debug.Log("\tElapsed water biomes " + sw.Elapsed); sw.Reset(); sw.Start(); bool[] setPoints = new bool[planet.points.Length]; bool[] nextPoints = new bool[planet.points.Length]; LinkedList <NextValue> next = new LinkedList <NextValue>(); float[] newHeight = new float[planet.points.Length]; int loop = 0; for (int i = 0; i < planet.points.Length; i++) { if (planet.points[i].biomeID == oceanBiomeIndex) { continue; } bool isBorder = false; foreach (var p in planet.points[i].connectedPoints) { if (planet.points[p].height >= oceanLevel || (planet.points[p].biomeID == lakeBiomeIndex && lakeBiomeIndex >= 0)) { continue; } isBorder = true; break; } if (!isBorder) { continue; } setPoints[i] = true; loop++; } if (next.Count == 0) { setPoints[new UniformIntDistribution(0, setPoints.Length).Next(gen)] = true; } for (int i = 0; i < planet.points.Length; i++) { if (setPoints[i]) { foreach (var p in planet.points[i].connectedPoints) { if (!setPoints[p] && !nextPoints[p]) { next.AddLast(new NextValue(p, 0)); nextPoints[p] = true; } } } } while (next.Count > 0) { var current = next.First.Value.index; next.RemoveFirst(); nextPoints[current] = false; setPoints[current] = true; int bestIndex = -1; bool haveCheckedNotsetPoint = false; foreach (var p in planet.points[current].connectedPoints) { if (setPoints[p]) { if (bestIndex < 0 || newHeight[p] < newHeight[bestIndex]) { bestIndex = p; } } else if (!nextPoints[p]) { haveCheckedNotsetPoint = true; } } float d = (planet.points[bestIndex].point - planet.points[current].point).magnitude; float dHeight = Mathf.Abs(planet.points[bestIndex].height - planet.points[current].height); if (planet.points[current].biomeID == lakeBiomeIndex && lakeBiomeIndex >= 0) { newHeight[current] = newHeight[bestIndex]; } else { newHeight[current] = newHeight[bestIndex] + d * (forcedOffsetElevation + distrib.Next(gen)) + dHeight; } if (!haveCheckedNotsetPoint) { continue; } if (next.First == null || newHeight[current] <= next.First.Value.weight) { foreach (var p in planet.points[current].connectedPoints) { if (!setPoints[p] && !nextPoints[p]) { next.AddFirst(new NextValue(p, newHeight[current])); nextPoints[p] = true; } } } else { var item = next.Last; while (item.Previous != null) { if (item.Value.weight <= newHeight[current]) { break; } item = item.Previous; } foreach (var p in planet.points[current].connectedPoints) { if (!setPoints[p] && !nextPoints[p]) { next.AddAfter(item, new NextValue(p, newHeight[current])); nextPoints[p] = true; } } } } if (oceanBiomeIndex >= 0) { for (int i = 0; i < newHeight.Length; i++) { if (planet.points[i].biomeID == oceanBiomeIndex) { newHeight[i] *= -1; } } } UnityEngine.Debug.Log("\tElapsed heights " + sw.Elapsed); sw.Reset(); sw.Start(); for (int i = 0; i < planet.points.Length; i++) { if (newHeight[i] == 0 || (planet.points[i].biomeID == lakeBiomeIndex && lakeBiomeIndex >= 0)) { planet.points[i].height = newHeight[i]; continue; } float sum = 0; foreach (var p in planet.points[i].connectedPoints) { sum += newHeight[p]; } planet.points[i].height = sum / planet.points[i].connectedPoints.Count; } UnityEngine.Debug.Log("\tElapsed smooth " + sw.Elapsed); sw.Reset(); sw.Start(); float min = Mathf.Min(newHeight); float max = Mathf.Max(newHeight); for (int i = 0; i < planet.points.Length; i++) { float h = planet.points[i].height; if (h < 0) { h /= -min; h = elevationCurve.Evaluate(h); h *= -minHeight; } else { h /= max; h = elevationCurve.Evaluate(h); h *= maxHeight; } planet.points[i].height = h; } UnityEngine.Debug.Log("\tElapsed height curve " + sw.Elapsed); sw.Reset(); sw.Start(); }
public float Get(float x, Lerp.Operator o = Lerp.Operator.Square) { float dec; int x1, x2; SplitValue(x, m_size, m_frequency, out x1, out x2, out dec); float v1 = m_distribution.Next(m_generator.Set(x1)); float v2 = m_distribution.Next(m_generator.Set(x2)); return(Lerp.LerpValue(v1, v2, dec, o)); }