Skip to content

Instantly share code, notes, and snippets.

@CapitanLiteral
CapitanLiteral / Inspector
Created June 24, 2020 12:47
Inspector lock toggle + Inspector rename
public static class Inspector
{
public static void InspectorRename(bool inspector = false)
{
EditorWindow windowToBeLocked = EditorWindow.mouseOverWindow;
if (windowToBeLocked.GetType().ToString().Equals("UnityEditor.InspectorWindow"))
{
if (inspector)
{
Texture tex = windowToBeLocked.titleContent.image;
[MenuItem("Tools/Inspector rename &r")]
public static void InspectorSwitchName()
{
EditorWindow windowToBeLocked = EditorWindow.mouseOverWindow;
if (windowToBeLocked.GetType().ToString().Equals("UnityEditor.InspectorWindow"))
{
if (windowToBeLocked.title != "Inspector")
{
Texture tex = windowToBeLocked.titleContent.image;
windowToBeLocked.title = "Inspector";
public static class BinaryFormatterWrapper
{
private static BinaryFormatter BinaryFormatter => binaryFormatter ?? (binaryFormatter = new BinaryFormatter());
private static BinaryFormatter binaryFormatter;
public static byte[] SerializeToByteArray(this object obj)
{
using (MemoryStream memoryStream = new MemoryStream())
{
BinaryFormatter.Serialize(memoryStream, obj);
using UnityEngine;
public static class VectorExtensions
{
// 2 component combinations
public static Vector4 XY__(this Vector2 aVec, float aZ = 0, float aW = 0) { return new Vector4(aVec.x, aVec.y, aZ, aW); }
public static Vector4 XY__(this Vector3 aVec, float aZ = 0, float aW = 0) { return new Vector4(aVec.x, aVec.y, aZ, aW); }
public static Vector4 XY__(this Vector4 aVec, float aZ = 0, float aW = 0) { return new Vector4(aVec.x, aVec.y, aZ, aW); }
public static Vector4 X_Y_(this Vector2 aVec, float aY = 0, float aW = 0) { return new Vector4(aVec.x, aY, aVec.y, aW); }
@CapitanLiteral
CapitanLiteral / DrawColoredList
Created November 3, 2019 00:11
Editor to display all editable prefabs
public static ScriptableObject DrawColoredList(ScriptableObject scriptableObject, int i, ScriptableObject selected)
{
if (scriptableObject == selected)
GUILayout.BeginHorizontal(EditorStyle.GetSelectedStyle());
else if (i % 2 == 0)
GUILayout.BeginHorizontal(EditorStyle.GetGreyedOutStyle());
else
GUILayout.BeginHorizontal();
if (GUILayout.Button(scriptableObject.name, EditorStyle.ListElementStyle))
public static IEnumerable<Type> GetTypesWith<TAttribute>(bool inherit)
where TAttribute : Attribute
{
return AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(a => a.GetTypes())
.Where(t => t.IsDefined(typeof(TAttribute), inherit));
}
public static List<T> FindAssetsByType<T>() where T : Object
{
List<T> assets = new List<T>();
string[] guids = AssetDatabase.FindAssets(string.Format("t:{0}", typeof(T)));
for( int i = 0; i < guids.Length; i++ )
{
string assetPath = AssetDatabase.GUIDToAssetPath( guids[i] );
T asset = AssetDatabase.LoadAssetAtPath<T>( assetPath );
if( asset != null )
{
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public static class EditorWindowExtensions
{
public static string Save(this EditorWindow window)
{
var data = JsonUtility.ToJson(window, false);
using System;
using System.Reflection;
using UnityEditor;
namespace Plugins.Gists.Editor
{
public static class InspectorLockToggle
{
[MenuItem("Tools/Toggle Lock &q")]
static void ToggleWindowLock() // Inspector must be inspecting something to be locked
Vector3 diff = lookAt3dPosition - transform.position;
diff.Normalize();
float rot_z = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0f, 0f, rot_z - 90);