unity GUI EditorWindow

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();
    }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值