Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created July 26, 2014 13:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/1daa2e136f6d14d1693b to your computer and use it in GitHub Desktop.
Save tsubaki/1daa2e136f6d14d1693b to your computer and use it in GitHub Desktop.
OnSceneGUIの入力例
using UnityEngine;
using System.Collections;
public class Sample : MonoBehaviour
{
[SerializeField]
private int count;
}
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