Skip to content

Instantly share code, notes, and snippets.

@tsubaki tsubaki/GizmoTest.cs
Created Jul 24, 2014

Embed
What would you like to do?
シーンにボタンを描画する
using UnityEngine;
using System.Collections;
#if UNITY_EDITOR
using UnityEditor;
#endif
[ExecuteInEditMode]
public class GizmoTest : MonoBehaviour {
Color currentColor = Color.red;
void UpdateColor()
{
if( currentColor == Color.red )
{
currentColor = Color.blue;
}else{
currentColor = Color.red;
}
renderer.material.color = currentColor;
}
#if UNITY_EDITOR
void Start()
{
UnityEditor.SceneView.onSceneGUIDelegate += OnSceneView;
}
void OnDestroy()
{
UnityEditor.SceneView.onSceneGUIDelegate -= OnSceneView;
}
void OnSceneView(SceneView sceneView)
{
var sceneCamera = SceneView.currentDrawingSceneView.camera;;
var pos = sceneCamera.WorldToScreenPoint(transform.position);
Handles.BeginGUI ();
var buttonRect = new Rect(pos.x , SceneView.currentDrawingSceneView.position.height - pos.y, 100, 30);
if( GUI.Button( buttonRect, name) )
{
UpdateColor();
}
Handles.EndGUI ();
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.