画线代码V1.0.0

时间:2023-02-21 11:55:27

画线代码:

  最终效果图:

画线代码V1.0.0

优点:

  1.效果还行,计算量也不大(就一点2维直线一般式能有多少运算量)。

缺点:

  1.每条线怎么也是建模,可能会有点开销。

  2.编辑起来很是麻烦。


代码部分:

  

/***************************************
Editor: Tason
Version: v1.0
Last Edit Date: 2018-XX-XX
Tel: 328791554@qq.com
Function Doc:
1.自建Mesh划线
***************************************/ using UnityEngine;
using System.Collections; namespace ZQFY
{
public class JWDrawLineManager_ZQFY : MonoBehaviour
{
//y = ax + b 2维直线一般式
public class JWLineA
{
public float m_a;
public float m_b; //无参构造
public JWLineA() { } //带参构造
public JWLineA(float _a, float _b)
{
m_a = _a;
m_b = _b;
} //传入一个点 & 一个向量
public void SetLine(Vector2 _dot, Vector2 _dir)
{
m_a = _dir.y / _dir.x;
m_b = _dot.y - _dot.x * m_a;
} //传入2根线 计算交点 (参数3 ; 如果平行返回的默认值)
public static Vector3 GetIntersectionPoint(JWLineA _a, JWLineA _b, Vector3 _default)
{
Vector3 r = _default;
if (_a.m_a != _b.m_a)
{
r.x = (_a.m_b - _b.m_b) / (_b.m_a - _a.m_a);
r.y = r.x * _a.m_a + _a.m_b;
}
return r;
}
} //单例
private static JWDrawLineManager_ZQFY m_instance;
public static JWDrawLineManager_ZQFY Instance
{
get { return m_instance; }
} private void Awake()
{
m_instance = this;
} //创建Mesh
public static Mesh CreateMesh(Vector3[] _v3, float _width)
{
Mesh r = new Mesh();
r.name = "JWLine";
r.vertices = GetPoints(_v3, _width);
r.triangles = GetTri(r.vertices.Length);
r.normals = GetNor(r.vertices.Length);
r.uv = GetUV(r.vertices.Length);
return r;
} //得到顶点
private static Vector3[] GetPoints(Vector3[] _v, float _width)
{
Vector3 tempN = new Vector3(, , -); //安全校验
if (_v.Length < )
return null; //开堆
Vector3[] r = new Vector3[_v.Length * ]; //第一个点
Vector3 temp0 = Vector3.Cross(tempN, _v[] - _v[]).normalized * _width;
r[] = temp0 + _v[];
r[] = r[] - * temp0; //后面(除最后一个)的点
JWLineA lineA = new JWLineA();
JWLineA lineB = new JWLineA();
for (int i = ; i < _v.Length - ; ++i)
{
//第一根线
lineA.SetLine(r[ * (i - )], _v[i] - _v[i - ]); //第二根线
Vector3 temp1 = _v[i + ] - _v[i];
Vector3 dot = _v[i] + Vector3.Cross(tempN, temp1).normalized * _width;
lineB.SetLine(dot, temp1); //计算交点
r[i * ] = JWLineA.GetIntersectionPoint(lineA, lineB, dot);
r[i * + ] = r[i * ] + * (_v[i] - r[i * ]);
} //最后一个点
Vector3 temp2 = Vector3.Cross(tempN, _v[_v.Length - ] - _v[_v.Length - ]).normalized * _width;
r[(_v.Length - ) * ] = temp2 + _v[_v.Length - ];
r[(_v.Length - ) * + ] = -temp2 + _v[_v.Length - ]; return r;
} //得到三角面
private static int[] GetTri(int _vc)
{
//计算三角面个数
int tc = (_vc - ) * * ;
int[] r = new int[tc]; for (int i = ,j = ; i < _vc - ; i += , j += )
{
r[j + ] = i + ;
r[j + ] = i + ;
r[j + ] = i + ; r[j + ] = i + ;
r[j + ] = i + ;
r[j + ] = i + ;
} return r;
} //得到顶点法线
private static Vector3[] GetNor(int _vc)
{
Vector3[] r = new Vector3[_vc];
for (int i = ; i < r.Length; ++i)
r[i] = new Vector3(, , -);
return r;
} //得到UV
private static Vector2[] GetUV(int _vc)
{
Vector2[] r = new Vector2[_vc]; for (int i = ; i < _vc; ++i)
{
r[i].x = 1.0f / _vc * * (i / ) ;
r[i].y = i % ;
} return r;
} //绘制Mesh
public GameObject CreatObject(string _name, Mesh _mesh, Material _material, float _z = , Transform _parent = null)
{
GameObject r = null;
//安全校验
if (_material == null)
return null; GameObject obj = new GameObject();
obj.name = _name;
if (_parent == null)
obj.transform.parent = transform;
else
obj.transform.parent = _parent;
if (_z == )
obj.transform.localPosition = Vector3.zero;
else
obj.transform.localPosition = new Vector3(, , _z);
obj.transform.localScale = Vector3.one;
MeshFilter mf = obj.AddComponent<MeshFilter>();
MeshRenderer mr = obj.AddComponent<MeshRenderer>();
mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
mr.receiveShadows = false;
mf.mesh = _mesh;
mr.material = _material;
r = obj;
return r;
} static void getAB(Vector3 A, Vector3 B, Vector3 C, float w, out Vector3 r1, out Vector3 r2, int num)
{
Vector3 BA = A - B; //把 A 平移到 B为原点处
Vector3 BC = C - B; if (num % == )
{
num = -;
}
else
{
num = ;
} BA.Normalize(); //只是使两个向量同长,方便求角平分线向量
BC.Normalize(); Vector3 BB = (BA + BC) / ; //角平分线向量 BB.Normalize(); //长度变1 int q = getQuadrant(A, B, C); //通过三个点的分布,知道r1 r2哪一个在内角,哪一个是外折角 if (q == || q == )
{
r2 = BB * (w / ); //折角处的一个点
r1 = -r2; //原点对面的对称折点 r1 *= num;
r2 *= num; //平移回原坐标系
r1 += B;
r2 += B;
}
else
{
r1 = BB * (w / ); //折角处的一个点
r2 = -r1; //原点对面的对称折点 r1 *= num;
r2 *= num; //平移回原坐标系
r1 += B;
r2 += B;
}
} //ABC是全局空间中的坐标, 如果以B为新原点 ,A为X负方向,那 返回C反在的象限数
static int getQuadrant(Vector3 A, Vector3 B, Vector3 C)
{
float ang;
//先算出BA的旋转角度 以B为原点 BA 与负轴的夹角
//1像限
if (A.x >= B.x && A.y >= B.y)
{
//AB直线相对世界转了 ang 角度
ang = Vector3.Angle(A - B, Vector3.left);
ang = ang / * Mathf.PI;
}
//2像限
else if (A.x <= B.x && A.y >= B.y)
{
ang = Vector3.Angle(A - B, Vector3.left);
ang = ang / * Mathf.PI;
}
else if (A.x <= B.x && A.y <= B.y)
{
ang = Vector3.Angle(A - B, Vector3.left);
ang = ( - ang) / * Mathf.PI;
}
//4像限
else
{
ang = Vector3.Angle(A - B, Vector3.left);
ang = ( - ang) / * Mathf.PI;
} //新坐标 xy
float x = (C.x - B.x) * Mathf.Cos(ang) - (C.y - B.y) * Mathf.Sin(ang);// + B.x; //不加就是以B为原点时的坐标,加就是以原始原点的坐标
float y = (C.x - B.x) * Mathf.Sin(ang) + (C.y - B.y) * Mathf.Cos(ang);// + B.y; if (x >= && y >= )
return ;
if (x <= && y >= )
return ;
if (x <= && y <= )
return ; return ;
}
}
}
/***************************************
Editor: Tason
Version: v1.0
Last Edit Date: 2018-XX-XX
Tel: 328791554@qq.com
Function Doc: ***************************************/ using UnityEngine;
using System.Collections;
using System.Collections.Generic; namespace ZQFY
{
public class LineManager_ZQFY : MonoBehaviour
{
public Material[] m_materials; public MyLine[] m_mylines;
public Material[] m_mylinesMaterials; public GameObject[] m_leftLights;
public UISprite[] m_leftLightsSprites;
public GameObject[] m_rightLights;
public UISprite[] m_rightLightsSprites; private Color c0;
private Color c1;
private Color c2;
private Color c3;
//线宽
private float m_width = 30f;
void Start()
{
ColorUtility.TryParseHtmlString("#87FDFFFF", out c0);
ColorUtility.TryParseHtmlString("#3D00FFFF", out c1);
ColorUtility.TryParseHtmlString("#7F7F7F7F", out c2);
ColorUtility.TryParseHtmlString("#87FDFFFF", out c3); //30条连线的数据
Vector3[] ps2 = new Vector3[];
GameObject[] m_linesObjs = new GameObject[];
m_mylines = new MyLine[];
for (int i = ; i < m_mylines.Length; ++i)
m_mylines[i] = new MyLine(); // ----- 第一条线 -----
ps2[].x = -; ps2[].y = ;
ps2[].x = -; ps2[].y = ;
ps2[].x = -157.5f; ps2[].y = ;
ps2[].x = ; ps2[].y = ;
ps2[].x = 157.5f; ps2[].y = ;
ps2[].x = ; ps2[].y = ;
ps2[].x = ; ps2[].y = ; //创建模型
Mesh mesh0 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line0", mesh0, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第二条线 -----
ps2[].x = -; ps2[].y = 95f;
ps2[].x = -; ps2[].y = 95f;
ps2[].x = -157.5f; ps2[].y = 95f;
ps2[].x = ; ps2[].y = 95f;
ps2[].x = 157.5f; ps2[].y = 95f;
ps2[].x = ; ps2[].y = 95f;
ps2[].x = ; ps2[].y = 95f; //创建模型
Mesh mesh1 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line1", mesh1, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第三条线 -----
ps2[].x = -; ps2[].y = -95f;
ps2[].x = -; ps2[].y = -95f;
ps2[].x = -157.5f; ps2[].y = -95f;
ps2[].x = ; ps2[].y = -95f;
ps2[].x = 157.5f; ps2[].y = -95f;
ps2[].x = ; ps2[].y = -95f;
ps2[].x = ; ps2[].y = -95f; //创建模型
Mesh mesh2 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line2", mesh2, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第四条线 -----
ps2[].x = -; ps2[].y = 104.5f;
ps2[].x = -; ps2[].y = 104.5f;
ps2[].x = -157.5f; ps2[].y = 0f;
ps2[].x = ; ps2[].y = -104.5f;
ps2[].x = 157.5f; ps2[].y = 0f;
ps2[].x = ; ps2[].y = 104.5f;
ps2[].x = ; ps2[].y = 104.5f; //创建模型
Mesh mesh3 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line3", mesh3, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第五条线 -----
ps2[].x = -; ps2[].y = -104.5f;
ps2[].x = -; ps2[].y = -104.5f;
ps2[].x = -157.5f; ps2[].y = 0f;
ps2[].x = ; ps2[].y = 104.5f;
ps2[].x = 157.5f; ps2[].y = 0f;
ps2[].x = ; ps2[].y = -104.5f;
ps2[].x = ; ps2[].y = -104.4f; //创建模型
Mesh mesh4 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line4", mesh4, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第六条线 -----
ps2[].x = -; ps2[].y = 38f;
ps2[].x = -; ps2[].y = 38f;
ps2[].x = -157.5f; ps2[].y = 123.5f;
ps2[].x = ; ps2[].y = 123.5f;
ps2[].x = 157.5f; ps2[].y = 123.5f;
ps2[].x = ; ps2[].y = 38f;
ps2[].x = ; ps2[].y = 38f; //创建模型
Mesh mesh5 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line5", mesh5, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第七条线 -----
ps2[].x = -; ps2[].y = -38f;
ps2[].x = -; ps2[].y = -38f;
ps2[].x = -157.5f; ps2[].y = -123.5f;
ps2[].x = ; ps2[].y = -123.5f;
ps2[].x = 157.5f; ps2[].y = -123.5f;
ps2[].x = ; ps2[].y = -38f;
ps2[].x = ; ps2[].y = -38f; //创建模型
Mesh mesh6 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line6", mesh6, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第八条线 -----
ps2[].x = -; ps2[].y = 142.5f;
ps2[].x = -; ps2[].y = 142.5f;
ps2[].x = -157.5f; ps2[].y = 142.5f;
ps2[].x = ; ps2[].y = 0f;
ps2[].x = 157.5f; ps2[].y = -142.5f;
ps2[].x = ; ps2[].y = -142.5f;
ps2[].x = ; ps2[].y = -142.5f; //创建模型
Mesh mesh7 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line7", mesh7, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第九条线 -----
ps2[].x = -; ps2[].y = -142.5f;
ps2[].x = -; ps2[].y = -142.5f;
ps2[].x = -157.5f; ps2[].y = -142.5f;
ps2[].x = ; ps2[].y = 0f;
ps2[].x = 157.5f; ps2[].y = 142.5f;
ps2[].x = ; ps2[].y = 142.5f;
ps2[].x = ; ps2[].y = 142.5f; //创建模型
Mesh mesh8 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line8", mesh8, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第十条线 -----
ps2[].x = -; ps2[].y = -28.5f;
ps2[].x = -; ps2[].y = -28.5f;
ps2[].x = -157.5f; ps2[].y = -114f;
ps2[].x = ; ps2[].y = 0f;
ps2[].x = 157.5f; ps2[].y = 114f;
ps2[].x = ; ps2[].y = -28.5f;
ps2[].x = ; ps2[].y = -28.5f; //创建模型
Mesh mesh9 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line9", mesh9, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第十一条线 -----
ps2[].x = -; ps2[].y = 28.5f;
ps2[].x = -; ps2[].y = 28.5f;
ps2[].x = -157.5f; ps2[].y = 114f;
ps2[].x = ; ps2[].y = ;
ps2[].x = 157.5f; ps2[].y = -114f;
ps2[].x = ; ps2[].y = 28.5f;
ps2[].x = ; ps2[].y = 28.5f; //创建模型
Mesh mesh10 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line10", mesh10, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第十二条线 -----
ps2[].x = -; ps2[].y = 123.5f;
ps2[].x = -; ps2[].y = 123.5f;
ps2[].x = -157.5f; ps2[].y = 38f;
ps2[].x = ; ps2[].y = 38f;
ps2[].x = 157.5f; ps2[].y = 38f;
ps2[].x = ; ps2[].y = 123.5f;
ps2[].x = ; ps2[].y = 123.5f; //创建模型
Mesh mesh11 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line11", mesh11, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第十三条线 -----
ps2[].x = -; ps2[].y = -123.5f;
ps2[].x = -; ps2[].y = -123.5f;
ps2[].x = -157.5f; ps2[].y = -38f;
ps2[].x = ; ps2[].y = -38f;
ps2[].x = 157.5f; ps2[].y = -38f;
ps2[].x = ; ps2[].y = -123.5f;
ps2[].x = ; ps2[].y = -123.5f; //创建模型
Mesh mesh12 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line12", mesh12, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第十四条线 -----
ps2[].x = -; ps2[].y = 114f;
ps2[].x = -; ps2[].y = 114f;
ps2[].x = -157.5f; ps2[].y = 28.5f;
ps2[].x = ; ps2[].y = 114f;
ps2[].x = 157.5f; ps2[].y = 28.5f;
ps2[].x = ; ps2[].y = 114f;
ps2[].x = ; ps2[].y = 114f; //创建模型
Mesh mesh13 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line13", mesh13, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第十五条线 -----
ps2[].x = -; ps2[].y = -114f;
ps2[].x = -; ps2[].y = -114f;
ps2[].x = -157.5f; ps2[].y = -28.5f;
ps2[].x = ; ps2[].y = -114f;
ps2[].x = 157.5f; ps2[].y = -28.5f;
ps2[].x = ; ps2[].y = -114f;
ps2[].x = ; ps2[].y = -114f; //创建模型
Mesh mesh14 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line14", mesh14, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第十六条线 -----
ps2[].x = -; ps2[].y = 19f;
ps2[].x = -; ps2[].y = 19f;
ps2[].x = -157.5f; ps2[].y = 19f;
ps2[].x = ; ps2[].y = 66.5f;
ps2[].x = 157.5f; ps2[].y = 19f;
ps2[].x = ; ps2[].y = 19f;
ps2[].x = ; ps2[].y = 19f; //创建模型
Mesh mesh15 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line15", mesh15, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第十七条线 -----
ps2[].x = -; ps2[].y = -19f;
ps2[].x = -; ps2[].y = -19f;
ps2[].x = -157.5f; ps2[].y = -19f;
ps2[].x = ; ps2[].y = -66.5f;
ps2[].x = 157.5f; ps2[].y = -19f;
ps2[].x = ; ps2[].y = -19f;
ps2[].x = ; ps2[].y = -19f; //创建模型
Mesh mesh16 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line16", mesh16, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第十八条线 -----
ps2[].x = -; ps2[].y = 133f;
ps2[].x = -; ps2[].y = 133f;
ps2[].x = -157.5f; ps2[].y = 133f;
ps2[].x = ; ps2[].y = -133f;
ps2[].x = 157.5f; ps2[].y = 133f;
ps2[].x = ; ps2[].y = 133f;
ps2[].x = ; ps2[].y = 133f; //创建模型
Mesh mesh17 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line17", mesh17, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第十九条线 -----
ps2[].x = -; ps2[].y = -133f;
ps2[].x = -; ps2[].y = -133f;
ps2[].x = -157.5f; ps2[].y = -133f;
ps2[].x = ; ps2[].y = 133f;
ps2[].x = 157.5f; ps2[].y = -133f;
ps2[].x = ; ps2[].y = -133f;
ps2[].x = ; ps2[].y = -133f; //创建模型
Mesh mesh18 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line18", mesh18, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第二十条线 -----
ps2[].x = -; ps2[].y = 85.5f;
ps2[].x = -; ps2[].y = 85.5f;
ps2[].x = -157.5f; ps2[].y = -57.5f;
ps2[].x = ; ps2[].y = -57.5f;
ps2[].x = 157.5f; ps2[].y = -57.5f;
ps2[].x = ; ps2[].y = 85.5f;
ps2[].x = ; ps2[].y = 85.5f; //创建模型
Mesh mesh19 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line19", mesh19, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第二十一条线 -----
ps2[].x = -; ps2[].y = -85.5f;
ps2[].x = -; ps2[].y = -85.5f;
ps2[].x = -157.5f; ps2[].y = 57.5f;
ps2[].x = ; ps2[].y = 57.5f;
ps2[].x = 157.5f; ps2[].y = 57.5f;
ps2[].x = ; ps2[].y = -85.5f;
ps2[].x = ; ps2[].y = -85.5f; //创建模型
Mesh mesh20 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line20", mesh20, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第二十二条线 -----
ps2[].x = -; ps2[].y = -9.5f;
ps2[].x = -; ps2[].y = -9.5f;
ps2[].x = -157.5f; ps2[].y = -104.5f;
ps2[].x = ; ps2[].y = 142.5f;
ps2[].x = 157.5f; ps2[].y = -104.5f;
ps2[].x = ; ps2[].y = -9.5f;
ps2[].x = ; ps2[].y = -9.5f; //创建模型
Mesh mesh21 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line21", mesh21, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第二十三条线 -----
ps2[].x = -; ps2[].y = 9.5f;
ps2[].x = -; ps2[].y = 9.5f;
ps2[].x = -157.5f; ps2[].y = 104.5f;
ps2[].x = ; ps2[].y = -142.5f;
ps2[].x = 157.5f; ps2[].y = 104.5f;
ps2[].x = ; ps2[].y = 9.5f;
ps2[].x = ; ps2[].y = 9.5f; //创建模型
Mesh mesh22 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line22", mesh22, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第二十四条线 -----
ps2[].x = -; ps2[].y = 76f;
ps2[].x = -; ps2[].y = 76f;
ps2[].x = -157.5f; ps2[].y = -76f;
ps2[].x = ; ps2[].y = 76f;
ps2[].x = 157.5f; ps2[].y = -76f;
ps2[].x = ; ps2[].y = 76f;
ps2[].x = ; ps2[].y = 76f; //创建模型
Mesh mesh23 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line23", mesh23, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第二十五条线 -----
ps2[].x = -; ps2[].y = -76f;
ps2[].x = -; ps2[].y = -76f;
ps2[].x = -157.5f; ps2[].y = 76f;
ps2[].x = ; ps2[].y = -76f;
ps2[].x = 157.5f; ps2[].y = 76f;
ps2[].x = ; ps2[].y = -76f;
ps2[].x = ; ps2[].y = -76f; //创建模型
Mesh mesh24 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line24", mesh24, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第二十六条线 -----
ps2[].x = -; ps2[].y = -66.5f;
ps2[].x = -; ps2[].y = -66.5f;
ps2[].x = -157.5f; ps2[].y = 66.5f;
ps2[].x = ; ps2[].y = 0f;
ps2[].x = 157.5f; ps2[].y = -66.5f;
ps2[].x = ; ps2[].y = 66.5f;
ps2[].x = ; ps2[].y = 66.5f; //创建模型
Mesh mesh25 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line25", mesh25, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第二十七条线 -----
ps2[].x = -; ps2[].y = 66.5f;
ps2[].x = -; ps2[].y = 66.5f;
ps2[].x = -157.5f; ps2[].y = -66.5f;
ps2[].x = ; ps2[].y = 0f;
ps2[].x = 157.5f; ps2[].y = 66.5f;
ps2[].x = ; ps2[].y = -66.5f;
ps2[].x = ; ps2[].y = -66.5f; //创建模型
Mesh mesh26 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line26", mesh26, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第二十八条线 -----
ps2[].x = -; ps2[].y = 57f;
ps2[].x = -; ps2[].y = 57f;
ps2[].x = -157.5f; ps2[].y = -85.5f;
ps2[].x = ; ps2[].y = -9.5f;
ps2[].x = 157.5f; ps2[].y = -85.5f;
ps2[].x = ; ps2[].y = 57f;
ps2[].x = ; ps2[].y = 57f; //创建模型
Mesh mesh27 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line27", mesh27, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第二十九条线 -----
ps2[].x = -; ps2[].y = -57f;
ps2[].x = -; ps2[].y = -57f;
ps2[].x = -157.5f; ps2[].y = 85.5f;
ps2[].x = ; ps2[].y = 9.5f;
ps2[].x = 157.5f; ps2[].y = 85.5f;
ps2[].x = ; ps2[].y = -57f;
ps2[].x = ; ps2[].y = -57f; //创建模型
Mesh mesh28 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line28", mesh28, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // ----- 第三十条线 -----
ps2[].x = -; ps2[].y = -152f;
ps2[].x = -; ps2[].y = -152f;
ps2[].x = -157.5f; ps2[].y = 0f;
ps2[].x = ; ps2[].y = 152f;
ps2[].x = 157.5f; ps2[].y = 152f;
ps2[].x = ; ps2[].y = 0f;
ps2[].x = ; ps2[].y = 0f; //创建模型
Mesh mesh29 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width); //创建GameObjects
m_linesObjs[] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line29", mesh29, m_materials[], , transform);
m_linesObjs[].layer = Const_ZQFY.Layer_Line;
m_mylines[].m_line = m_linesObjs[];
m_mylines[].m_leftLight = m_leftLights[];
m_mylines[].m_rightLight = m_rightLights[]; // 绑定Shader
for (int i = ; i < m_materials.Length; ++i)
m_materials[i].shader = Shader.Find("Custom/CutLineShader"); // 全部隐藏
FadeLines();
} private void Update()
{
if (m_showLineSwitch)
{
if (m_timer + Time.deltaTime > m_totalTime)
{
m_timer = ; //灰化当前
ShowLineGrey(DataManager_ZQFY.Instance.m_awardLinesList[m_index % DataManager_ZQFY.Instance.m_awardLinesList.Count]); AppFacade_ZQFY.Instance.SendNotification(Const_ZQFY.SHOWELEMENTS); int NextIndex = ++m_index % DataManager_ZQFY.Instance.m_awardLinesList.Count; //彩化下一根
ShowLineColor(DataManager_ZQFY.Instance.m_awardLinesList[NextIndex]); DataManager_ZQFY.Instance.m_hideElements.Clear();
for (int i = ; i < DataManager_ZQFY.Instance.m_awardLines[DataManager_ZQFY.Instance.m_awardLinesList[NextIndex]].Count; ++i)
DataManager_ZQFY.Instance.m_hideElements.Add(DataManager_ZQFY.Instance.m_awardLines[DataManager_ZQFY.Instance.m_awardLinesList[NextIndex]][i]); AppFacade_ZQFY.Instance.SendNotification(Const_ZQFY.HIDEELEMENTS); AppFacade_ZQFY.Instance.SendNotification(Const_ZQFY.SPAWNELEMENT);
}
else
{
m_timer += Time.deltaTime;
}
}
} //彩化需要显示的线
public void ShowLinesColor()
{
foreach (var a in DataManager_ZQFY.Instance.m_awardLines)
ShowLineColor(a.Key);
} //显示多少根线(EndAnimation阶段)
public void ShowLines()
{
FadeLines(); foreach (var a in DataManager_ZQFY.Instance.m_awardLines)
ShowLine(a.Key, true);
} public void ShowLineGrey()
{
ShowLines(); for (int i = ; i < DataManager_ZQFY.Instance.m_awardLinesList.Count; ++i)
{
ShowLineGrey(DataManager_ZQFY.Instance.m_awardLinesList[i]);
}
} //隐藏所有线段
public void FadeLines()
{
for (int i = ; i < m_mylines.Length; ++i)
{
ShowLine(i, false);
}
} //线和灯的对应结构体
public class MyLine
{
public GameObject m_leftLight;
public GameObject m_rightLight;
public GameObject m_line; //public MyLine();
//public MyLine(GameObject _l, GameObject _r, GameObject _line)
//{ m_leftLight = _l; m_rightLight = _r; m_line = _line; }
} //显示灯&线
private void ShowLine(int _index, bool _switch)
{
if (_index < || _index > m_mylines.Length)
return;
m_mylines[_index].m_leftLight.SetActive(_switch);
m_mylines[_index].m_rightLight.SetActive(_switch);
m_mylines[_index].m_line.SetActive(_switch);
} //显示灯& 线 原色
private void ShowLineColor(int _index)
{
if (_index < || _index > m_mylines.Length)
return; m_mylinesMaterials[_index].SetColor("_MainColor", c0);
m_mylinesMaterials[_index].SetColor("_OutSideColor", c1); m_leftLightsSprites[_index].color = c3;
m_rightLightsSprites[_index].color = c3;
} //显示灯 & 线 灰色
private void ShowLineGrey(int _index)
{
if (_index < || _index > m_mylines.Length)
return; m_mylinesMaterials[_index].SetColor("_MainColor", c2);
m_mylinesMaterials[_index].SetColor("_OutSideColor", c2); m_leftLightsSprites[_index].color = c2;
m_rightLightsSprites[_index].color = c2;
} //最后的线轮播动画
private bool m_showLineSwitch = false; private int m_index = ; private float m_timer; public float m_totalTime = ; //开始轮播
public void StartShowLines()
{
if (DataManager_ZQFY.Instance.m_awardLinesList.Count > && DataManager_ZQFY.Instance.m_freeCount == && DataManager_ZQFY.Instance.m_autoCount == )
{
m_showLineSwitch = true;
m_index = ;
m_timer = ; //第一根线显示颜色
ShowLineColor(DataManager_ZQFY.Instance.m_awardLinesList[m_index]); DataManager_ZQFY.Instance.m_hideElements.Clear();
for (int i = ; i < DataManager_ZQFY.Instance.m_awardLines[DataManager_ZQFY.Instance.m_awardLinesList[m_index]].Count; ++i)
DataManager_ZQFY.Instance.m_hideElements.Add(DataManager_ZQFY.Instance.m_awardLines[DataManager_ZQFY.Instance.m_awardLinesList[m_index]][i]); AppFacade_ZQFY.Instance.SendNotification(Const_ZQFY.HIDEELEMENTS); AppFacade_ZQFY.Instance.SendNotification(Const_ZQFY.SPAWNELEMENT); }
} //关闭轮播
public void StopShowLines()
{
m_showLineSwitch = false; if (DataManager_ZQFY.Instance.m_awardLinesList.Count > )
{
for (int i = ; i < DataManager_ZQFY.Instance.m_awardLinesList.Count; ++i)
ShowLine(DataManager_ZQFY.Instance.m_awardLinesList[i], false); AppFacade_ZQFY.Instance.SendNotification(Const_ZQFY.SHOWELEMENTS);
}
}
}
}

下面这段代码还是放弃吧,太恶心了~ 为了让线好看点,我也是蛮拼的,这个东西就很难给资源包了~丢了shader资源包吧!

资源包:

链接:https://pan.baidu.com/s/1lbbAR_nuHfBC5L0Of9lDEA 密码:1hi8

Shader图:

画线代码V1.0.0

Shader代码:

  

// Shader created with Shader Forge v1.26
// Shader Forge (c) Neat Corporation / Joachim Holmer - http://www.acegikmo.com/shaderforge/
// Note: Manually altering this data may prevent you from opening it in Shader Forge
/*SF_DATA;ver:1.26;sub:START;pass:START;ps:flbk:,iptp:0,cusa:False,bamd:0,lico:0,lgpr:1,limd:0,spmd:1,trmd:0,grmd:0,uamb:True,mssp:True,bkdf:False,hqlp:False,rprd:False,enco:False,rmgx:True,rpth:0,vtps:0,hqsc:True,nrmq:1,nrsp:0,vomd:0,spxs:False,tesm:0,olmd:1,culm:0,bsrc:3,bdst:7,dpts:2,wrdp:False,dith:0,rfrpo:True,rfrpn:Refraction,coma:15,ufog:True,aust:True,igpj:True,qofs:0,qpre:3,rntp:2,fgom:False,fgoc:False,fgod:False,fgor:False,fgmd:0,fgcr:0.5,fgcg:0.5,fgcb:0.5,fgca:1,fgde:0.01,fgrn:0,fgrf:300,stcl:False,stva:128,stmr:255,stmw:255,stcp:6,stps:0,stfa:0,stfz:0,ofsf:0,ofsu:0,f2p0:False,fnsp:False,fnfb:False;n:type:ShaderForge.SFN_Final,id:7195,x:34219,y:32540,varname:node_7195,prsc:2|custl-7247-OUT,alpha-4367-OUT,clip-6377-OUT;n:type:ShaderForge.SFN_Color,id:1107,x:32898,y:32351,ptovrint:False,ptlb:MainColor,ptin:_MainColor,varname:node_1107,prsc:2,glob:False,taghide:False,taghdr:True,tagprd:False,tagnsco:False,tagnrm:False,c1:0.5,c2:0.5,c3:1,c4:1;n:type:ShaderForge.SFN_TexCoord,id:1357,x:32304,y:33056,varname:node_1357,prsc:2,uv:0;n:type:ShaderForge.SFN_Slider,id:5069,x:32320,y:33369,ptovrint:False,ptlb:CutValue,ptin:_CutValue,varname:node_5069,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:1,max:1;n:type:ShaderForge.SFN_OneMinus,id:6516,x:32508,y:33076,varname:node_6516,prsc:2|IN-1357-U;n:type:ShaderForge.SFN_Tex2d,id:8166,x:33074,y:32767,ptovrint:False,ptlb:MainTex,ptin:_MainTex,varname:node_8166,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,ntxv:0,isnm:False|UVIN-8480-OUT;n:type:ShaderForge.SFN_Add,id:3737,x:32929,y:33172,varname:node_3737,prsc:2|A-9539-OUT,B-5069-OUT;n:type:ShaderForge.SFN_Clamp01,id:6377,x:33081,y:33092,varname:node_6377,prsc:2|IN-3737-OUT;n:type:ShaderForge.SFN_Subtract,id:9539,x:32747,y:33032,varname:node_9539,prsc:2|A-6516-OUT,B-7751-OUT;n:type:ShaderForge.SFN_Vector1,id:7751,x:32508,y:33215,varname:node_7751,prsc:2,v1:0.5;n:type:ShaderForge.SFN_TexCoord,id:1556,x:31933,y:32693,varname:node_1556,prsc:2,uv:0;n:type:ShaderForge.SFN_Add,id:8480,x:32649,y:32726,varname:node_8480,prsc:2|A-2132-OUT,B-915-OUT;n:type:ShaderForge.SFN_Slider,id:1546,x:32038,y:32504,ptovrint:False,ptlb:SecondScale,ptin:_SecondScale,varname:node_1546,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0.3931624,max:1;n:type:ShaderForge.SFN_Multiply,id:8057,x:32403,y:32500,varname:node_8057,prsc:2|A-476-OUT,B-1546-OUT;n:type:ShaderForge.SFN_Vector1,id:476,x:32315,y:32429,varname:node_476,prsc:2,v1:0.5;n:type:ShaderForge.SFN_Subtract,id:915,x:32607,y:32483,varname:node_915,prsc:2|A-476-OUT,B-8057-OUT;n:type:ShaderForge.SFN_Multiply,id:2132,x:32283,y:32718,varname:node_2132,prsc:2|A-1556-UVOUT,B-1546-OUT;n:type:ShaderForge.SFN_Color,id:6611,x:32912,y:32160,ptovrint:False,ptlb:OutSideColor,ptin:_OutSideColor,varname:node_6611,prsc:2,glob:False,taghide:False,taghdr:True,tagprd:False,tagnsco:False,tagnrm:False,c1:1,c2:1,c3:1,c4:1;n:type:ShaderForge.SFN_Lerp,id:7247,x:33186,y:32306,varname:node_7247,prsc:2|A-6611-RGB,B-1107-RGB,T-8166-R;n:type:ShaderForge.SFN_Multiply,id:4367,x:33532,y:32796,varname:node_4367,prsc:2|A-1107-A,B-8166-R;proporder:8166-1107-5069-1546-6611;pass:END;sub:END;*/ Shader "Custom/CutLineShader" {
Properties {
_MainTex ("MainTex", 2D) = "white" {}
[HDR]_MainColor ("MainColor", Color) = (0.5,0.5,,)
_CutValue ("CutValue", Range(, )) =
_SecondScale ("SecondScale", Range(, )) = 0.3931624
[HDR]_OutSideColor ("OutSideColor", Color) = (,,,)
[HideInInspector]_Cutoff ("Alpha cutoff", Range(,)) = 0.5
}
SubShader {
Tags {
"IgnoreProjector"="True"
"Queue"="Transparent"
"RenderType"="Transparent"
}
LOD
Pass {
Name "FORWARD"
Tags {
"LightMode"="ForwardBase"
}
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define UNITY_PASS_FORWARDBASE
#include "UnityCG.cginc"
#pragma multi_compile_fwdbase
#pragma multi_compile_fog
#pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2
#pragma target 3.0
uniform float4 _MainColor;
uniform float _CutValue;
uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
uniform float _SecondScale;
uniform float4 _OutSideColor;
struct VertexInput {
float4 vertex : POSITION;
float2 texcoord0 : TEXCOORD0;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
UNITY_FOG_COORDS()
};
VertexOutput vert (VertexInput v) {
VertexOutput o = (VertexOutput);
o.uv0 = v.texcoord0;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex );
UNITY_TRANSFER_FOG(o,o.pos);
return o;
}
float4 frag(VertexOutput i) : COLOR {
clip(saturate((((1.0 - i.uv0.r)-0.5)+_CutValue)) - 0.5);
////// Lighting:
float node_476 = 0.5;
float2 node_8480 = ((i.uv0*_SecondScale)+(node_476-(node_476*_SecondScale)));
float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(node_8480, _MainTex));
float3 finalColor = lerp(_OutSideColor.rgb,_MainColor.rgb,_MainTex_var.r);
fixed4 finalRGBA = fixed4(finalColor,(_MainColor.a*_MainTex_var.r));
UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
return finalRGBA;
}
ENDCG
}
Pass {
Name "ShadowCaster"
Tags {
"LightMode"="ShadowCaster"
}
Offset , CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define UNITY_PASS_SHADOWCASTER
#include "UnityCG.cginc"
#include "Lighting.cginc"
#pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_shadowcaster
#pragma multi_compile_fog
#pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2
#pragma target 3.0
uniform float _CutValue;
struct VertexInput {
float4 vertex : POSITION;
float2 texcoord0 : TEXCOORD0;
};
struct VertexOutput {
V2F_SHADOW_CASTER;
float2 uv0 : TEXCOORD1;
};
VertexOutput vert (VertexInput v) {
VertexOutput o = (VertexOutput);
o.uv0 = v.texcoord0;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex );
TRANSFER_SHADOW_CASTER(o)
return o;
}
float4 frag(VertexOutput i) : COLOR {
clip(saturate((((1.0 - i.uv0.r)-0.5)+_CutValue)) - 0.5);
SHADOW_CASTER_FRAGMENT(i)
}
ENDCG
}
}
FallBack "Diffuse"
CustomEditor "ShaderForgeMaterialInspector"
}

杂谈:

  这个画线我还是花了点心血的~(T.T因为公司的项目核心就是这个鬼东西)。

  最开始画线想的比较简单,直接用UISprite摆就好,结果摆出来的断面太明显了。而且一旦角度越刁钻断面就越明显。

  后来采用建模的方式来创建线段,开头一切顺利,包括三角面创建,单面渲染等等,第一版本出来是这样的:

  画线代码V1.0.0

  脚大马爹,这是什么鬼,为啥线又粗有细,经过我的仔细分析:

画线代码V1.0.0  

可以很明显的看书 1 和 2线长度完全不相同,当然横向的线比斜向的线粗很多咯,所以我后来引入了2维直线一般式,用直线2元一次方程求解的方式计算交点,完美的解决了线的问题,最后出来的效果就是效果图的效果了。

这里为了排线也是很花了点功夫,见下图:

画线代码V1.0.0

不要问这是什么!我是不会说的。End!

画线代码V1.0.0的更多相关文章

  1. OpenGL进阶演示样例1——动态画线(虚线、实线、颜色、速度等)

            用OpenGL动态绘制线段.事实上非常easy,但到如今为止.网上可參考资料并不多. 于是亲自己主动手写一个函数,方便动态绘制线段.代码例如以下: #include<GL/glu ...

  2. 阿里官方Java代码规范标准《阿里巴巴Java开发手册 终极版 v1&period;3&period;0》

    终极版 v1.3.0 2017年开春之际,阿里诚意献上重磅大礼:<阿里巴巴Java开发手册>,首次公开阿里官方Java代码规范标准.这套Java统一规范标准将有助于提高行业编码规范化水平, ...

  3. Hyperledger Fabric&lpar;v1&period;2&period;0&rpar;代码分析1——channel创建

    Hyperledger Fabric(v1.2.0)代码分析1--channel创建 0. e2e_cli Hyperledger Fabric提供了一个e2e的例子,该例中创建了一个基础的区块链网络 ...

  4. 读阿里巴巴Java开发手册v1&period;2&period;0之工程结构有感【架构篇】

    首先,把昨天那俩条sql语句的优化原因给大家补充一下,第一条效率极低,第二条优化后的,sql语句截图如下: 经过几个高手的评论和个人的分析: 第一条sql语句查询很慢是因为它首先使用了in关键字查询, ...

  5. RapidJSON v1&period;1&period;0 发布简介

    时隔 15.6 个月,终于发布了一个新版本 v1.1.0. 新版本除了包含了这些日子收集到的无数的小改进及 bug fixes,也有一些新功能.本文尝试从使用者的角度,简单介绍一下这些功能和沿由. P ...

  6. 仅仅需手动添加一行代码就可以让Laravel4执行在SAE &lpar;v&period; 1&period;0&period;0&rpar;

    Github:https://github.com/chariothy/laravel4-sae (已更新至v1.1.0) laravel4-sae (v. 1.0.0) 仅仅需手动添加一行代码就可以 ...

  7. 读阿里巴巴Java开发手册v1&period;2&period;0之编程规约有感【架构篇】

     不为过去蹉跎,改变当下. 为什么开篇就送这么一句话给大家,我相信很多处于1-3年码龄的哥们儿们,在平时的编码历程中编码的个性可能是多彩的,每个人都有每个人特定的风格,但是我们现在这么随意写,以后这么 ...

  8. CentOS 7&period;4 安装 K8S v1&period;11&period;0 集群所遇到的问题

    0.引言 最近打算将现有项目的 Docker 部署到阿里云上面,但是之前是单机部署,现在阿里云上面有 3 台机器,所以想做一个 Docker 集群.之前考虑是用 Docker Swarm 来做这个事情 ...

  9. React多页面应用脚手架-v1&period;3&period;0

    react-multi-page-app是一个基于react和webpack的多页面应用架构,通过编译生成对应目录结构清晰的静态页面,实现多页面便捷开发维护.1.3.0 版本对项目整体做了一个全面的升 ...

随机推荐

  1. 解决因为使用了官方xbean-2&period;4&period;0&period;jar 的库造成的性能问题

    最近我们游戏经常收到玩家投诉卡进度条的问题.而且后台显示执行队列和CPU使用率异常高 根据调用的JDB分析出 使用xbean 时候会调用以下代码 在设置xmlobject 时候会有一个 GlobalL ...

  2. 浅谈c语言结构体

    对于很多非计算机专业来说,c语言课程基本上指针都不怎么讲,更别说后面的结构体了.这造成很多学生对结构体的不熟悉.这里我就浅谈一下我对结构体的认识. 结构体,就是我们自己定义出一种新的类型,定义好之后, ...

  3. 该应用的登录功能版本较旧,无法使用QQ账号登录,请升级到最新版本,如果还无法解决,请联系开发者升级。(错误码:100044)

    该原因应该是你的应用数据签名更改的原因 解决步骤已经写到我的公众号,二维码在下面. 欢迎观看我的CSDN学院课程,地址:http://edu.csdn.net/course/detail/2877 本 ...

  4. 越狱Season 1-Season 1&comma; Episode 3&colon; Cell Test

    Season 1, Episode 3: Cell Test -CO: Oh, my God. 我的天 Williamson, get in here. Williamson 快进来 What the ...

  5. Android&colon; 在native中访问assets全解析

    本文总结在Android Native C++开发中访问APK中的assets资源的方法 在CMake中添加相关NDK LIB的 依赖 因为我们接下来用到的一些函数实现在NDK库libandroid. ...

  6. 不要62&lpar;数位DP&rpar;

    不要62 http://acm.hdu.edu.cn/showproblem.php?pid=2089 Time Limit: 1000/1000 MS (Java/Others)    Memory ...

  7. JVM工具jcmd实践

    暂时参考以下链接,后续补充自己的实践. https://www.jianshu.com/p/388e35d8a09b

  8. Keepalived安装后出现的问题总结

    1. 在配好主从备份之后,发现虚拟IP能ping通,但是访问虚拟IP对应机器上的服务(不是apache或者mysql之类的公用软件)却不成功,这是因为要访问的服务绑定了主机上的一个实体IP不是INAD ...

  9. Oracle获取session的trace

    1. 使用参数SQL_TRACE 下面是官网对此参数的说明 SQL_TRACE Property Description Parameter type Boolean Default value fa ...

  10. openstack self-service 实例 连接外网数据表流程

    我的openstack的架构是最简单的controller-compute架构,在provider基础上创建self-service  self-service的实例上外网的流量走向 登陆实例,pin ...