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("当窗口关闭时调用");
    	}
    
    
    
    
    }
    
    
    
  • 相关阅读:
    webpack入门
    Javascript隐式转换
    一个最小手势库的实现
    运用JS设置cookie、读取cookie、删除cookie
    不同浏览器下兼容文本两端对齐
    使用CSS3实现一个3D相册
    JavaScript 火的有点过头了,但又能火多久呢?
    强大的css3
    CSS3与页面布局学习总结
    红米手机真机调试问题记录
  • 原文地址:https://www.cnblogs.com/yufenghou/p/7338750.html
Copyright © 2011-2022 走看看