https://www.jianshu.com/p/b40a2d7c5b47
https://blog.csdn.net/qq_36383623/article/details/100175023
窗口的宽度:position.xMax - position.xMin;
position是EditorWindow的自有成员。
//GUI.DrawTexture(new Rect(80, 80, 600, 400), tex);
//GUI.backgroundColor = Color.yellow;
GUILayout.BeginArea(new Rect(100, 100, 500, 300), EditorStyles.textArea);
{
GUI.DrawTexture(new Rect(2, 2, 496, 296), tex);
}
GUI.SetNextControlName(m_xxx[i]);
string name = GUI.GetNameOfFocusedControl();
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class TestWindow : EditorWindow
{
static string m_itemString = "xxx";
private string[] m_xxx = new string[2] { "abcxxxxxxxxxxxxxxxxx", "12222222222222222222222223" };
private int x;
private static Texture2D tex;
[MenuItem(@"XEditor/Timeline/DramaWindow %e")]
static void DramaTimelineWindow()
{
var win = GetWindow(typeof(TestWindow));
win.name = "xxx";
tex = new Texture2D(2, 2);
tex.wrapMode = TextureWrapMode.Clamp;
tex.SetPixel(0, 0, new Color(1, 1, 1, 1));
tex.SetPixel(0, 1, new Color(1, 1, 1, 1));
tex.SetPixel(1, 0, new Color(1, 1, 1, 1));
tex.SetPixel(1, 1, new Color(1, 1, 1, 1));
tex.Apply();
}
private string timeline, timeline2;
private bool showHint = false;
void OnGUI()
{
GUILayout.BeginVertical();
GUI.SetNextControlName("text1");
timeline = EditorGUILayout.TextField("xxx:", timeline);
GUI.SetNextControlName("text2");
timeline2 = EditorGUILayout.TextField("3333:", timeline2);
string name = GUI.GetNameOfFocusedControl();
if (name.Equals("text1"))
{
ShowHint();
}
GUILayout.EndVertical();
}
private void ShowHint()
{
GUILayout.BeginArea(new Rect(100, 100, 500, 300), EditorStyles.textArea);
{
GUI.DrawTexture(new Rect(2, 2, 496, 296), tex);
for (int i = 0; i < m_xxx.Length; ++i)
{
GUIStyle style = new GUIStyle();
style.alignment = TextAnchor.LowerLeft;
style.fontSize = 15;
style.fixedHeight = 25;
style.normal.textColor = Color.black;
if (GUILayout.Button(m_xxx[i], style, GUILayout.Width(200)))
{
timeline = m_xxx[i];
Debug.LogError(timeline);
showHint = false;
GUI.FocusControl("");
}
}
}
GUILayout.EndArea();
}
}