示例#1
0
    protected virtual void Update()
    {
        if (Thruster != null)
        {
            if (Application.isPlaying == true)
            {
                FlickerOffset += FlickerSpeed * Time.deltaTime;
            }

            if (points == null)
            {
                points = new float[128];

                for (var i = points.Length - 1; i >= 0; i--)
                {
                    points[i] = Random.value;
                }
            }

            var noise  = Mathf.Repeat(FlickerOffset, points.Length);
            var index  = (int)noise;
            var frac   = noise % 1.0f;
            var pointA = points[index];
            var pointB = points[(index + 1) % points.Length];
            var pointC = points[(index + 2) % points.Length];
            var pointD = points[(index + 3) % points.Length];
            var f      = 1.0f - SgtHelper.CubicInterpolate(pointA, pointB, pointC, pointD, frac) * Flicker;

            throttle = SgtHelper.Dampen(throttle, Thruster.Throttle, Dampening, Time.deltaTime);

            transform.localScale = BaseScale + ThrottleScale * throttle * f;
        }
    }
示例#2
0
    public void UpdateMesh()
    {
        if (Detail > 2)
        {
            if (generatedMesh == null)
            {
                generatedMesh = SgtHelper.CreateTempMesh("Flare Mesh (Generated)");

                UpdateApply();
            }

            var total     = Detail + 1;
            var positions = new Vector3[total];
            var coords1   = new Vector2[total];
            var indices   = new int[Detail * 3];
            var angleStep = (Mathf.PI * 2.0f) / Detail;
            var noiseStep = 0.0f;

            if (Noise == true && NoisePoints > 0)
            {
                SgtHelper.BeginRandomSeed(NoiseSeed);
                {
                    points.Clear();

                    for (var i = 0; i < NoisePoints; i++)
                    {
                        points.Add(Random.value);
                    }

                    noiseStep = NoisePoints / (float)Detail;
                }
                SgtHelper.EndRandomSeed();
            }

            for (var point = 0; point < Detail; point++)
            {
                var v     = point + 1;
                var angle = angleStep * point;
                var x     = Mathf.Sin(angle);
                var y     = Mathf.Cos(angle);
                var r     = Radius;

                if (Wave == true)
                {
                    var waveAngle = (angle + WavePhase * Mathf.Deg2Rad) * WavePoints;

                    r += Mathf.Pow(Mathf.Cos(waveAngle) * 0.5f + 0.5f, WavePower * WavePower) * WaveStrength;
                }

                if (Noise == true && NoisePoints > 0)
                {
                    //var noise  = Mathf.Repeat(noiseStep * point + NoisePhase, NoisePoints);
                    var noise  = point * noiseStep;
                    var index  = (int)noise;
                    var frac   = noise % 1.0f;
                    var pointA = points[(index + 0) % NoisePoints];
                    var pointB = points[(index + 1) % NoisePoints];
                    var pointC = points[(index + 2) % NoisePoints];
                    var pointD = points[(index + 3) % NoisePoints];

                    r += SgtHelper.CubicInterpolate(pointA, pointB, pointC, pointD, frac) * NoiseStrength;
                }

                positions[v] = new Vector3(x * r, y * r, 0.0f);
                coords1[v]   = new Vector2(1.0f, 0.0f);
            }

            for (var tri = 0; tri < Detail; tri++)
            {
                var i  = tri * 3;
                var v0 = tri + 1;
                var v1 = tri + 2;

                if (v1 >= total)
                {
                    v1 = 1;
                }

                indices[i + 0] = 0;
                indices[i + 1] = v0;
                indices[i + 2] = v1;
            }

            generatedMesh.Clear(false);
            generatedMesh.vertices  = positions;
            generatedMesh.uv        = coords1;
            generatedMesh.triangles = indices;
            generatedMesh.RecalculateNormals();
            generatedMesh.RecalculateBounds();
        }
    }