How to mimic Unity Scene Gizmo?

I am trying to build a product visualization platform inside Unity and I think that the Scene Gizmo type of control is best suited for the job. Any ideas how can I accomplish that in code?

http://starscenesoftware.com/vectrosity.html

Hi Kadrasko,

Im not sure of the example you gave but gizmos can be used to show paths or points in the editor for some items in your script.
For example with waypoints you draw lines between some given points and say a sphere at each point:

public Vector3[] waypoints;
private float node_radius = 0.5f; // gizmo

public void OnDrawGizmos() 
    {
        if(waypoints == null)
            return;
 
        for(int i=0;i< waypoints.Length;i++) {
            Vector3 pos = waypoints*;*

Gizmos.color = Color.yellow;
Gizmos.DrawSphere(pos, node_radius);
if(i>0) {
Vector3 prev = waypoints[i-1];
Gizmos.DrawLine(prev,pos);
}
}
}
Anything to do with the gizmos should be done in OnDrawGizmos().
It’s also an excellent addition to any bezier script so you can see the effect before running it to generate bezier curves in a scene. Following [this thread][1], I needed to simulate hanging wires all over my scene, and I could not see them before playing the game, so I added in some gizmo code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Bezier : MonoBehaviour
{

  • public bool draw = true;*

  • public Transform pos_from; // start of curve*

  • public Transform pos_to; // other end of curve*

  • public Vector3 pos_pivot_1; // in relation to pos_from*

  • public Vector3 pos_pivot_2; // in relation to pos_from*

  • public int segments = 5;*

  • private LineRenderer lineRenderer;*

  • void Start()*

  • {*

  •  lineRenderer = GetComponent<LineRenderer>();*
    
  •  lineRenderer.useWorldSpace = true;*
    
  •  lineRenderer.SetVertexCount(segments);*
    
  • }*

  • void Update()*

  • {*

  •  if(draw)*
    
  •  {*
    
  •  	draw_curve();*
    
  •  	draw = false;*
    
  •  }*
    
  • }*

  • void draw_curve()*

  • {*

  •  Vector3 _from = pos_from.position;*
    
  •  Vector3 piv_1 = pos_from.position - pos_pivot_1;*
    
  •  Vector3 piv_2 = pos_to.position - pos_pivot_2;*
    
  •  Vector3 _to = pos_to.position;*
    
  •  Vector3 v;*
    
  •  for (int i = 0; i < segments; i++)*
    
  •  {*
    

_ float point = 1.0f/segments*i;_

  •  	v = CalculateBezierPoint(point, _from, piv_1, piv_2, _to);*
    
  •  	lineRenderer.SetPosition(i,v);*
    
  •  }*
    
  •  v = CalculateBezierPoint(1, _from, piv_1, piv_2, _to);*
    
  •  lineRenderer.SetPosition(segments-1,v);*
    
  • }*

  • private void OnDrawGizmos()*
    {

  •  Vector3 _from = pos_from.position;*
    
  •  Vector3 piv_1 = pos_from.position - pos_pivot_1;*
    
  •  Vector3 piv_2 = pos_to.position - pos_pivot_2;*
    
  •  Vector3 _to = pos_to.position;*
    
  •  Vector3 v = Vector3.zero;*
    
  •  for (int i = 0; i < segments; i++)*
    
  •  {*
    

_ float point = 1.0f/segments*i;_

  •  	v = CalculateBezierPoint(point, _from, piv_1, piv_2, _to);*
    
  •  	Gizmos.color = Color.yellow;*
    
  •      Gizmos.DrawSphere(v, 0.1f);*
    

if(i>0) {
point = 1.0f/segments*(i-1);

  •  		Vector3 prev = CalculateBezierPoint(point, _from, piv_1, piv_2, _to);*
    

Gizmos.DrawLine(prev,v);

  •  	}*
    
  •  }		*
    
  •  Gizmos.DrawLine(v,_to);*
    

}

  • Vector3 CalculateBezierPoint(float t, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)*
  • {*
  •  float u = 1.0f-t;*
    

_ float tt = tt;_
_ float uu = u
u;_
_ float uuu = uuu;_
_ float ttt = tt
t;_

_ Vector3 p = uuu * p0; //first term_
_ p += 3 * uu * t * p1; //second term_
_ p += 3 * u * tt * p2; //third term_
_ p += ttt * p3; //fourth term_

  • return p;*
  • }*
    }
    Hopefully these 2 examples can help get you on your way
    Cheers

[1]: http://forum.unity3d.com/threads/134810-bezier-curves-through-script