Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created July 24, 2014 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/37d7c20b4f7f9660b610 to your computer and use it in GitHub Desktop.
Save tsubaki/37d7c20b4f7f9660b610 to your computer and use it in GitHub Desktop.
シーンにボタンを描画する
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