Beispiel #1
0
    void GenerateCurve()
    {
        Queue <FrameDate> frames;
        List <Transform>  wayPoints = new List <Transform>();
        List <PathNode>   pathnodes = new List <PathNode>(nodes.Values);

        pathnodes.Sort((a, b) =>
        {
            return(a.Index.CompareTo(b.Index));
        });

        int count = pathnodes.Count;

        for (int i = 0; i < count; ++i)
        {
            if (i == 0)
            {
                psystem.transform.position    = pathnodes[i].Node.position;
                psystem.transform.eulerAngles = Vector3.zero;
            }
            if (pathnodes[i].Node)
            {
                wayPoints.Add(pathnodes[i].Node);
            }
        }
        //至少要两个点
        if (wayPoints.Count > 1)
        {
            float          distance = ParticleUtils.CalculateDirection(wayPoints, out frames);
            AnimationCurve curve_X;
            AnimationCurve curve_Y;
            AnimationCurve curve_Z;
            float          lifeTime = distance / psystem.startLifetime;
            ParticleUtils.MakeCurve(frames, distance, lifeTime, out curve_X, out curve_Y, out curve_Z);
            var vel = psystem.velocityOverLifetime;
            vel.enabled = true;
            vel.space   = ParticleSystemSimulationSpace.Local;
            vel.x       = new ParticleSystem.MinMaxCurve(lifeTime, curve_X);
            vel.y       = new ParticleSystem.MinMaxCurve(lifeTime, curve_Y);
            vel.z       = new ParticleSystem.MinMaxCurve(lifeTime, curve_Z);
        }
    }
    public void DrawPath(List <Vector3> points)
    {
        Queue <FrameDate> frames;
        float             distance = ParticleUtils.CalculateDirection(points, out frames);

        particle.transform.position = points[0];
        AnimationCurve curve_X;
        AnimationCurve curve_Y;
        AnimationCurve curve_Z;
        float          lifeTime = distance / particle.startLifetime;

        ParticleUtils.MakeCurve(frames, distance, lifeTime, out curve_X, out curve_Y, out curve_Z);
        var vel = particle.velocityOverLifetime;

        vel.enabled = true;
        vel.space   = ParticleSystemSimulationSpace.Local;
        vel.x       = new ParticleSystem.MinMaxCurve(lifeTime, curve_X);
        vel.y       = new ParticleSystem.MinMaxCurve(lifeTime, curve_Y);
        vel.z       = new ParticleSystem.MinMaxCurve(lifeTime, curve_Z);
    }