Created
July 26, 2014 13:03
-
-
Save tsubaki/1daa2e136f6d14d1693b to your computer and use it in GitHub Desktop.
OnSceneGUIの入力例
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; | |
public class Sample : MonoBehaviour | |
{ | |
[SerializeField] | |
private int count; | |
} |
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; | |
using UnityEditor; | |
[CustomEditor(typeof(Sample))] | |
public class SampleEditor : Editor { | |
private Vector2 buttonSize = new Vector2(60, 60); | |
void OnSceneGUI() | |
{ | |
var sceneCamera = SceneView.currentDrawingSceneView.camera;; | |
var component = (Sample)target; | |
var pos = sceneCamera.WorldToScreenPoint(component.transform.position); | |
Handles.BeginGUI (); | |
var countButtonRect = new Rect( | |
pos.x - buttonSize.x * 0.5f, | |
SceneView.currentDrawingSceneView.position.height - pos.y - buttonSize.y * 0.5f, | |
buttonSize.x, | |
buttonSize.y); | |
var leftButton = countButtonRect; | |
leftButton.position += new Vector2(-buttonSize.x, 0); | |
var rightButtonRect = countButtonRect; | |
rightButtonRect.position += new Vector2(buttonSize.x, 0); | |
if( GUI.Button( countButtonRect, serializedObject.FindProperty("count").intValue.ToString()) ) | |
{ | |
serializedObject.FindProperty("count").intValue += 1; | |
serializedObject.ApplyModifiedProperties(); | |
} | |
if( GUI.Button(leftButton , "<-") ) | |
{ | |
component.transform.position += Vector3.left; | |
} | |
if( GUI.Button(rightButtonRect , "->") ) | |
{ | |
component.transform.position += Vector3.right; | |
} | |
Handles.EndGUI(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment