Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GLTest : MonoBehaviour {
static Material lineMaterial;
static void CreateLineMaterial ()
{
if (!lineMaterial){
// Unity has a built-in shader that is useful for drawing
// simple colored things.
Shader shader = Shader.Find ("Hidden/Internal-Colored");
lineMaterial = new Material (shader);
lineMaterial.hideFlags = HideFlags.HideAndDontSave;
// Turn on alpha blending
lineMaterial.SetInt ("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
lineMaterial.SetInt ("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
// Turn backface culling off
lineMaterial.SetInt ("_Cull", (int)UnityEngine.Rendering.CullMode.Off);
// Turn off depth writes
lineMaterial.SetInt ("_ZWrite", 0);
}
}
public void OnRenderObject (){
CreateLineMaterial ();
/*定型フォーマットのようなもの*/
lineMaterial.SetPass (0);
GL.PushMatrix ();
GL.MultMatrix (transform.localToWorldMatrix);
/**/
GL.Begin (GL.LINES);
GL.Color (new Color (1.0f, 1.0f, 0, 0.8f));//以下は黄色
//GL.Color (new Color (255, 255, 0, 0.8f));//0-255の書き方にすると、色鮮やかになる。正しい使用法かは不明
/*始点、終点を指定していく*/
GL.Vertex3(-4, 0, 25);
GL.Vertex3(0, 4, 25);
GL.Vertex3(0, 4, 25);
GL.Vertex3(3, 7, 25);
GL.Vertex3(3, 7, 25);
GL.Vertex3(7, 10, 25);
GL.Vertex3(7, 10, 25);
GL.Vertex3(11, 12, 25);
/*色を変えたい時は、GL.Colorを再度指定し直す*/
GL.Color (new Color (0.0f, 1.0f, 0.25f, 0.8F));//以下は緑色
//横軸
 GL.Vertex3(-7, -2, 25);
GL.Vertex3(14, -2, 25);
//縦軸
GL.Vertex3 (-7, -2, 25);
GL.Vertex3 (-7, 15, 25);
GL.End ();
GL.PopMatrix ();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment