码迷,mamicode.com
首页 > 其他好文 > 详细

画线代码V1.0.0

时间:2018-08-20 12:24:01      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:osi   角度   ntop   component   htm   const   section   画线   技术分享   

画线代码:

  最终效果图:

技术分享图片

优点:

  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(0, 0, -1);

            //安全校验
            if (_v.Length < 2)
                return null;

            //开堆
            Vector3[] r = new Vector3[_v.Length * 2];

            //第一个点
            Vector3 temp0 = Vector3.Cross(tempN, _v[1] - _v[0]).normalized * _width;
            r[0] = temp0 + _v[0];
            r[1] = r[0] - 2 * temp0;

            //后面(除最后一个)的点
            JWLineA lineA = new JWLineA();
            JWLineA lineB = new JWLineA();
            for (int i = 1; i < _v.Length - 1; ++i)
            {
                //第一根线
                lineA.SetLine(r[2 * (i - 1)], _v[i] - _v[i - 1]);

                //第二根线
                Vector3 temp1 = _v[i + 1] - _v[i];
                Vector3 dot = _v[i] +  Vector3.Cross(tempN, temp1).normalized * _width;
                lineB.SetLine(dot, temp1);

                //计算交点
                r[i * 2]        = JWLineA.GetIntersectionPoint(lineA, lineB, dot);
                r[i * 2 + 1]    = r[i * 2] + 2 * (_v[i] - r[i * 2]);
            }

            //最后一个点
            Vector3 temp2 = Vector3.Cross(tempN, _v[_v.Length - 1] - _v[_v.Length - 2]).normalized * _width;
            r[(_v.Length - 1) * 2]      = temp2 + _v[_v.Length - 1];
            r[(_v.Length - 1) * 2 + 1]  = -temp2 + _v[_v.Length - 1];

            return r;
        }

        //得到三角面
        private static int[] GetTri(int _vc)
        {
            //计算三角面个数
            int tc = (_vc - 2) * 3 * 2;
            int[] r = new int[tc];

            for (int i = 0,j = 0 ; i < _vc - 2; i += 2, j += 6)
            {
                r[j + 0] = i + 0;
                r[j + 1] = i + 1;
                r[j + 2] = i + 3;

                r[j + 3] = i + 0;
                r[j + 4] = i + 3;
                r[j + 5] = i + 2;
            }

            return r;
        }

        //得到顶点法线
        private static Vector3[] GetNor(int _vc)
        {
            Vector3[] r = new Vector3[_vc];
            for (int i = 0; i < r.Length; ++i)
                r[i] = new Vector3(0, 0, -1);
            return r;
        }

        //得到UV
        private static Vector2[] GetUV(int _vc)
        {
            Vector2[] r = new Vector2[_vc];

            for (int i = 0; i < _vc; ++i)
            {
                r[i].x = 1.0f / _vc * 2 * (i / 2) ;
                r[i].y = i % 2;
            }

            return r;
        }

        //绘制Mesh
        public GameObject CreatObject(string _name, Mesh _mesh, Material _material, float _z = 0, 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 == 0)
                obj.transform.localPosition = Vector3.zero;
            else
                obj.transform.localPosition = new Vector3(0, 0, _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 % 2 == 0)
            {
                num = -1;
            }
            else
            {
                num = 1;
            }

            BA.Normalize(); //只是使两个向量同长,方便求角平分线向量
            BC.Normalize();

            Vector3 BB = (BA + BC) / 2; //角平分线向量

            BB.Normalize(); //长度变1

            int q = getQuadrant(A, B, C); //通过三个点的分布,知道r1 r2哪一个在内角,哪一个是外折角

            if (q == 3 || q == 4)
            {
                r2 = BB * (w / 2); //折角处的一个点
                r1 = -r2;  //原点对面的对称折点

                r1 *= num;
                r2 *= num;

                //平移回原坐标系
                r1 += B;
                r2 += B;
            }
            else
            {
                r1 = BB * (w / 2); //折角处的一个点
                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 / 180 * Mathf.PI;
            }
            //2像限
            else if (A.x <= B.x && A.y >= B.y)
            {
                ang = Vector3.Angle(A - B, Vector3.left);
                ang = ang / 180 * Mathf.PI;
            }
            else if (A.x <= B.x && A.y <= B.y)
            {
                ang = Vector3.Angle(A - B, Vector3.left);
                ang = (360 - ang) / 180 * Mathf.PI;
            }
            //4像限
            else
            {
                ang = Vector3.Angle(A - B, Vector3.left);
                ang = (360 - ang) / 180 * 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 >= 0 && y >= 0)
                return 1;
            if (x <= 0 && y >= 0)
                return 2;
            if (x <= 0 && y <= 0)
                return 3;

            return 4;
        }
    }
}
View Code
技术分享图片
/***************************************
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[7];
            GameObject[] m_linesObjs = new GameObject[30];
            m_mylines = new MyLine[30];
            for (int i = 0; i < m_mylines.Length; ++i)
                m_mylines[i] = new MyLine();


            // ----- 第一条线 -----
            ps2[0].x = -399; ps2[0].y = 0;
            ps2[1].x = -315; ps2[1].y = 0;
            ps2[2].x = -157.5f; ps2[2].y = 0;
            ps2[3].x = 0; ps2[3].y = 0;
            ps2[4].x = 157.5f; ps2[4].y = 0;
            ps2[5].x = 315; ps2[5].y = 0;
            ps2[6].x = 399; ps2[6].y = 0;

            //创建模型
            Mesh mesh0 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[0] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line0", mesh0, m_materials[0], 0, transform);
            m_linesObjs[0].layer = Const_ZQFY.Layer_Line;
            m_mylines[0].m_line = m_linesObjs[0];
            m_mylines[0].m_leftLight = m_leftLights[15];
            m_mylines[0].m_rightLight = m_rightLights[15];


            // ----- 第二条线 -----
            ps2[0].x = -399; ps2[0].y = 95f;
            ps2[1].x = -315; ps2[1].y = 95f;
            ps2[2].x = -157.5f; ps2[2].y = 95f;
            ps2[3].x = 0; ps2[3].y = 95f;
            ps2[4].x = 157.5f; ps2[4].y = 95f;
            ps2[5].x = 315; ps2[5].y = 95f;
            ps2[6].x = 399; ps2[6].y = 95f;

            //创建模型
            Mesh mesh1 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[1] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line1", mesh1, m_materials[1], 0, transform);
            m_linesObjs[1].layer = Const_ZQFY.Layer_Line;
            m_mylines[1].m_line = m_linesObjs[1];
            m_mylines[1].m_leftLight = m_leftLights[5];
            m_mylines[1].m_rightLight = m_rightLights[5];

            // ----- 第三条线 -----
            ps2[0].x = -399; ps2[0].y = -95f;
            ps2[1].x = -315; ps2[1].y = -95f;
            ps2[2].x = -157.5f; ps2[2].y = -95f;
            ps2[3].x = 0; ps2[3].y = -95f;
            ps2[4].x = 157.5f; ps2[4].y = -95f;
            ps2[5].x = 315; ps2[5].y = -95f;
            ps2[6].x = 399; ps2[6].y = -95f;

            //创建模型
            Mesh mesh2 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[2] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line2", mesh2, m_materials[2], 0, transform);
            m_linesObjs[2].layer = Const_ZQFY.Layer_Line;
            m_mylines[2].m_line = m_linesObjs[2];
            m_mylines[2].m_leftLight = m_leftLights[25];
            m_mylines[2].m_rightLight = m_rightLights[25];


            // ----- 第四条线 -----
            ps2[0].x = -399; ps2[0].y = 104.5f;
            ps2[1].x = -315; ps2[1].y = 104.5f;
            ps2[2].x = -157.5f; ps2[2].y = 0f;
            ps2[3].x = 0; ps2[3].y = -104.5f;
            ps2[4].x = 157.5f; ps2[4].y = 0f;
            ps2[5].x = 315; ps2[5].y = 104.5f;
            ps2[6].x = 399; ps2[6].y = 104.5f;

            //创建模型
            Mesh mesh3 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[3] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line3", mesh3, m_materials[3], 0, transform);
            m_linesObjs[3].layer = Const_ZQFY.Layer_Line;
            m_mylines[3].m_line = m_linesObjs[3];
            m_mylines[3].m_leftLight = m_leftLights[4];
            m_mylines[3].m_rightLight = m_rightLights[4];

            // ----- 第五条线 -----
            ps2[0].x = -399; ps2[0].y = -104.5f;
            ps2[1].x = -315; ps2[1].y = -104.5f;
            ps2[2].x = -157.5f; ps2[2].y = 0f;
            ps2[3].x = 0; ps2[3].y = 104.5f;
            ps2[4].x = 157.5f; ps2[4].y = 0f;
            ps2[5].x = 315; ps2[5].y = -104.5f;
            ps2[6].x = 399; ps2[6].y = -104.4f;

            //创建模型
            Mesh mesh4 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[4] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line4", mesh4, m_materials[4], 0, transform);
            m_linesObjs[4].layer = Const_ZQFY.Layer_Line;
            m_mylines[4].m_line = m_linesObjs[4];
            m_mylines[4].m_leftLight = m_leftLights[26];
            m_mylines[4].m_rightLight = m_rightLights[26];

            // ----- 第六条线 -----
            ps2[0].x = -399; ps2[0].y = 38f;
            ps2[1].x = -315; ps2[1].y = 38f;
            ps2[2].x = -157.5f; ps2[2].y = 123.5f;
            ps2[3].x = 0; ps2[3].y = 123.5f;
            ps2[4].x = 157.5f; ps2[4].y = 123.5f;
            ps2[5].x = 315; ps2[5].y = 38f;
            ps2[6].x = 399; ps2[6].y = 38f;

            //创建模型
            Mesh mesh5 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[5] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line5", mesh5, m_materials[5], 0, transform);
            m_linesObjs[5].layer = Const_ZQFY.Layer_Line;
            m_mylines[5].m_line = m_linesObjs[5];
            m_mylines[5].m_leftLight = m_leftLights[11];
            m_mylines[5].m_rightLight = m_rightLights[11];

            // ----- 第七条线 -----
            ps2[0].x = -399; ps2[0].y = -38f;
            ps2[1].x = -315; ps2[1].y = -38f;
            ps2[2].x = -157.5f; ps2[2].y = -123.5f;
            ps2[3].x = 0; ps2[3].y = -123.5f;
            ps2[4].x = 157.5f; ps2[4].y = -123.5f;
            ps2[5].x = 315; ps2[5].y = -38f;
            ps2[6].x = 399; ps2[6].y = -38f;

            //创建模型
            Mesh mesh6 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[6] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line6", mesh6, m_materials[6], 0, transform);
            m_linesObjs[6].layer = Const_ZQFY.Layer_Line;
            m_mylines[6].m_line = m_linesObjs[6];
            m_mylines[6].m_leftLight = m_leftLights[19];
            m_mylines[6].m_rightLight = m_rightLights[19];

            // ----- 第八条线 -----
            ps2[0].x = -399; ps2[0].y = 142.5f;
            ps2[1].x = -315; ps2[1].y = 142.5f;
            ps2[2].x = -157.5f; ps2[2].y = 142.5f;
            ps2[3].x = 0; ps2[3].y = 0f;
            ps2[4].x = 157.5f; ps2[4].y = -142.5f;
            ps2[5].x = 315; ps2[5].y = -142.5f;
            ps2[6].x = 399; ps2[6].y = -142.5f;

            //创建模型
            Mesh mesh7 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[7] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line7", mesh7, m_materials[7], 0, transform);
            m_linesObjs[7].layer = Const_ZQFY.Layer_Line;
            m_mylines[7].m_line = m_linesObjs[7];
            m_mylines[7].m_leftLight = m_leftLights[0];
            m_mylines[7].m_rightLight = m_rightLights[30];

            // ----- 第九条线 -----
            ps2[0].x = -399; ps2[0].y = -142.5f;
            ps2[1].x = -315; ps2[1].y = -142.5f;
            ps2[2].x = -157.5f; ps2[2].y = -142.5f;
            ps2[3].x = 0; ps2[3].y = 0f;
            ps2[4].x = 157.5f; ps2[4].y = 142.5f;
            ps2[5].x = 315; ps2[5].y = 142.5f;
            ps2[6].x = 399; ps2[6].y = 142.5f;

            //创建模型
            Mesh mesh8 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[8] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line8", mesh8, m_materials[8], 0, transform);
            m_linesObjs[8].layer = Const_ZQFY.Layer_Line;
            m_mylines[8].m_line = m_linesObjs[8];
            m_mylines[8].m_leftLight = m_leftLights[30];
            m_mylines[8].m_rightLight = m_rightLights[0];

            // ----- 第十条线 -----
            ps2[0].x = -399; ps2[0].y = -28.5f;
            ps2[1].x = -315; ps2[1].y = -28.5f;
            ps2[2].x = -157.5f; ps2[2].y = -114f;
            ps2[3].x = 0; ps2[3].y = 0f;
            ps2[4].x = 157.5f; ps2[4].y = 114f;
            ps2[5].x = 315; ps2[5].y = -28.5f;
            ps2[6].x = 399; ps2[6].y = -28.5f;

            //创建模型
            Mesh mesh9 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[9] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line9", mesh9, m_materials[9], 0, transform);
            m_linesObjs[9].layer = Const_ZQFY.Layer_Line;
            m_mylines[9].m_line = m_linesObjs[9];
            m_mylines[9].m_leftLight = m_leftLights[18];
            m_mylines[9].m_rightLight = m_rightLights[18];

            // ----- 第十一条线 -----
            ps2[0].x = -399; ps2[0].y = 28.5f;
            ps2[1].x = -315; ps2[1].y = 28.5f;
            ps2[2].x = -157.5f; ps2[2].y = 114f;
            ps2[3].x = 0; ps2[3].y = 0;
            ps2[4].x = 157.5f; ps2[4].y = -114f;
            ps2[5].x = 315; ps2[5].y = 28.5f;
            ps2[6].x = 399; ps2[6].y = 28.5f;

            //创建模型
            Mesh mesh10 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[10] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line10", mesh10, m_materials[10], 0, transform);
            m_linesObjs[10].layer = Const_ZQFY.Layer_Line;
            m_mylines[10].m_line = m_linesObjs[10];
            m_mylines[10].m_leftLight = m_leftLights[12];
            m_mylines[10].m_rightLight = m_rightLights[12];

            // ----- 第十二条线 -----
            ps2[0].x = -399; ps2[0].y = 123.5f;
            ps2[1].x = -315; ps2[1].y = 123.5f;
            ps2[2].x = -157.5f; ps2[2].y = 38f;
            ps2[3].x = 0; ps2[3].y = 38f;
            ps2[4].x = 157.5f; ps2[4].y = 38f;
            ps2[5].x = 315; ps2[5].y = 123.5f;
            ps2[6].x = 399; ps2[6].y = 123.5f;

            //创建模型
            Mesh mesh11 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[11] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line11", mesh11, m_materials[11], 0, transform);
            m_linesObjs[11].layer = Const_ZQFY.Layer_Line;
            m_mylines[11].m_line = m_linesObjs[11];
            m_mylines[11].m_leftLight = m_leftLights[2];
            m_mylines[11].m_rightLight = m_rightLights[2];


            // ----- 第十三条线 -----
            ps2[0].x = -399; ps2[0].y = -123.5f;
            ps2[1].x = -315; ps2[1].y = -123.5f;
            ps2[2].x = -157.5f; ps2[2].y = -38f;
            ps2[3].x = 0; ps2[3].y = -38f;
            ps2[4].x = 157.5f; ps2[4].y = -38f;
            ps2[5].x = 315; ps2[5].y = -123.5f;
            ps2[6].x = 399; ps2[6].y = -123.5f;

            //创建模型
            Mesh mesh12 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[12] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line12", mesh12, m_materials[12], 0, transform);
            m_linesObjs[12].layer = Const_ZQFY.Layer_Line;
            m_mylines[12].m_line = m_linesObjs[12];
            m_mylines[12].m_leftLight = m_leftLights[28];
            m_mylines[12].m_rightLight = m_rightLights[28];


            // ----- 第十四条线 -----
            ps2[0].x = -399; ps2[0].y = 114f;
            ps2[1].x = -315; ps2[1].y = 114f;
            ps2[2].x = -157.5f; ps2[2].y = 28.5f;
            ps2[3].x = 0; ps2[3].y = 114f;
            ps2[4].x = 157.5f; ps2[4].y = 28.5f;
            ps2[5].x = 315; ps2[5].y = 114f;
            ps2[6].x = 399; ps2[6].y = 114f;

            //创建模型
            Mesh mesh13 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[13] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line13", mesh13, m_materials[13], 0, transform);
            m_linesObjs[13].layer = Const_ZQFY.Layer_Line;
            m_mylines[13].m_line = m_linesObjs[13];
            m_mylines[13].m_leftLight = m_leftLights[3];
            m_mylines[13].m_rightLight = m_rightLights[3];

            // ----- 第十五条线 -----
            ps2[0].x = -399; ps2[0].y = -114f;
            ps2[1].x = -315; ps2[1].y = -114f;
            ps2[2].x = -157.5f; ps2[2].y = -28.5f;
            ps2[3].x = 0; ps2[3].y = -114f;
            ps2[4].x = 157.5f; ps2[4].y = -28.5f;
            ps2[5].x = 315; ps2[5].y = -114f;
            ps2[6].x = 399; ps2[6].y = -114f;

            //创建模型
            Mesh mesh14 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[14] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line14", mesh14, m_materials[14], 0, transform);
            m_linesObjs[14].layer = Const_ZQFY.Layer_Line;
            m_mylines[14].m_line = m_linesObjs[14];
            m_mylines[14].m_leftLight = m_leftLights[27];
            m_mylines[14].m_rightLight = m_rightLights[27];

            // ----- 第十六条线 -----
            ps2[0].x = -399; ps2[0].y = 19f;
            ps2[1].x = -315; ps2[1].y = 19f;
            ps2[2].x = -157.5f; ps2[2].y = 19f;
            ps2[3].x = 0; ps2[3].y = 66.5f;
            ps2[4].x = 157.5f; ps2[4].y = 19f;
            ps2[5].x = 315; ps2[5].y = 19f;
            ps2[6].x = 399; ps2[6].y = 19f;

            //创建模型
            Mesh mesh15 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[15] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line15", mesh15, m_materials[15], 0, transform);
            m_linesObjs[15].layer = Const_ZQFY.Layer_Line;
            m_mylines[15].m_line = m_linesObjs[15];
            m_mylines[15].m_leftLight = m_leftLights[13];
            m_mylines[15].m_rightLight = m_rightLights[13];

            // ----- 第十七条线 -----
            ps2[0].x = -399; ps2[0].y = -19f;
            ps2[1].x = -315; ps2[1].y = -19f;
            ps2[2].x = -157.5f; ps2[2].y = -19f;
            ps2[3].x = 0; ps2[3].y = -66.5f;
            ps2[4].x = 157.5f; ps2[4].y = -19f;
            ps2[5].x = 315; ps2[5].y = -19f;
            ps2[6].x = 399; ps2[6].y = -19f;

            //创建模型
            Mesh mesh16 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[16] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line16", mesh16, m_materials[16], 0, transform);
            m_linesObjs[16].layer = Const_ZQFY.Layer_Line;
            m_mylines[16].m_line = m_linesObjs[16];
            m_mylines[16].m_leftLight = m_leftLights[17];
            m_mylines[16].m_rightLight = m_rightLights[17];

            // ----- 第十八条线 -----
            ps2[0].x = -399; ps2[0].y = 133f;
            ps2[1].x = -315; ps2[1].y = 133f;
            ps2[2].x = -157.5f; ps2[2].y = 133f;
            ps2[3].x = 0; ps2[3].y = -133f;
            ps2[4].x = 157.5f; ps2[4].y = 133f;
            ps2[5].x = 315; ps2[5].y = 133f;
            ps2[6].x = 399; ps2[6].y = 133f;

            //创建模型
            Mesh mesh17 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[17] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line17", mesh17, m_materials[17], 0, transform);
            m_linesObjs[17].layer = Const_ZQFY.Layer_Line;
            m_mylines[17].m_line = m_linesObjs[17];
            m_mylines[17].m_leftLight = m_leftLights[1];
            m_mylines[17].m_rightLight = m_rightLights[1];

            // ----- 第十九条线 -----
            ps2[0].x = -399; ps2[0].y = -133f;
            ps2[1].x = -315; ps2[1].y = -133f;
            ps2[2].x = -157.5f; ps2[2].y = -133f;
            ps2[3].x = 0; ps2[3].y = 133f;
            ps2[4].x = 157.5f; ps2[4].y = -133f;
            ps2[5].x = 315; ps2[5].y = -133f;
            ps2[6].x = 399; ps2[6].y = -133f;

            //创建模型
            Mesh mesh18 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[18] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line18", mesh18, m_materials[18], 0, transform);
            m_linesObjs[18].layer = Const_ZQFY.Layer_Line;
            m_mylines[18].m_line = m_linesObjs[18];
            m_mylines[18].m_leftLight = m_leftLights[29];
            m_mylines[18].m_rightLight = m_rightLights[29];

            // ----- 第二十条线 -----
            ps2[0].x = -399; ps2[0].y = 85.5f;
            ps2[1].x = -315; ps2[1].y = 85.5f;
            ps2[2].x = -157.5f; ps2[2].y = -57.5f;
            ps2[3].x = 0; ps2[3].y = -57.5f;
            ps2[4].x = 157.5f; ps2[4].y = -57.5f;
            ps2[5].x = 315; ps2[5].y = 85.5f;
            ps2[6].x = 399; ps2[6].y = 85.5f;

            //创建模型
            Mesh mesh19 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[19] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line19", mesh19, m_materials[19], 0, transform);
            m_linesObjs[19].layer = Const_ZQFY.Layer_Line;
            m_mylines[19].m_line = m_linesObjs[19];
            m_mylines[19].m_leftLight = m_leftLights[6];
            m_mylines[19].m_rightLight = m_rightLights[6];

            // ----- 第二十一条线 -----
            ps2[0].x = -399; ps2[0].y = -85.5f;
            ps2[1].x = -315; ps2[1].y = -85.5f;
            ps2[2].x = -157.5f; ps2[2].y = 57.5f;
            ps2[3].x = 0; ps2[3].y = 57.5f;
            ps2[4].x = 157.5f; ps2[4].y = 57.5f;
            ps2[5].x = 315; ps2[5].y = -85.5f;
            ps2[6].x = 399; ps2[6].y = -85.5f;

            //创建模型
            Mesh mesh20 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[20] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line20", mesh20, m_materials[20], 0, transform);
            m_linesObjs[20].layer = Const_ZQFY.Layer_Line;
            m_mylines[20].m_line = m_linesObjs[20];
            m_mylines[20].m_leftLight = m_leftLights[24];
            m_mylines[20].m_rightLight = m_rightLights[24];

            // ----- 第二十二条线 -----
            ps2[0].x = -399; ps2[0].y = -9.5f;
            ps2[1].x = -315; ps2[1].y = -9.5f;
            ps2[2].x = -157.5f; ps2[2].y = -104.5f;
            ps2[3].x = 0; ps2[3].y = 142.5f;
            ps2[4].x = 157.5f; ps2[4].y = -104.5f;
            ps2[5].x = 315; ps2[5].y = -9.5f;
            ps2[6].x = 399; ps2[6].y = -9.5f;

            //创建模型
            Mesh mesh21 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[21] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line21", mesh21, m_materials[21], 0, transform);
            m_linesObjs[21].layer = Const_ZQFY.Layer_Line;
            m_mylines[21].m_line = m_linesObjs[21];
            m_mylines[21].m_leftLight = m_leftLights[16];
            m_mylines[21].m_rightLight = m_rightLights[16];

            // ----- 第二十三条线 -----
            ps2[0].x = -399; ps2[0].y = 9.5f;
            ps2[1].x = -315; ps2[1].y = 9.5f;
            ps2[2].x = -157.5f; ps2[2].y = 104.5f;
            ps2[3].x = 0; ps2[3].y = -142.5f;
            ps2[4].x = 157.5f; ps2[4].y = 104.5f;
            ps2[5].x = 315; ps2[5].y = 9.5f;
            ps2[6].x = 399; ps2[6].y = 9.5f;

            //创建模型
            Mesh mesh22 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[22] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line22", mesh22, m_materials[22], 0, transform);
            m_linesObjs[22].layer = Const_ZQFY.Layer_Line;
            m_mylines[22].m_line = m_linesObjs[22];
            m_mylines[22].m_leftLight = m_leftLights[14];
            m_mylines[22].m_rightLight = m_rightLights[14];

            // ----- 第二十四条线 -----
            ps2[0].x = -399; ps2[0].y = 76f;
            ps2[1].x = -315; ps2[1].y = 76f;
            ps2[2].x = -157.5f; ps2[2].y = -76f;
            ps2[3].x = 0; ps2[3].y = 76f;
            ps2[4].x = 157.5f; ps2[4].y = -76f;
            ps2[5].x = 315; ps2[5].y = 76f;
            ps2[6].x = 399; ps2[6].y = 76f;

            //创建模型
            Mesh mesh23 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[23] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line23", mesh23, m_materials[23], 0, transform);
            m_linesObjs[23].layer = Const_ZQFY.Layer_Line;
            m_mylines[23].m_line = m_linesObjs[23];
            m_mylines[23].m_leftLight = m_leftLights[7];
            m_mylines[23].m_rightLight = m_rightLights[7];


            // ----- 第二十五条线 -----
            ps2[0].x = -399; ps2[0].y = -76f;
            ps2[1].x = -315; ps2[1].y = -76f;
            ps2[2].x = -157.5f; ps2[2].y = 76f;
            ps2[3].x = 0; ps2[3].y = -76f;
            ps2[4].x = 157.5f; ps2[4].y = 76f;
            ps2[5].x = 315; ps2[5].y = -76f;
            ps2[6].x = 399; ps2[6].y = -76f;

            //创建模型
            Mesh mesh24 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[24] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line24", mesh24, m_materials[24], 0, transform);
            m_linesObjs[24].layer = Const_ZQFY.Layer_Line;
            m_mylines[24].m_line = m_linesObjs[24];
            m_mylines[24].m_leftLight = m_leftLights[23];
            m_mylines[24].m_rightLight = m_rightLights[23];

            // ----- 第二十六条线 -----
            ps2[0].x = -399; ps2[0].y = -66.5f;
            ps2[1].x = -315; ps2[1].y = -66.5f;
            ps2[2].x = -157.5f; ps2[2].y = 66.5f;
            ps2[3].x = 0; ps2[3].y = 0f;
            ps2[4].x = 157.5f; ps2[4].y = -66.5f;
            ps2[5].x = 315; ps2[5].y = 66.5f;
            ps2[6].x = 399; ps2[6].y = 66.5f;

            //创建模型
            Mesh mesh25 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[25] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line25", mesh25, m_materials[25], 0, transform);
            m_linesObjs[25].layer = Const_ZQFY.Layer_Line;
            m_mylines[25].m_line = m_linesObjs[25];
            m_mylines[25].m_leftLight = m_leftLights[22];
            m_mylines[25].m_rightLight = m_rightLights[8];

            // ----- 第二十七条线 -----
            ps2[0].x = -399; ps2[0].y = 66.5f;
            ps2[1].x = -315; ps2[1].y = 66.5f;
            ps2[2].x = -157.5f; ps2[2].y = -66.5f;
            ps2[3].x = 0; ps2[3].y = 0f;
            ps2[4].x = 157.5f; ps2[4].y = 66.5f;
            ps2[5].x = 315; ps2[5].y = -66.5f;
            ps2[6].x = 399; ps2[6].y = -66.5f;

            //创建模型
            Mesh mesh26 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[26] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line26", mesh26, m_materials[26], 0, transform);
            m_linesObjs[26].layer = Const_ZQFY.Layer_Line;
            m_mylines[26].m_line = m_linesObjs[26];
            m_mylines[26].m_leftLight = m_leftLights[8];
            m_mylines[26].m_rightLight = m_rightLights[22];

            // ----- 第二十八条线 -----
            ps2[0].x = -399; ps2[0].y = 57f;
            ps2[1].x = -315; ps2[1].y = 57f;
            ps2[2].x = -157.5f; ps2[2].y = -85.5f;
            ps2[3].x = 0; ps2[3].y = -9.5f;
            ps2[4].x = 157.5f; ps2[4].y = -85.5f;
            ps2[5].x = 315; ps2[5].y = 57f;
            ps2[6].x = 399; ps2[6].y = 57f;

            //创建模型
            Mesh mesh27 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[27] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line27", mesh27, m_materials[27], 0, transform);
            m_linesObjs[27].layer = Const_ZQFY.Layer_Line;
            m_mylines[27].m_line = m_linesObjs[27];
            m_mylines[27].m_leftLight = m_leftLights[9];
            m_mylines[27].m_rightLight = m_rightLights[9];

            // ----- 第二十九条线 -----
            ps2[0].x = -399; ps2[0].y = -57f;
            ps2[1].x = -315; ps2[1].y = -57f;
            ps2[2].x = -157.5f; ps2[2].y = 85.5f;
            ps2[3].x = 0; ps2[3].y = 9.5f;
            ps2[4].x = 157.5f; ps2[4].y = 85.5f;
            ps2[5].x = 315; ps2[5].y = -57f;
            ps2[6].x = 399; ps2[6].y = -57f;

            //创建模型
            Mesh mesh28 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[28] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line28", mesh28, m_materials[28], 0, transform);
            m_linesObjs[28].layer = Const_ZQFY.Layer_Line;
            m_mylines[28].m_line = m_linesObjs[28];
            m_mylines[28].m_leftLight = m_leftLights[21];
            m_mylines[28].m_rightLight = m_rightLights[21];

            // ----- 第三十条线 -----
            ps2[0].x = -399; ps2[0].y = -152f;
            ps2[1].x = -315; ps2[1].y = -152f;
            ps2[2].x = -157.5f; ps2[2].y = 0f;
            ps2[3].x = 0; ps2[3].y = 152f;
            ps2[4].x = 157.5f; ps2[4].y = 152f;
            ps2[5].x = 315; ps2[5].y = 0f;
            ps2[6].x = 399; ps2[6].y = 0f;

            //创建模型
            Mesh mesh29 = JWDrawLineManager_ZQFY.CreateMesh(ps2, m_width);

            //创建GameObjects
            m_linesObjs[29] = JWDrawLineManager_ZQFY.Instance.CreatObject("Line29", mesh29, m_materials[29], 0, transform);
            m_linesObjs[29].layer = Const_ZQFY.Layer_Line;
            m_mylines[29].m_line = m_linesObjs[29];
            m_mylines[29].m_leftLight = m_leftLights[31];
            m_mylines[29].m_rightLight = m_rightLights[15];

            // 绑定Shader
            for (int i = 0; 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 = 0;

                    //灰化当前
                    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 = 0; 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 = 0; i < DataManager_ZQFY.Instance.m_awardLinesList.Count; ++i)
            {
                ShowLineGrey(DataManager_ZQFY.Instance.m_awardLinesList[i]);
            }
        }

        //隐藏所有线段
        public void FadeLines()
        {
            for (int i = 0; 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 < 0 || _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 < 0 || _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 < 0 || _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 = 0;

        private float m_timer;

        public float m_totalTime = 1;

        //开始轮播
        public void StartShowLines()
        {
            if (DataManager_ZQFY.Instance.m_awardLinesList.Count > 0 && DataManager_ZQFY.Instance.m_freeCount == 0 && DataManager_ZQFY.Instance.m_autoCount == 0)
            {
                m_showLineSwitch = true;
                m_index = 0;
                m_timer = 0;

                //第一根线显示颜色
                ShowLineColor(DataManager_ZQFY.Instance.m_awardLinesList[m_index]);

                DataManager_ZQFY.Instance.m_hideElements.Clear();
                for (int i = 0; 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 > 0)
            {
                for (int i = 0; i < DataManager_ZQFY.Instance.m_awardLinesList.Count; ++i)
                    ShowLine(DataManager_ZQFY.Instance.m_awardLinesList[i], false);

                AppFacade_ZQFY.Instance.SendNotification(Const_ZQFY.SHOWELEMENTS);
            }
        }
    }
}
View Code

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

资源包:

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

Shader图:

技术分享图片

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,1,1)
        _CutValue ("CutValue", Range(0, 1)) = 1
        _SecondScale ("SecondScale", Range(0, 1)) = 0.3931624
        [HDR]_OutSideColor ("OutSideColor", Color) = (1,1,1,1)
        [HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
    }
    SubShader {
        Tags {
            "IgnoreProjector"="True"
            "Queue"="Transparent"
            "RenderType"="Transparent"
        }
        LOD 200
        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(1)
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                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 1, 1
            
            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)0;
                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"
}
View Code

 杂谈:

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

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

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

  技术分享图片

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

技术分享图片  

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

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

技术分享图片

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

 

画线代码V1.0.0

标签:osi   角度   ntop   component   htm   const   section   画线   技术分享   

原文地址:https://www.cnblogs.com/jwv5/p/9504761.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!