代码段-使用DoTween绘制一条有多个中间节点的LineRenderer线

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// 
/// 渐变绘制一条有多个中间节点的LineRenderer线
/// 
[RequireComponent (typeof(LineRenderer))]
public class DrawSingleLine : MonoBehaviour {
    public float _delayTime = .5f;

    public float[] _timeArr;//每一段要播放的时间长度
    private LineRenderer _lr;//需要被划线的物体

    private Vector3[] _lrPosArr;//该线需要被逐一绘制的点
    private void Start()
    {
        Init();
        StartCoroutine(DrawLine());
    }
    private IEnumerator DrawLine()
    {
        yield return new WaitForSeconds(_delayTime);
        //遍历所有点进行设置
        for (int k = 1, kmax = _lrPosArr.Length; k < kmax; k++)
        {
            Vector3 perPos = _lrPosArr[k - 1];//得到划线的前一个点
            Vector3 targetPos = _lrPosArr[k];//得到当前需要差值到达的点
            _lr.positionCount = k + 1;//扩充数组的数量
            _lr.SetPosition(k, perPos);//设置当前点坐标
            //声明临时变量,开始进行差值
            float curTime =Time.time;
            Vector3 midPos;
            while (Time.time();
        _lrPosArr = new Vector3[_lr.positionCount];

        for (int i = 0, max = _lr.positionCount; i < max; i++)
        {
            //得到具体的相对坐标值
            _lrPosArr[i] = _lr.GetPosition(i);
        }
        _lr.positionCount = 1;
    }
}

你可能感兴趣的:(Unity学习)