Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Lines : MonoBehaviour {
- public GameObject plane;
- public bool showMain = true;
- public bool showSub = false;
- public int gridSizeX{ get{ return (_gridSizeX < 0) ? _gridSizeX = 1: _gridSizeX; } set{ _gridSizeX = value; } }
- public int gridSizeY{ get{ return (_gridSizeY < 0) ? _gridSizeY = 1: _gridSizeY; } set{ _gridSizeY = value; } }
- public int gridSizeZ{ get{ return (_gridSizeZ < 0) ? _gridSizeZ = 1: _gridSizeZ; } set{ _gridSizeZ = value; } }
- public float smallStep{ get{ return (_smallStep < 0) ? _smallStep = 1: _smallStep; } set{ _smallStep = value; } }
- public float largeStep{ get{ return (_largeStep < 0) ? _largeStep = 1: _largeStep; } set{ _largeStep = value; } }
- private int _gridSizeX = 100;
- private int _gridSizeY = 1;
- private int _gridSizeZ = 100;
- private float _smallStep = 5;
- private float _largeStep = 25;
- public float startX;
- public float startY;
- public float startZ;
- private float offsetY = 0;
- private float scrollRate = 0.1f;
- private float lastScroll = 0f;
- private Material lineMaterial;
- private Color mainColor = new Color(0f,1f,0f,1f);
- private Color subColor = new Color(0f,0.5f,0f,1f);
- private float worldOffset;
- void Start ()
- {
- worldOffset = gridSizeX/-2f;
- }
- void CreateLineMaterial()
- {
- if( !lineMaterial ) {
- lineMaterial = new Material( "Shader \"Lines/Colored Blended\" {" +
- "SubShader { Pass { " +
- " Blend SrcAlpha OneMinusSrcAlpha " +
- " ZWrite Off Cull Off Fog { Mode Off } " +
- " BindChannels {" +
- " Bind \"vertex\", vertex Bind \"color\", color }" +
- "} } }" );
- lineMaterial.hideFlags = HideFlags.HideAndDontSave;
- lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;}
- }
- void OnPostRender()
- {
- /*
- CreateLineMaterial();
- // set the current material
- lineMaterial.SetPass( 0 );
- GL.Begin( GL.LINES );
- if(showSub)
- {
- GL.Color(subColor);
- //Layers
- for(float j = 0; j <= gridSizeY; j += smallStep)
- {
- //X axis lines
- for(float i = 0; i <= gridSizeZ; i += smallStep)
- {
- GL.Vertex3(worldOffset+ startX, j + offsetY, startZ + i+worldOffset);
- GL.Vertex3(worldOffset+ gridSizeX, j + offsetY, startZ + i+worldOffset);
- }
- //Z axis lines
- for(float i = 0; i <= gridSizeX; i += smallStep)
- {
- GL.Vertex3(worldOffset+ startX + i, j + offsetY, startZ+worldOffset);
- GL.Vertex3(worldOffset+ startX + i, j + offsetY, gridSizeZ+worldOffset);
- }
- }
- //Y axis lines
- for(float i = 0; i <= gridSizeZ; i += smallStep)
- {
- for(float k = 0; k <= gridSizeX; k += smallStep)
- {
- GL.Vertex3(worldOffset+ startX + k, startY + offsetY, startZ + i+worldOffset);
- GL.Vertex3(worldOffset+ startX + k, gridSizeY + offsetY, startZ + i+worldOffset);
- }
- }
- }
- if(showMain)
- {
- GL.Color(mainColor);
- //Layers
- for(float j = 0; j <= gridSizeY; j += largeStep)
- {
- //X axis lines
- for(float i = 0; i <= gridSizeZ; i += largeStep)
- {
- GL.Vertex3(worldOffset+ startX, j + offsetY, startZ + i+worldOffset);
- GL.Vertex3(worldOffset+ gridSizeX, j + offsetY, startZ + i+worldOffset);
- }
- //Z axis lines
- for(float i = 0; i <= gridSizeX; i += largeStep)
- {
- GL.Vertex3(worldOffset+ startX + i, j + offsetY, startZ+worldOffset);
- GL.Vertex3(worldOffset+ startX + i, j + offsetY, gridSizeZ+worldOffset);
- }
- }
- //Y axis lines
- for(float i = 0; i <= gridSizeZ; i += largeStep)
- {
- for(float k = 0; k <= gridSizeX; k += largeStep)
- {
- GL.Vertex3(worldOffset+ startX + k, startY + offsetY, startZ + i+worldOffset);
- GL.Vertex3(worldOffset+ startX + k, gridSizeY + offsetY, startZ + i+worldOffset);
- }
- }
- }
- GL.End(); */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement