• Unity快捷键


    using System;
    using UnityEngine;
    using System.Collections;
    using UnityEditor;
    using System.IO;
    using System.Text;
    using System.Collections.Generic;
    
    public class CustomHotKey : MonoBehaviour
    {
    	[MenuItem("CustomHotKey/ToggleActivie &v")]
    	public static void ToggleActive()
    	{
    		foreach (var obj in Selection.gameObjects)
    		{
    			Undo.RegisterCompleteObjectUndo(new UnityEngine.Object[] { obj, }, obj.name);
    			obj.SetActive(!obj.activeSelf);
    		}
    	}
    
    	[MenuItem("CustomHotKey/TogglePause &p")]
    	public static void TogglePause()
    	{
    		EditorApplication.isPaused = !EditorApplication.isPaused;
    	}
    
    	[MenuItem("CustomHotKey/SaveProject &s")]
    	public static void SaveAssets()
    	{
    		AssetDatabase.SaveAssets();
    		Debug.Log("Project Saved.");
    	}
    
    	[MenuItem("CustomHotKey/ApplyPrefab &a")]
    	public static void ApplyPrefab()
    	{
    		foreach (var obj in Selection.gameObjects)
    		{
    			var prefabParent = PrefabUtility.GetPrefabParent(obj);
    			if (prefabParent != null)
    				PrefabUtility.ReplacePrefab(PrefabUtility.FindPrefabRoot(obj), prefabParent, ReplacePrefabOptions.ConnectToPrefab);
    		}
    	}
    
    	[MenuItem("CustomHotKey/Open Containing Folder &o")]
    	public static void OpenContainingFolder()
    	{
    #if UNITY_EDITOR_WIN
    		var path = Path.Combine(Path.Combine(Application.dataPath, ".."), AssetDatabase.GetAssetPath(Selection.activeObject));
    
    		ShowSelectedInExplorer.FilesOrFolders(path);
    #else
    		Debug.LogWarning("not supported on current platform");
    #endif
    	}
    
    	[MenuItem("CustomHotKey/Copy Hierarchy Path &i")]
    	public static void CopyHierarchyPath()
    	{
    		var output = "";
    		foreach (var obj in Selection.gameObjects)
    		{
    			var line = obj.name;
    			var parent = obj.transform.parent;
    			while (parent)
    			{
    				line = parent.gameObject.name + "/" + line;
    				parent = parent.parent;
    			}
    
    			if (output.Length > 0)
    				output += "\n";
    			output += line;
    		}
    
    		// copy to clipboard
    		TextEditor te = new TextEditor();
    		//te.content = new GUIContent(output);
    		te.text = output;
    		te.OnFocus();
    		te.Copy();
    	}
    
    	[MenuItem("CustomHotKey/Copy Asset Path &t")]
    	public static void CopyAssetPath()
    	{
    		StringBuilder output = new StringBuilder();
    		foreach (var obj in Selection.objects)
    		{
    			if (output.Length > 0)
    				output.AppendLine();
    			output.Append(AssetDatabase.GetAssetPath(obj));
    		}
    
    		String outputStr = output.ToString();
    
    		// copy to clipboard
    		TextEditor te = new TextEditor();
    		//te.content = new GUIContent(output);
    		te.text = outputStr;
    		te.OnFocus();
    		te.Copy();
    	}
    
    	[MenuItem("CustomHotKey/Clear Console &c")]
    	public static void ClearConsole()
    	{
    		Type logEntries = System.Type.GetType("UnityEditor.LogEntries,UnityEditor.dll");
    		if (logEntries == null)
    		{
    			Debug.LogWarning("Can't find type");
    			return;
    		}
    
    		var method = logEntries.GetMethod("Clear", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
    		if (method != null)
    		{
    			method.Invoke(null, null);
    			GUIUtility.keyboardControl = 0;
    		}
    		else
    		{
    			Debug.LogWarning("Can't find methord");
    			return;
    		}
    	}
    
    	[MenuItem("CustomHotKey/AddUISound (with path from clipboard) %&S")]
    	public static void AddUISound()
    	{
    		String soundPath = EditorGUIUtility.systemCopyBuffer ?? "";
    		GameObject[] sels = Selection.gameObjects;
    		if (sels == null)
    			return;
    
    		Boolean bRemove = String.IsNullOrEmpty(soundPath) || soundPath == " ";
    
    		Int32 count = 0;
    		foreach (GameObject sel in sels)
    		{
    			if (UISoundAssist.AddOrRemoveUIMainSound(sel, !bRemove, soundPath))
    				++count;
    		}
    
    		if (!bRemove)
    		{
    			if (count > 0)
    				Debug.LogFormat("sound event '{0}' has been added to {1} UI controls", soundPath, count);
    			else
    				Debug.LogWarningFormat("sound event '{0}' has not been added to any UI control", soundPath);
    		}
    		else
    		{
    			if (count > 0)
    				Debug.LogFormat("sound event has been removed from {0} UI controls", count);
    			else
    				Debug.LogFormat("sound event has not been removed from any UI control");
    		}
    	}
    
    	[MenuItem("CustomHotKey/AddUIToggleSound (with two path from clipboard) %&T")]
    	public static void AddUIToggleSound()
    	{
    		String soundPath = EditorGUIUtility.systemCopyBuffer ?? "";
    		GameObject[] sels = Selection.gameObjects;
    		if (sels == null)
    			return;
    
    		Boolean bRemove = String.IsNullOrEmpty(soundPath) || soundPath == " ";
    
    		Int32 count = 0;
    		foreach (GameObject sel in sels)
    		{
    			if (UISoundAssist.AddOrRemoveUIToggleSound(sel, !bRemove, soundPath))
    				++count;
    		}
    
    		if (!bRemove)
    		{
    			if (count > 0)
    				Debug.LogFormat("sound event '{0}' has been added to {1} UI controls", soundPath, count);
    			else
    				Debug.LogWarningFormat("sound event '{0}' has not been added to any UI control", soundPath);
    		}
    		else
    		{
    			if (count > 0)
    				Debug.LogFormat("sound event has been removed from {0} UI controls", count);
    			else
    				Debug.LogFormat("sound event has not been removed from any UI control");
    		}
    	}
    
    	static bool hide = true;
    	[MenuItem("CustomHotKey/Toggle Selected wireframe &x")]
    	public static void ToggleWireframe(){
    		if (Selection.activeGameObject == null) return ;
    
    		Renderer[] renderers = Selection.activeGameObject.GetComponentsInChildren<Renderer>();
    		for( int i = 0; i < renderers.Length; i ++)
    		{
    #pragma warning disable 618
    			EditorUtility.SetSelectedWireframeHidden(renderers[i], hide);
    #pragma warning restore 618
    		}
    		hide = !hide;
    	}
    
    	[MenuItem("CustomHotKey/Reimport selected %&i")]
    	public static void ReimportSelected()
    	{
    
    		var objs = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets);
    		
    		foreach (var obj in objs)
    		{
    			AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(obj.GetInstanceID()));
    		}
    	}
    
    	[MenuItem("CustomHotKey/Unparent Selected #%&P")]
    	static void UnparentSelectedObjecet()
    	{
    		foreach (var obj in Selection.gameObjects)
    		{
    			var tp = PrefabUtility.GetPrefabType(obj);
    			if (tp == PrefabType.Prefab || tp == PrefabType.ModelPrefab)
    				continue;
    
    			Transform objT = obj.transform;
    			if (objT != null && objT.parent != null)
    			{
    				Undo.SetTransformParent(objT, null, "Unparent " + obj.name);
    			}
    		}
    	}
    
    	[MenuItem("CustomHotKey/Restore 60 FPS #%&6")]
    	static void Restore_60_FPS()
    	{
    		Application.targetFrameRate = 60;
    	}
    	[MenuItem("CustomHotKey/Select Objects by Clipboard #%&7")]
    	static void SelectObjectsByClipboard()
    	{
    		string[] lines = GUIUtility.systemCopyBuffer.Split('\r', '\n');
    		List<UnityEngine.Object> objs = new List<UnityEngine.Object>();
    
    		foreach (string line in lines)
    		{
    			if (string.IsNullOrEmpty(line))
    				continue;
    			var obj = AssetDatabase.LoadAssetAtPath(line, typeof(UnityEngine.Object));
    			if (obj != null)
    			{
    				objs.Add(obj);
    				Debug.Log(obj.name);
    			}
    		}
    		Selection.objects = objs.ToArray();
    		
    	}
    }
    
    
  • 相关阅读:
    71 是否同一棵二叉搜索树(25 分)
    75 平衡二叉树的根(25 分)
    72 树种统计(25 分)
    2018(容斥定理 HDU6286)
    直观的理解计算机中的数值编码
    如何关闭emacs开启时自己打开的欢迎界面
    图论:最短路径:广度优先搜索(C语言实现)
    ubunut 14.04 将Caps Lock设置为Control
    邻接表:C语言实现
    队列(C语言实现)
  • 原文地址:https://www.cnblogs.com/ezhar/p/16341206.html
Copyright © 2020-2023  润新知