public void Generate() { existance = (Time.time - createdTime) / lifetime; if (existance <= 1f) { existanceEased = Easings.Interpolate(existance, easing); current = FlatFXState.Lerp(start, end, existanceEased); switch (type) { case FlatFXType.Explosion: GenerateExplosion(); break; case FlatFXType.Ripple: GenerateRipple(); break; case FlatFXType.Pop: GeneratePop(); break; case FlatFXType.Crosslight: GenerateCrosslight(); break; case FlatFXType.SunRays: GenerateSunRays(); break; } } }
private void GeneratePop() { vertices.Clear(); colors.Clear(); float rayWidth = 0.1f; float a; Vector2 start, end, direction; triangles = new int[sectorCount * 2 * 3]; for (int i = 0; i < sectorCount; i++) { a = (360f / sectorCount) * i + current.rotation; start = CirclePoint(Mathf.Max(current.size / 2f - current.thickness, 0f), a) + current.position; end = CirclePoint(current.size / 2f, a) + current.position; direction = end - start; vertices.Add(start + (new Vector2(-direction.y, direction.x).normalized *(rayWidth / 2f))); vertices.Add(end + (new Vector2(-direction.y, direction.x).normalized *(rayWidth / 2f))); vertices.Add(end + (new Vector2(direction.y, -direction.x).normalized *(rayWidth / 2f))); vertices.Add(start + (new Vector2(direction.y, -direction.x).normalized *(rayWidth / 2f))); colors.Add(current.innerColor); colors.Add(current.outerColor); colors.Add(current.outerColor); colors.Add(current.innerColor); triangles[(i * 6) + 0] = (i * 4) + 0; triangles[(i * 6) + 2] = (i * 4) + 2; triangles[(i * 6) + 1] = (i * 4) + 1; triangles[(i * 6) + 3] = (i * 4) + 2; triangles[(i * 6) + 5] = (i * 4) + 0; triangles[(i * 6) + 4] = (i * 4) + 3; } }
public FlatFXSettings(FlatFXType type, int sectorCount, float lifetime, Easings.Functions easing, float randomizePosition, FlatFXState start, FlatFXState end) { this.type = type; this.sectorCount = sectorCount; this.lifetime = lifetime; this.easing = easing; this.randomizePosition = randomizePosition; this.start = start; this.end = end; }
public FlatFXParticle(FlatFXType type, float lifetime, int sectorCount, Easings.Functions easing, FlatFXState start, FlatFXState end) { this.type = type; this.lifetime = lifetime; this.sectorCount = sectorCount; this.easing = easing; this.start = start; this.end = end; this.createdTime = Time.time; }
public static FlatFXState Lerp(FlatFXState start, FlatFXState end, float t) { return(new FlatFXState( Vector2.Lerp(start.position, end.position, t), Mathf.Lerp(start.size, end.size, t), Mathf.Lerp(start.thickness, end.thickness, t), Mathf.Lerp(start.rotation, end.rotation, t), Color.Lerp(start.innerColor, end.innerColor, t), Color.Lerp(start.outerColor, end.outerColor, t), Mathf.Lerp(start.seed, end.seed, t) )); }