Created
July 24, 2014 15:42
-
-
Save tsubaki/37d7c20b4f7f9660b610 to your computer and use it in GitHub Desktop.
シーンにボタンを描画する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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