Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

EditorGUILayout.Vector2Field

static function Vector2Field(label: string, value: Vector2, params options: GUILayoutOption[]): Vector2;
static Vector2 Vector2Field(string label, Vector2 value, params GUILayoutOption[] options);
static def Vector2Field(label as string, value as Vector2, *options as GUILayoutOption[]) as Vector2
static function Vector2Field(label: GUIContent, value: Vector2, params options: GUILayoutOption[]): Vector2;
static Vector2 Vector2Field(GUIContent label, Vector2 value, params GUILayoutOption[] options);
static def Vector2Field(label as GUIContent, value as Vector2, *options as GUILayoutOption[]) as Vector2

Parameters

labelLabel to display above the field.
valueThe value to edit.
optionsAn optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the style.
See Also: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

Returns

Vector2 The value entered by the user.

Description

Make an X & Y field for entering a Vector2.


Measure the distance between 2 points.

	// Simple Script that measures the distance between 2 points
	
	class EditorGUILayoutVector2Field extends EditorWindow {
		
		var distance : float = 0;
		var p1 : Vector2;
		var p2 : Vector2;
	
		@MenuItem("Examples/Measure Distance")
		static function Init() {
			var window = GetWindow(EditorGUILayoutVector2Field);
			window.Show();
		}
		function OnGUI() {
			p1 = EditorGUILayout.Vector2Field("Point 1:", p1);
			p2 = EditorGUILayout.Vector2Field("Point 2:", p2);
			EditorGUILayout.LabelField("Distance:", distance.ToString());
			if(GUILayout.Button("Close"))
				this.Close();		
		}
		function OnInspectorUpdate() {
			distance = Vector2.Distance(p1,p2);
			this.Repaint();
		}
	}