zoukankan      html  css  js  c++  java
  • unity 编辑器扩展 创建一个窗口

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEditor;
    
    
    public class MyEditor : EditorWindow {
    
    	[MenuItem("GameObject/window")]
    	static void AddWindow()
    	{
    		Rect wr=new Rect(0,0,500,500);
    		MyEditor windows=(MyEditor)EditorWindow.GetWindowWithRect(typeof(MyEditor),wr,true,"window name");
    		windows.Show();
    	}
    
    
    	private string text;
    	private Texture texture;
    
    	public void Awake()
    	{
    		texture = Resources.Load("1") as Texture;
    	}
    
    	void OnGUI()
    	{
    		//文本框
    		text = EditorGUILayout.TextField("输入文字",text);
    
    		if(GUILayout.Button("打开通知",GUILayout.Width(200)))
    		{
    			//打开一个通知栏
    			this.ShowNotification(new GUIContent("this is a notification"));
    		}
    		if(GUILayout.Button("关闭通知",GUILayout.Width(200)))
    		{
    			//关闭通知栏
    			this.RemoveNotification();
    		}
    
    		EditorGUILayout.LabelField("鼠标在窗口的位置",Event.current.mousePosition.ToString());
    
    
    		texture = EditorGUILayout.ObjectField("添加贴图",texture,typeof(Texture),true) as Texture;
    
    
    		if(GUILayout.Button("关闭窗口",GUILayout.Width(200)))
    		{
    			//关闭窗口
    			this.Close();
    		}
    	}
    
    
    	void OnFocus()
    	{
    		Debug.Log("当窗口获得焦点时调用一次");
    	}
    
    	void OnLostFocus()
    	{
    		Debug.Log("当窗口丢失焦点时调用一次");
    	}
    
    
    	void OnHierarchyChange()
    	{
    		Debug.Log("当Hierarchy视图中的任何对象发生改变时调用一次");
    	}
    
    	void OnProjectChange()
    	{
    		Debug.Log("当Project视图中的资源发生改变时调用一次");
    	}
    
    	void OnInspectorUpdate()
    	{
    		//重画
    		this.Repaint();
    	}
    
    	void OnSelectionChange()
    	{
    		foreach(Transform t in Selection.transforms)
    		{
    			Debug.Log("OnSelectionChange"+t.name);
    		}
    	}
    
    
    	void OnDestroy()
    	{
    		Debug.Log("当窗口关闭时调用");
    	}
    
    
    
    
    }
    
    
    
  • 相关阅读:
    关于数论的一些总结
    gym101431B
    4.29训练题解
    hdu4347
    5.13训练的一些题解
    5.20训练的一些题解
    hdu4796
    hdu5984
    bzoj1941 hdu5992
    hdu4307
  • 原文地址:https://www.cnblogs.com/yufenghou/p/7338750.html
Copyright © 2011-2022 走看看