创建脚本iTweenPathPlugin.cs,将其添加到相应的组件中。
通过PathNodes添加节点绘制路径,同时可以通过调用GetPath(pathName)传入路径名获取相应的路径节点。

public class iTweenPathPlugin : MonoBehaviour {

    public string pathName = "";
    public Color pathColor = Color.cyan;
    public List<Vector3> pathNodes = new List<Vector3>() { Vector3.zero, Vector3.zero };
    public static Dictionary<string, iTweenPathPlugin> paths = new Dictionary<string, iTweenPathPlugin>();

    /// <summary>
    /// 将路径保存
    /// </summary>
    void OnEnable()
    {
        if (!string.IsNullOrEmpty(pathName))
        {
            paths.Add(pathName.ToLower(), this);
        }else
        {
            Debug.Log("Path is null,you need to edit it.");
        }
    }

    /// <summary>
    /// 绘制辅助可视线
    /// </summary>
    void OnDrawGizmosSelected()
    {
        if (enabled)
        { 
            if (pathNodes.Count > 0)
            {
                iTween.DrawPath(pathNodes.ToArray(), pathColor);
            }
        } 
    }

    /// <summary>
    /// 根据路径名获取加载的路径
    /// </summary>
    /// <param name="pathName">路径名string</param>
    /// <returns>路径节点数组Vector3[]</returns>
    public static Vector3[] GetPath(string pathName)
    {
        pathName = pathName.ToLower();
        if (paths.ContainsKey(pathName))
        {
            return paths[pathName].pathNodes.ToArray();
        }else
        {
            Debug.Log("no path exists.");
            return null;
        }
    }
}

效果:
iTween创建辅助可视化路径

参考
iTween Visual Editor项目

相关文章: