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("当窗口关闭时调用");
    	}
    
    
    
    
    }
    
    
    
  • 相关阅读:
    groovy-搭建环境
    isAssignableFrom
    H5调用摄像头
    php生成唯一id
    剑指Offer刷题日常
    ASCII码对照表
    用redis stream作队列的一些心得
    在 CAP 中使用 AOP ( Castle.DynamicProxy )
    office2019下载
    JVM调优浅谈
  • 原文地址:https://www.cnblogs.com/yufenghou/p/7338750.html
Copyright © 2011-2022 走看看