This commit is contained in:
2020-07-04 14:41:25 +08:00
parent 70c346d2c1
commit a8f02e4da5
3748 changed files with 587372 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 80f77e19806a8424c837de1283215a9c
folderAsset: yes
timeCreated: 1484616169
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,6 @@
using UnityEngine;
namespace UnityEditorHelper
{
public class LayerAttribute : PropertyAttribute { }
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 971f5270110911b4fb502df4a3ad7eb5
timeCreated: 1434825477
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,41 @@
using System;
using UnityEngine;
namespace UnityEditorHelper
{
public class LimitAttribute : PropertyAttribute
{
public enum Mode { LimitLower, LimitUpper, LimitBoth }
private readonly Mode _limitMode;
private readonly int _lowerLimit;
private readonly int _upperLimit;
public LimitAttribute(int lowerLimit) : this(Mode.LimitLower, lowerLimit, int.MaxValue) { }
public LimitAttribute(int lowerLimit, int upperLimit) : this(Mode.LimitLower, lowerLimit, upperLimit) { }
private LimitAttribute(Mode mode, int lowerLimit, int upperLimit)
{
_limitMode = mode;
_lowerLimit = lowerLimit;
_upperLimit = upperLimit;
}
public int Limit(int value)
{
switch (_limitMode)
{
case Mode.LimitLower:
return Mathf.Clamp(value, _lowerLimit, int.MaxValue);
case Mode.LimitUpper:
return Mathf.Clamp(value, int.MinValue, _upperLimit);
case Mode.LimitBoth:
return Mathf.Clamp(value, _lowerLimit, _upperLimit);
default:
throw new ArgumentOutOfRangeException();
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 31dce993b711b3d4ebe6de30a65f6f15
timeCreated: 1434825476
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,6 @@
using UnityEngine;
namespace UnityEditorHelper
{
public class SortingLayerAttribute : PropertyAttribute { }
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cba79dad475a86645af6e8d148acbd8e
timeCreated: 1434825477
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,6 @@
using UnityEngine;
namespace UnityEditorHelper
{
public class TagAttribute : PropertyAttribute { }
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 30ebe4ad2affb194daaaf76da62e6bc0
timeCreated: 1434825476
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: dcf8a59cabf64419da646c468cf2c605
folderAsset: yes
timeCreated: 1484616170
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,241 @@
using System;
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace UnityEditorHelper
{
public static class EditorHelper
{
private static readonly GUIStyle SimpleRectStyle;
static EditorHelper()
{
Texture2D simpleTexture = new Texture2D(1, 1);
simpleTexture.SetPixel(0, 0, Color.white);
simpleTexture.Apply();
SimpleRectStyle = new GUIStyle { normal = { background = simpleTexture } };
}
public static bool DrawIconHeader(string key, Texture icon, string caption, Color captionColor)
{
bool state = EditorPrefs.GetBool(key, true);
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField(new GUIContent(icon), EditorStyles.miniLabel, GUILayout.Width(22), GUILayout.Height(22));
using (new SwitchColor(captionColor)) {
EditorGUILayout.BeginVertical();
GUILayout.Space(5);
EditorGUILayout.LabelField(caption, EditorStyles.boldLabel);
EditorGUILayout.EndVertical();
}
EditorGUILayout.Space();
string cap = state ? "\u25bc" : "\u25b2";
if (GUILayout.Button(cap, EditorStyles.label, GUILayout.Width(16), GUILayout.Height(16))) {
state = !state;
EditorPrefs.SetBool(key, state);
}
}
EditorGUILayout.EndHorizontal();
GUILayout.Space(2);
return state;
}
public static string GetAssetPath(string assetFileName)
{
if (!AssetDatabase.GetAllAssetPaths().Any(p => p.EndsWith(assetFileName))) {
AssetDatabase.Refresh();
}
string basePath = AssetDatabase.GetAllAssetPaths().First(p => p.EndsWith(assetFileName));
int lastDelimiter = basePath.LastIndexOf('/') + 1;
basePath = basePath.Remove(lastDelimiter, basePath.Length - lastDelimiter);
return basePath;
}
public static GUIStyle GetEditorStyle(string style)
{
return EditorGUIUtility.GetBuiltinSkin(EditorGUIUtility.isProSkin ? EditorSkin.Scene : EditorSkin.Inspector).GetStyle(style);
}
public static void GUIDrawRect(Rect position, Color color)
{
using (new SwitchColor(color)) {
GUI.Box(position, GUIContent.none, SimpleRectStyle);
}
}
}
public sealed class HighlightBox : IDisposable
{
public HighlightBox() : this(new Color(0.1f, 0.1f, 0.2f))
{
}
public HighlightBox(Color color)
{
GUILayout.Space(8f);
GUILayout.BeginHorizontal();
GUILayout.Space(4f);
using (new SwitchColor(color)) {
EditorGUILayout.BeginHorizontal(EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).GetStyle("sv_iconselector_labelselection"), GUILayout.MinHeight(10f));
}
GUILayout.BeginVertical();
GUILayout.Space(4f);
}
public void Dispose()
{
try {
GUILayout.Space(3f);
GUILayout.EndVertical();
EditorGUILayout.EndHorizontal();
GUILayout.Space(3f);
GUILayout.EndHorizontal();
GUILayout.Space(3f);
} catch (Exception e) {
Debug.LogWarning(e);
}
}
}
public sealed class EditorBlock : IDisposable
{
public enum Orientation
{
Horizontal,
Vertical
}
private readonly Orientation _orientation;
public EditorBlock(Orientation orientation, string style, params GUILayoutOption[] options)
{
_orientation = orientation;
if (orientation == Orientation.Horizontal) {
EditorGUILayout.BeginHorizontal(string.IsNullOrEmpty(style) ? GUIStyle.none : style, options);
} else {
EditorGUILayout.BeginVertical(string.IsNullOrEmpty(style) ? GUIStyle.none : style, options);
}
}
public EditorBlock(Orientation orientation, string style) : this(orientation, style, new GUILayoutOption[] { })
{
}
public EditorBlock(Orientation orientation) : this(orientation, null, new GUILayoutOption[] { })
{
}
public void Dispose()
{
if (_orientation == Orientation.Horizontal) {
EditorGUILayout.EndHorizontal();
} else {
EditorGUILayout.EndVertical();
}
}
}
public sealed class SwitchColor : IDisposable
{
private readonly Color _savedColor;
public SwitchColor(Color newColor)
{
_savedColor = GUI.backgroundColor;
GUI.color = newColor;
}
public void Dispose()
{
GUI.color = _savedColor;
}
}
public class IndentBlock : IDisposable
{
public IndentBlock()
{
EditorGUI.indentLevel++;
}
public void Dispose()
{
EditorGUI.indentLevel--;
}
}
public class ScrollViewBlock : IDisposable
{
public ScrollViewBlock(ref Vector2 scrollPosition, params GUILayoutOption[] options)
{
scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, options);
}
public void Dispose()
{
EditorGUILayout.EndScrollView();
}
}
public sealed class FoldableBlock : IDisposable
{
private readonly Color _defaultBackgroundColor;
private bool _expanded;
public FoldableBlock(ref bool expanded, string header) : this(ref expanded, header, null)
{
}
public FoldableBlock(ref bool expanded, string header, Texture2D icon)
{
_defaultBackgroundColor = GUI.backgroundColor;
GUILayout.Space(3f);
GUILayout.BeginHorizontal();
GUILayout.Space(3f);
GUI.changed = false;
if (!GUILayout.Toggle(true, new GUIContent("<b><size=11>" + header + "</size></b>", icon), "dragtab", GUILayout.MinWidth(20f)))
expanded = !expanded;
GUILayout.Space(2f);
GUILayout.EndHorizontal();
if (!expanded) {
GUILayout.Space(3f);
} else {
GroupStart();
}
_expanded = expanded;
}
private void GroupStart()
{
GUILayout.BeginHorizontal();
GUILayout.Space(4f);
EditorGUILayout.BeginHorizontal(NGUIEditorTools.textArea, GUILayout.MinHeight(10f));
GUILayout.BeginVertical();
GUILayout.Space(2f);
}
private void GroupEnd()
{
try {
GUILayout.Space(3f);
GUILayout.EndVertical();
EditorGUILayout.EndHorizontal();
GUILayout.Space(3f);
GUILayout.EndHorizontal();
GUILayout.Space(3f);
GUI.backgroundColor = _defaultBackgroundColor;
} catch (Exception e) {
Debug.LogWarning(e);
}
}
public void Dispose()
{
if (_expanded)
GroupEnd();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 1c3e20c87f936934aaefd4030d9b275b
timeCreated: 1434825476
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 4735623ddbab36341a8c0974da521977
folderAsset: yes
timeCreated: 1484616170
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
using UnityEngine;
using UnityEditor;
namespace UnityEditorHelper
{
[CustomPropertyDrawer(typeof (LayerAttribute))]
public class LayerPropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (property.propertyType != SerializedPropertyType.Integer)
{
Debug.LogWarning("LayerAttribute can only be applied on integer properties/fields");
return;
}
property.intValue = EditorGUI.LayerField(position, property.name, property.intValue);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: db7cad7f95703f84ea5d8b4baea7a483
timeCreated: 1434825477
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
using UnityEngine;
using UnityEditor;
namespace UnityEditorHelper
{
[CustomPropertyDrawer(typeof (LimitAttribute))]
public class LimitPropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (property.propertyType != SerializedPropertyType.Integer)
{
Debug.LogWarning("LimitAttribute can only be applied on integer properties/fields");
return;
}
LimitAttribute limiter = attribute as LimitAttribute;
property.intValue = limiter.Limit(EditorGUI.IntField(position, property.name, property.intValue));
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 9c031d8492d933e49b0bc44865d327aa
timeCreated: 1434825477
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,46 @@
using System.Reflection;
using UnityEditorInternal;
using UnityEngine;
using UnityEditor;
namespace UnityEditorHelper
{
[CustomPropertyDrawer(typeof (SortingLayerAttribute))]
public class SortingLayerDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (property.propertyType != SerializedPropertyType.Integer)
{
Debug.LogWarning("SortingLayerAttributes can only be applied on integer properties/fields");
return;
}
EditorGUI.LabelField(position, label);
position.x += EditorGUIUtility.labelWidth;
position.width -= EditorGUIUtility.labelWidth;
string[] sortingLayerNames = GetSortingLayerNames();
int[] sortingLayerIDs = GetSortingLayerIDs();
int sortingLayerIndex = Mathf.Max(0, System.Array.IndexOf(sortingLayerIDs, property.intValue));
sortingLayerIndex = EditorGUI.Popup(position, sortingLayerIndex, sortingLayerNames);
property.intValue = sortingLayerIDs[sortingLayerIndex];
}
private string[] GetSortingLayerNames()
{
System.Type internalEditorUtilityType = typeof (InternalEditorUtility);
PropertyInfo sortingLayersProperty = internalEditorUtilityType.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
return (string[]) sortingLayersProperty.GetValue(null, new object[0]);
}
private int[] GetSortingLayerIDs()
{
System.Type internalEditorUtilityType = typeof (InternalEditorUtility);
PropertyInfo sortingLayersProperty = internalEditorUtilityType.GetProperty("sortingLayerUniqueIDs", BindingFlags.Static | BindingFlags.NonPublic);
return (int[]) sortingLayersProperty.GetValue(null, new object[0]);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d3e77ff7706ee9c4a85b478eb23510fd
timeCreated: 1434825477
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
using UnityEngine;
using UnityEditor;
namespace UnityEditorHelper
{
[CustomPropertyDrawer(typeof (TagAttribute))]
public class TagPropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (property.propertyType != SerializedPropertyType.String)
{
Debug.LogWarning("TagAttribute can only be applied on string properties/fields");
return;
}
property.stringValue = EditorGUI.TagField(position, property.name, property.stringValue);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 32950be6beb9f3b4ca5419e5d71ec0ed
timeCreated: 1434825476
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,13 @@
Copyright 2016 Thomas Hummes
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0c7758ff7f2e8407ea1c12e6067ae309
timeCreated: 1480063277
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,4 @@
# UnityEditorHelper
An organized bunch of scripts to make editor scripting in Unity easier - gathered from some of my projects and other free sources
More information can be found in the wiki including examples and screenshots: https://github.com/JefferiesTube/UnityEditorHelper/wiki

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d817bb522bbb94bf0b8fbb2989522217
timeCreated: 1480063278
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant: