Пример #1
0
        public void BuildMesh(FastLineData lineData)
        {
            Mesh mesh = new Mesh();

            Vector3[] vertices = new Vector3[lineData.linesVectors.Length * 2];
            Vector3   curVector;
            Vector3   nextVector;

            for (int i = 0; i < lineData.linesVectors.Length; i++)
            {
                // Operate only if there is a next vector, The line generator needs 2 points to generate
                if (lineData.linesVectors.Length > i + 1)
                {
                    curVector       = lineData.linesVectors[i];
                    nextVector      = lineData.linesVectors[i + 1];
                    vertices[i]     = new Vector3(curVector.x + lineData.widthMultiplyer, curVector.y, curVector.z + lineData.widthMultiplyer);
                    vertices[i + 1] = new Vector3(nextVector.x + lineData.widthMultiplyer, nextVector.y, nextVector.z + lineData.widthMultiplyer);
                    vertices[i + 2] = new Vector3(curVector.x - lineData.widthMultiplyer, curVector.y, curVector.z - lineData.widthMultiplyer);
                    vertices[i + 3] = new Vector3(nextVector.x - lineData.widthMultiplyer, nextVector.y, nextVector.z - lineData.widthMultiplyer);
                }
            }

            mesh.vertices = vertices;
            int multiplayer = lineData.linesVectors.Length - 1;

            int[] triangles = new int[6 * multiplayer];
            int   curVert   = 0;

            for (int i = 0; i < lineData.linesVectors.Length - 1; i++)
            {
                if (i != 0)
                {
                    curVert = curVert + 6;
                }
                triangles[curVert]     = 0;
                triangles[curVert + 1] = 2;
                triangles[curVert + 2] = 3;

                triangles[curVert + 3] = 3;
                triangles[curVert + 4] = 1;
                triangles[curVert + 5] = 0;
            }

            mesh.triangles = triangles;
            gameObject.AddComponent <MeshFilter>().mesh = mesh;
            curRenderer                  = gameObject.AddComponent <MeshRenderer>();
            curRenderer.material         = lineData.lineMaterial;
            curRenderer.receiveShadows   = false;
            curRenderer.sortingLayerName = EditorPrimer.GoodIdToBadUnityId(0);
            curRenderer.GetPropertyBlock(propertyBlock);
            propertyBlock.SetColor("_Color", lineData.lineColor);
            curRenderer.SetPropertyBlock(propertyBlock);
        }
Пример #2
0
 public static void CreateFastLine(FastLineData lineData)
 {
     if (lineData.parentTransform == null)
     {
         GameObject lineContainer = new GameObject("LinesContainer");
         lineContainer.transform.SetParent(lineData.parentTransform);
         lineContainer.AddComponent <LineGenerator>().BuildMesh(lineData);
     }
     else
     {
         lineData.parentTransform.gameObject.AddComponent <LineGenerator>().BuildMesh(lineData);
     }
 }
Пример #3
0
 void Start()
 {
     EditorCameraReference = CameraManager.CurrentRenderCamera.GetComponent <Camera>();
     mapHeight             = 32; // GET THE TILE SIZE FROM LOADED MAP!
     mapWidth = 32;
     if (curLineRenderer == null)
     {
         curLineRenderer = gameObject.AddComponent <LineGenerator>();
         FastLineData testLine = new FastLineData();
         testLine.linesVectors    = new Vector3[2];
         testLine.linesVectors[0] = new Vector3(-0.32f, 0, 0);
         testLine.linesVectors[1] = new Vector3(0.32f, 0, 0);
         testLine.widthMultiplyer = 0.05f;
         testLine.lineMaterial    = Resources.Load("BerrySystem/UI/UI_Color", typeof(Material)) as Material;
         testLine.lineColor       = new Color();
         curLineRenderer.BuildMesh(testLine);
     }
 }
Пример #4
0
        GameObject CreateLine(Vector2 lineStart, Vector2 lineEnd, bool isX, int gridIndex, Color targetColor)
        {
            GameObject   fastLineObj = new GameObject("GridLine" + gridIndex);
            FastLineData testLine    = new FastLineData();

            testLine.linesVectors      = new Vector3[2];
            testLine.linesVectors[0].x = lineStart.x;
            testLine.linesVectors[0].y = 0.01f;
            testLine.linesVectors[0].z = lineStart.y;
            testLine.linesVectors[1].x = lineEnd.x;
            testLine.linesVectors[1].y = 0.01f;
            testLine.linesVectors[1].z = lineEnd.y;
            testLine.widthMultiplyer   = deafultLineWidth;
            testLine.lineMaterial      = Resources.Load("BerrySystem/UI/UI_Color", typeof(Material)) as Material;
            testLine.lineColor         = targetColor;
            fastLineObj.AddComponent <LineGenerator>().BuildMesh(testLine);
            fastLineObj.transform.SetParent(GridContainer.transform);
            return(fastLineObj);
        }